diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 51 |
1 files changed, 44 insertions, 7 deletions
@@ -599,6 +599,18 @@ static void communicateWithRunningInstance_App_(iApp *d, iProcessId instance, | |||
599 | } | 599 | } |
600 | #endif /* defined (LAGRANGE_ENABLE_IPC) */ | 600 | #endif /* defined (LAGRANGE_ENABLE_IPC) */ |
601 | 601 | ||
602 | static iBool hasCommandLineOpenableScheme_(const iRangecc uri) { | ||
603 | static const char *schemes[] = { | ||
604 | "gemini:", "gopher:", "finger:", "file:", "data:", "about:" | ||
605 | }; | ||
606 | iForIndices(i, schemes) { | ||
607 | if (startsWithCase_Rangecc(uri, schemes[i])) { | ||
608 | return iTrue; | ||
609 | } | ||
610 | } | ||
611 | return iFalse; | ||
612 | } | ||
613 | |||
602 | static void init_App_(iApp *d, int argc, char **argv) { | 614 | static void init_App_(iApp *d, int argc, char **argv) { |
603 | init_CommandLine(&d->args, argc, argv); | 615 | init_CommandLine(&d->args, argc, argv); |
604 | /* Where was the app started from? We ask SDL first because the command line alone is | 616 | /* Where was the app started from? We ask SDL first because the command line alone is |
@@ -633,6 +645,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
633 | defineValues_CommandLine(&d->args, "go-home", 0); | 645 | defineValues_CommandLine(&d->args, "go-home", 0); |
634 | defineValues_CommandLine(&d->args, "help", 0); | 646 | defineValues_CommandLine(&d->args, "help", 0); |
635 | defineValues_CommandLine(&d->args, listTabUrls_CommandLineOption, 0); | 647 | defineValues_CommandLine(&d->args, listTabUrls_CommandLineOption, 0); |
648 | defineValues_CommandLine(&d->args, openUrlOrSearch_CommandLineOption, 1); | ||
636 | defineValuesN_CommandLine(&d->args, "new-tab", 0, 1); | 649 | defineValuesN_CommandLine(&d->args, "new-tab", 0, 1); |
637 | defineValues_CommandLine(&d->args, "sw", 0); | 650 | defineValues_CommandLine(&d->args, "sw", 0); |
638 | defineValues_CommandLine(&d->args, "version;V", 0); | 651 | defineValues_CommandLine(&d->args, "version;V", 0); |
@@ -652,14 +665,11 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
652 | const iRangecc arg = i.entry; | 665 | const iRangecc arg = i.entry; |
653 | if (i.argType == value_CommandLineArgType) { | 666 | if (i.argType == value_CommandLineArgType) { |
654 | /* URLs and file paths accepted. */ | 667 | /* URLs and file paths accepted. */ |
655 | const iBool isKnownScheme = | 668 | const iBool isOpenable = hasCommandLineOpenableScheme_(arg); |
656 | startsWithCase_Rangecc(arg, "gemini:") || startsWithCase_Rangecc(arg, "gopher:") || | 669 | if (isOpenable || fileExistsCStr_FileInfo(cstr_Rangecc(arg))) { |
657 | startsWithCase_Rangecc(arg, "finger:") || startsWithCase_Rangecc(arg, "file:") || | ||
658 | startsWithCase_Rangecc(arg, "data:") || startsWithCase_Rangecc(arg, "about:"); | ||
659 | if (isKnownScheme || fileExistsCStr_FileInfo(cstr_Rangecc(arg))) { | ||
660 | iString *decUrl = | 670 | iString *decUrl = |
661 | isKnownScheme ? urlDecodeExclude_String(collectNewRange_String(arg), "/?#:") | 671 | isOpenable ? urlDecodeExclude_String(collectNewRange_String(arg), "/?#:") |
662 | : makeFileUrl_String(collectNewRange_String(arg)); | 672 | : makeFileUrl_String(collectNewRange_String(arg)); |
663 | pushBack_StringList(openCmds, | 673 | pushBack_StringList(openCmds, |
664 | collectNewFormat_String( | 674 | collectNewFormat_String( |
665 | "open newtab:1 url:%s", cstr_String(decUrl))); | 675 | "open newtab:1 url:%s", cstr_String(decUrl))); |
@@ -670,6 +680,19 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
670 | terminate_App_(1); | 680 | terminate_App_(1); |
671 | } | 681 | } |
672 | } | 682 | } |
683 | else if (equal_CommandLineConstIterator(&i, openUrlOrSearch_CommandLineOption)) { | ||
684 | const iCommandLineArg *arg = iClob(argument_CommandLineConstIterator(&i)); | ||
685 | const iString *input = value_CommandLineArg(arg, 0); | ||
686 | if (startsWith_String(input, "//")) { | ||
687 | input = collectNewFormat_String("gemini:%s", cstr_String(input)); | ||
688 | } | ||
689 | if (hasCommandLineOpenableScheme_(range_String(input))) { | ||
690 | input = collect_String(urlDecodeExclude_String(input, "/?#:")); | ||
691 | } | ||
692 | pushBack_StringList( | ||
693 | openCmds, | ||
694 | collectNewFormat_String("search newtab:1 query:%s", cstr_String(input))); | ||
695 | } | ||
673 | else if (!isDefined_CommandLine(&d->args, collectNewRange_String(i.entry))) { | 696 | else if (!isDefined_CommandLine(&d->args, collectNewRange_String(i.entry))) { |
674 | fprintf(stderr, "Unknown option: %s\n", cstr_Rangecc(arg)); | 697 | fprintf(stderr, "Unknown option: %s\n", cstr_Rangecc(arg)); |
675 | terminate_App_(1); | 698 | terminate_App_(1); |
@@ -2126,6 +2149,20 @@ iBool handleCommand_App(const char *cmd) { | |||
2126 | } | 2149 | } |
2127 | return iTrue; | 2150 | return iTrue; |
2128 | } | 2151 | } |
2152 | else if (equal_Command(cmd, "search")) { | ||
2153 | const int newTab = argLabel_Command(cmd, "newtab"); | ||
2154 | const iString *query = collect_String(suffix_Command(cmd, "query")); | ||
2155 | if (!isLikelyUrl_String(query)) { | ||
2156 | const iString *url = searchQueryUrl_App(query); | ||
2157 | if (!isEmpty_String(url)) { | ||
2158 | postCommandf_App("open newtab:%d url:%s", newTab, cstr_String(url)); | ||
2159 | } | ||
2160 | } | ||
2161 | else { | ||
2162 | postCommandf_App("open newtab:%d url:%s", newTab, cstr_String(query)); | ||
2163 | } | ||
2164 | return iTrue; | ||
2165 | } | ||
2129 | else if (equal_Command(cmd, "open")) { | 2166 | else if (equal_Command(cmd, "open")) { |
2130 | iString *url = collectNewCStr_String(suffixPtr_Command(cmd, "url")); | 2167 | iString *url = collectNewCStr_String(suffixPtr_Command(cmd, "url")); |
2131 | const iBool noProxy = argLabel_Command(cmd, "noproxy"); | 2168 | const iBool noProxy = argLabel_Command(cmd, "noproxy"); |