--- sample.urlview Jul 2000 09:05:10 -0000 1.1.1.1 +++ sample.urlview Jan 2003 08:30:51 -0000 @@ -28 +28,12 @@ COMMAND url_handler.sh +# Switch for generating HTML output +#HTMLOUT + +# Template string for HTML body (outer layer) (%s contains generated inner layer of HTML_LINKs) +#HTML_TEMPLATE
    \n%s
\n +#HTML_TEMPLATE %s\n +#HTML_TEMPLATE urlview generated links%s + +# Template string for HTML link entry (inner layer) per URL (both %s contain the URL) +#HTML_LINK
  • %s\n +#HTML_LINK %s
    \n --- urlview.1 Jul 2000 19:32:31 -0000 1.1 +++ urlview.1 Jan 2003 08:30:51 -0000 @@ -76,2 +76,16 @@ shouldn't happen with the default regula explicitly excludes single quotes.) +.TP +HTMLOUT +This switch will force \fBurlview\fP to generate HTML output (on stdout). +.TP +HTML_TEMPLATE \fItemplate\fP +When HTMLOUT is set, this specifies the template string for the HTML body (outer layer). +To be useful, \fItemplate\fP must contain \fB%s\fP, which represents the set of +HTML links (inner layer) as specified below. +.TP +HTML_LINK \fIlink\fP +When HTMLOUT is set, this specifies the template string for HTML links (inner layer). +To be useful, \fIlink\fP must contain at least one \fB%s\fP, which represents the URL; +a second \fB%s\fP may also be used (and it also contains the URL). The \fIlink\fP +will almost certainly use both \fB%s\fP instances. .SH FILES --- urlview.c Jul 2000 06:26:52 -0000 1.4 +++ urlview.c Jan 2003 08:30:51 -0000 @@ -63,2 +63,4 @@ #define SYSTEM_INITFILE "/etc/urlview.conf" +#define DEFAULT_HTML_TEMPLATE "
      \n%s
    \n" /* or "%s" */ +#define DEFAULT_HTML_LINK "
  • %s\n" /* or "%s
    \n" */ @@ -155,2 +157,58 @@ void search_backward (char *search, int } + +void html_out (int urlcount, char **url, char *html_template, char *html_link) +{ + char *links = 0; + size_t n = 0; + size_t len = 0; + int i; + + links = (char *) malloc (1); + for (i = 0; i < urlcount; i++) + { + n = 2 * strlen (url[i]) + strlen (html_link); + links = (char *) realloc (links, len + n + 1); + n = snprintf (links + len, n+1, html_link, url[i], url[i]); + len += n; + } + + printf (html_template, links); +} + +void escape_string (char *wc, char *pc) +{ + while (ISSPACE (*pc)) + pc++; + + while (*pc && *pc != '\n') + { + if (*pc == '\\') + { + pc++; + switch (*pc) + { + case 'n': + *wc++ = '\n'; + break; + case 'r': + *wc++ = '\r'; + break; + case 't': + *wc++ = '\t'; + break; + case 'f': + *wc++ = '\f'; + break; + default: + *wc++ = '\\'; + *wc++ = *pc; + break; + } + } + else + *wc++ = *pc; + pc++; + } + *wc = 0; +} @@ -171,2 +229,4 @@ int main (int argc, char **argv) char scratch[1024]; + char html_template[1024]; + char html_link[1024]; char **url; @@ -190,2 +250,3 @@ int main (int argc, char **argv) int expert = 0; + int html = 0; @@ -196,2 +257,4 @@ int main (int argc, char **argv) strncpy (command, DEFAULT_COMMAND, sizeof (command) - 1); + strncpy (html_template, DEFAULT_HTML_TEMPLATE, sizeof (html_template) - 1); + strncpy (html_link, DEFAULT_HTML_LINK, sizeof (html_link) - 1); memset((void *)search, 0, sizeof(search)); @@ -215,36 +278,3 @@ int main (int argc, char **argv) { - pc = buf + 6; - while (ISSPACE (*pc)) - pc++; - wc = regexp; - while (*pc && *pc != '\n') - { - if (*pc == '\\') - { - pc++; - switch (*pc) - { - case 'n': - *wc++ = '\n'; - break; - case 'r': - *wc++ = '\r'; - break; - case 't': - *wc++ = '\t'; - break; - case 'f': - *wc++ = '\f'; - break; - default: - *wc++ = '\\'; - *wc++ = *pc; - break; - } - } - else - *wc++ = *pc; - pc++; - } - *wc = 0; + escape_string (regexp, buf + 6); } @@ -259,2 +289,10 @@ int main (int argc, char **argv) } + else if (strncmp ("HTML_TEMPLATE", buf, 13) == 0 && ISSPACE (buf[13])) + { + escape_string (html_template, buf + 13); + } + else if (strncmp ("HTML_LINK", buf, 9) == 0 && ISSPACE (buf[9])) + { + escape_string (html_link, buf + 9); + } else if (strcmp ("EXPERT\n", buf) == 0) @@ -263,2 +301,6 @@ int main (int argc, char **argv) } + else if (strcmp("HTMLOUT\n", buf) == 0) + { + html = 1; + } else @@ -368,2 +410,7 @@ into a line of its own in your \n\ + if (html) + { + html_out (urlcount, url, html_template, html_link); + exit (0); + } /*** present the URLs to the user ***/ --- urlview.conf.suse Jul 2000 09:05:10 -0000 1.1.1.1 +++ urlview.conf.suse Jan 2003 08:30:51 -0000 @@ -8,2 +8,4 @@ # COMMAND url_handler.sh '%s' +# HTML_TEMPLATE
      \n%s
    \n +# HTML_LINK
  • %s\n #