diff options
Diffstat (limited to 'src/gmutil.c')
-rw-r--r-- | src/gmutil.c | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/src/gmutil.c b/src/gmutil.c index ecfe2128..b32722ac 100644 --- a/src/gmutil.c +++ b/src/gmutil.c | |||
@@ -22,6 +22,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
22 | 22 | ||
23 | #include "gmutil.h" | 23 | #include "gmutil.h" |
24 | #include "fontpack.h" | 24 | #include "fontpack.h" |
25 | #include "lang.h" | ||
26 | #include "sitespec.h" | ||
27 | #include "ui/color.h" | ||
25 | 28 | ||
26 | #include <the_Foundation/file.h> | 29 | #include <the_Foundation/file.h> |
27 | #include <the_Foundation/fileinfo.h> | 30 | #include <the_Foundation/fileinfo.h> |
@@ -277,6 +280,19 @@ const iBlock *urlThemeSeed_String(const iString *url) { | |||
277 | return collect_Block(newRange_Block(user)); | 280 | return collect_Block(newRange_Block(user)); |
278 | } | 281 | } |
279 | 282 | ||
283 | const iBlock *urlPaletteSeed_String(const iString *url) { | ||
284 | if (equalCase_Rangecc(urlScheme_String(url), "file")) { | ||
285 | return urlThemeSeed_String(url); | ||
286 | } | ||
287 | /* Check for a site-specific setting. */ | ||
288 | const iString *seed = | ||
289 | valueString_SiteSpec(collectNewRange_String(urlRoot_String(url)), paletteSeed_SiteSpecKey); | ||
290 | if (!isEmpty_String(seed)) { | ||
291 | return utf8_String(seed); | ||
292 | } | ||
293 | return urlThemeSeed_String(url); | ||
294 | } | ||
295 | |||
280 | static iBool isAbsolutePath_(iRangecc path) { | 296 | static iBool isAbsolutePath_(iRangecc path) { |
281 | return isAbsolute_Path(collect_String(urlDecode_String(collect_String(newRange_String(path))))); | 297 | return isAbsolute_Path(collect_String(urlDecode_String(collect_String(newRange_String(path))))); |
282 | } | 298 | } |
@@ -735,13 +751,36 @@ const iString *canonicalUrl_String(const iString *d) { | |||
735 | return canon ? collect_String(canon) : d; | 751 | return canon ? collect_String(canon) : d; |
736 | } | 752 | } |
737 | 753 | ||
754 | const iString *prettyDataUrl_String(const iString *d, int contentColor) { | ||
755 | iUrl url; | ||
756 | init_Url(&url, d); | ||
757 | if (!equalCase_Rangecc(url.scheme, "data")) { | ||
758 | return d; | ||
759 | } | ||
760 | iString *pretty = new_String(); | ||
761 | const char *comma = strchr(url.path.start, ','); | ||
762 | if (!comma) { | ||
763 | comma = iMin(constEnd_String(d), constBegin_String(d) + 256); | ||
764 | } | ||
765 | appendRange_String(pretty, (iRangecc){ constBegin_String(d), comma }); | ||
766 | if (size_Range(&url.path)) { | ||
767 | if (contentColor != none_ColorId) { | ||
768 | appendCStr_String(pretty, escape_Color(contentColor)); | ||
769 | } | ||
770 | appendCStr_String(pretty, " ("); | ||
771 | appendCStr_String(pretty, formatCStrs_Lang("num.bytes.n", size_Range(&url.path))); | ||
772 | appendCStr_String(pretty, ")"); | ||
773 | } | ||
774 | return collect_String(pretty); | ||
775 | } | ||
776 | |||
738 | iRangecc mediaTypeWithoutParameters_Rangecc(iRangecc mime) { | 777 | iRangecc mediaTypeWithoutParameters_Rangecc(iRangecc mime) { |
739 | iRangecc part = iNullRange; | 778 | iRangecc part = iNullRange; |
740 | nextSplit_Rangecc(mime, ";", &part); | 779 | nextSplit_Rangecc(mime, ";", &part); |
741 | return part; | 780 | return part; |
742 | } | 781 | } |
743 | 782 | ||
744 | const iString *feedEntryOpenCommand_String(const iString *url, int newTab) { | 783 | const iString *feedEntryOpenCommand_String(const iString *url, int newTab, int newWindow) { |
745 | if (!isEmpty_String(url)) { | 784 | if (!isEmpty_String(url)) { |
746 | iString *cmd = collectNew_String(); | 785 | iString *cmd = collectNew_String(); |
747 | const size_t fragPos = indexOf_String(url, '#'); | 786 | const size_t fragPos = indexOf_String(url, '#'); |
@@ -749,15 +788,20 @@ const iString *feedEntryOpenCommand_String(const iString *url, int newTab) { | |||
749 | iString *head = newRange_String( | 788 | iString *head = newRange_String( |
750 | (iRangecc){ constBegin_String(url) + fragPos + 1, constEnd_String(url) }); | 789 | (iRangecc){ constBegin_String(url) + fragPos + 1, constEnd_String(url) }); |
751 | format_String(cmd, | 790 | format_String(cmd, |
752 | "open fromsidebar:1 newtab:%d gotourlheading:%s url:%s", | 791 | "open fromsidebar:1 newtab:%d newwindow:%d gotourlheading:%s url:%s", |
753 | newTab, | 792 | newTab, |
793 | newWindow, | ||
754 | cstr_String(head), | 794 | cstr_String(head), |
755 | cstr_Rangecc((iRangecc){ constBegin_String(url), | 795 | cstr_Rangecc((iRangecc){ constBegin_String(url), |
756 | constBegin_String(url) + fragPos })); | 796 | constBegin_String(url) + fragPos })); |
757 | delete_String(head); | 797 | delete_String(head); |
758 | } | 798 | } |
759 | else { | 799 | else { |
760 | format_String(cmd, "open fromsidebar:1 newtab:%d url:%s", newTab, cstr_String(url)); | 800 | format_String(cmd, |
801 | "open fromsidebar:1 newtab:%d newwindow:%d url:%s", | ||
802 | newTab, | ||
803 | newWindow, | ||
804 | cstr_String(url)); | ||
761 | } | 805 | } |
762 | return cmd; | 806 | return cmd; |
763 | } | 807 | } |
@@ -901,40 +945,3 @@ const iGmError *get_GmError(enum iGmStatusCode code) { | |||
901 | return &errors_[0].err; /* unknown */ | 945 | return &errors_[0].err; /* unknown */ |
902 | } | 946 | } |
903 | 947 | ||
904 | int replaceRegExp_String(iString *d, const iRegExp *regexp, const char *replacement, | ||
905 | void (*matchHandler)(void *, const iRegExpMatch *), | ||
906 | void *context) { | ||
907 | iRegExpMatch m; | ||
908 | iString result; | ||
909 | int numMatches = 0; | ||
910 | const char *pos = constBegin_String(d); | ||
911 | init_RegExpMatch(&m); | ||
912 | init_String(&result); | ||
913 | while (matchString_RegExp(regexp, d, &m)) { | ||
914 | appendRange_String(&result, (iRangecc){ pos, begin_RegExpMatch(&m) }); | ||
915 | /* Replace any capture group back-references. */ | ||
916 | for (const char *ch = replacement; *ch; ch++) { | ||
917 | if (*ch == '\\') { | ||
918 | ch++; | ||
919 | if (*ch == '\\') { | ||
920 | appendCStr_String(&result, "\\"); | ||
921 | } | ||
922 | else if (*ch >= '0' && *ch <= '9') { | ||
923 | appendRange_String(&result, capturedRange_RegExpMatch(&m, *ch - '0')); | ||
924 | } | ||
925 | } | ||
926 | else { | ||
927 | appendData_Block(&result.chars, ch, 1); | ||
928 | } | ||
929 | } | ||
930 | if (matchHandler) { | ||
931 | matchHandler(context, &m); | ||
932 | } | ||
933 | pos = end_RegExpMatch(&m); | ||
934 | numMatches++; | ||
935 | } | ||
936 | appendRange_String(&result, (iRangecc){ pos, constEnd_String(d) }); | ||
937 | set_String(d, &result); | ||
938 | deinit_String(&result); | ||
939 | return numMatches; | ||
940 | } | ||