Re: [Vimprobable-users] RC file consolidation
Vimprobable is a lean web browser optimised for full keyboard control
Brought to you by:
hanness
From: Matthew C. <je...@gm...> - 2012-01-16 03:14:45
|
Hi all, After reading Hans-Peter's post, I believe it may be more beneficial to leave these as seperate files - although an ideal solution from my point of view would be to combine the two options and allow these to be configured in the rc file or in the specific file(s). This could be expanded to include the other files (bookmarks, quickmarks, URI handlers), such that I could have an rc file that looked like: searchengine ... quickmark ... bookmark ... and the existing files as dynamically updated while running vimprobable. Just another opinion. Thanks, -Matt On Sun, Jan 15, 2012 at 04:34:36PM +0100, Hannes Schüller wrote: > Here is a patch merging the functionality of the searchengines > configuration file into vimprobablerc. See Hans-Peter's post > (http://sourceforge.net/mailarchive/message.php?msg_id=28666686) > concerning this subject. He brings up good points *against* this > (though I tried to preserve the advantages from the list of use cases > as far as possible). Nevertheless, so far, the consensus seemed to be to > merge it. So this is the last chance for major protest. > > Hannes > diff --git a/main.c b/main.c > index f106245..0508db5 100644 > --- a/main.c > +++ b/main.c > @@ -1,6 +1,6 @@ > /* > (c) 2009 by Leon Winter > - (c) 2009-2011 by Hannes Schueller > + (c) 2009-2012 by Hannes Schueller > (c) 2009-2010 by Matto Fransen > (c) 2010-2011 by Hans-Peter Deifel > (c) 2010-2011 by Thomas Adam > @@ -2491,7 +2491,6 @@ main(int argc, char *argv[]) { > static gboolean ver = false; > static gboolean configfile_exists = FALSE; > static const char *cfile = NULL; > - char *searchengines_file; > static GOptionEntry opts[] = { > { "version", 'v', 0, G_OPTION_ARG_NONE, &ver, "print version", NULL }, > { "embed", 'e', 0, G_OPTION_ARG_STRING, &winid, "embedded", NULL }, > @@ -2536,6 +2535,8 @@ main(int argc, char *argv[]) { > setup_cookies(); > #endif > > + make_searchengines_list(searchengines, LENGTH(searchengines)); > + > /* Check if the specified file exists. */ > /* And only warn the user, if they explicitly asked for a config on the > * command line. > @@ -2551,7 +2552,7 @@ main(int argc, char *argv[]) { > > /* read config file */ > /* But only report errors if we failed, and the file existed. */ > - if (!read_rcfile(configfile) && configfile_exists) { > + if ((SUCCESS != read_rcfile(configfile)) && configfile_exists) { > a.i = Error; > a.s = g_strdup_printf("Error in config file '%s'", configfile); > echo(&a); > @@ -2559,28 +2560,6 @@ main(int argc, char *argv[]) { > g_free(configfile); > } > > - make_searchengines_list(searchengines, LENGTH(searchengines)); > - > - /* read searchengines. */ > - searchengines_file = g_strdup_printf(SEARCHENGINES_STORAGE_FILENAME); > - switch (read_searchengines(searchengines_file)) { > - case SYNTAX_ERROR: > - a.i = Error; > - a.s = g_strdup_printf("Syntax error in searchengines file '%s'", searchengines_file); > - echo(&a); > - g_free(a.s); > - break; > - case READING_FAILED: > - a.i = Error; > - a.s = g_strdup_printf("Could not read searchengines file '%s'", searchengines_file); > - echo(&a); > - g_free(a.s); > - break; > - default: > - break; > - } > - g_free(searchengines_file); > - > /* command line argument: URL */ > if (argc > 1) { > strncpy(url, argv[argc - 1], 255); > diff --git a/utilities.c b/utilities.c > index fa0db44..431147c 100644 > --- a/utilities.c > +++ b/utilities.c > @@ -1,6 +1,6 @@ > /* > (c) 2009 by Leon Winter > - (c) 2009-2011 by Hannes Schueller > + (c) 2009-2012 by Hannes Schueller > (c) 2009-2010 by Matto Fransen > (c) 2010-2011 by Hans-Peter Deifel > (c) 2010-2011 by Thomas Adam > @@ -24,30 +24,6 @@ static GList *dynamic_searchengines = NULL; > > void add_modkeys(char key); > > -gboolean read_rcfile(const char *config) > -{ > - int t; > - char s[255]; > - FILE *fpin; > - gboolean returnval = TRUE; > - > - if ((fpin = fopen(config, "r")) == NULL) > - return FALSE; > - while (fgets(s, 254, fpin)) { > - /* > - * ignore lines that begin with #, / and such > - */ > - if (!isalpha(s[0])) > - continue; > - t = strlen(s); > - s[t - 1] = '\0'; > - if (!process_line(s)) > - returnval = FALSE; > - } > - fclose(fpin); > - return returnval; > -} > - > void save_command_history(char *line) > { > char *c = line; > @@ -709,71 +685,6 @@ static gboolean sanity_check_search_url(const char *string) > return !was_percent_char && percent_s_count == 1; > } > > -enum ConfigFileError > -read_searchengines(const char *filename) > -{ > - FILE *file; > - char buffer[BUFFERSIZE], c; > - int linum = 0, index; > - gboolean found_malformed_lines = FALSE; > - Searchengine *new; > - > - if (access(filename, F_OK) != 0) > - return FILE_NOT_FOUND; > - > - file = fopen(filename, "r"); > - if (file == NULL) > - return READING_FAILED; > - > - while (fgets(buffer, BUFFERSIZE, file)) { > - linum++; > - > - /* skip empty lines */ > - if (!strcmp(buffer, "\n")) continue; > - > - /* skip too long lines */ > - if (buffer[strlen(buffer)-1] != '\n') { > - c = getc(file); > - if (c != EOF) { /* this is not the last line */ > - while ((c=getc(file)) != EOF && c != '\n'); > - fprintf(stderr, "searchengines: syntax error on line %d\n", linum); > - found_malformed_lines = TRUE; > - continue; > - } > - } > - > - /* split line at whitespace */ > - index = split_string_at_whitespace(buffer); > - > - if (index < 0 || buffer[0] == '\0' || buffer[index] == '\0' > - || !sanity_check_search_url(buffer+index)) { > - fprintf(stderr, "searchengines: syntax error on line %d\n", linum); > - found_malformed_lines = TRUE; > - continue; > - } > - > - new = malloc(sizeof(Searchengine)); > - if (new == NULL) { > - fprintf(stderr, "Memory exhausted while loading search engines.\n"); > - exit(EXIT_FAILURE); > - } > - > - new->handle = g_strdup(buffer); > - new->uri = g_strdup(buffer+index); > - > - dynamic_searchengines = g_list_prepend(dynamic_searchengines, new); > - } > - > - if (ferror(file)) { > - fclose(file); > - return READING_FAILED; > - } > - > - fclose(file); > - > - return found_malformed_lines ? SYNTAX_ERROR : SUCCESS; > -} > - > void make_searchengines_list(Searchengine *searchengines, int length) > { > int i; > @@ -800,3 +711,57 @@ char *find_uri_for_searchengine(const char *handle) > > return NULL; > } > + > +enum ConfigFileError > +read_rcfile(const char *config) > +{ > + int t, linum = 0, index; > + char s[255], *buffer; > + FILE *fpin; > + gboolean found_malformed_lines = FALSE; > + Searchengine *new; > + > + if (access(config, F_OK) != 0) > + return FILE_NOT_FOUND; > + > + fpin = fopen(config, "r"); > + if (fpin == NULL) > + return READING_FAILED; > + > + while (fgets(s, 254, fpin)) { > + linum++; > + /* > + * ignore lines that begin with #, / and such > + */ > + if (!isalpha(s[0])) > + continue; > + t = strlen(s); > + s[t - 1] = '\0'; > + if (strncmp(s, "searchengine", 12) == 0) { > + buffer = (s + 12); > + while (buffer[0] == ' ') > + buffer++; > + /* split line at whitespace */ > + index = split_string_at_whitespace(buffer); > + if (index < 0 || buffer[0] == '\0' || buffer[index] == '\0' > + || !sanity_check_search_url(buffer+index)) { > + fprintf(stderr, "searchengines: syntax error on line %d\n", linum); > + found_malformed_lines = TRUE; > + continue; > + } > + new = malloc(sizeof(Searchengine)); > + if (new == NULL) { > + fprintf(stderr, "Memory exhausted while loading search engines.\n"); > + exit(EXIT_FAILURE); > + } > + new->handle = g_strdup(buffer); > + new->uri = g_strdup(buffer+index); > + dynamic_searchengines = g_list_prepend(dynamic_searchengines, new); > + } else { > + if (!process_line(s)) > + found_malformed_lines = TRUE; > + } > + } > + fclose(fpin); > + return found_malformed_lines ? SYNTAX_ERROR : SUCCESS; > +} > diff --git a/utilities.h b/utilities.h > index eec1277..9f4aacc 100644 > --- a/utilities.h > +++ b/utilities.h > @@ -1,6 +1,6 @@ > /* > (c) 2009 by Leon Winter > - (c) 2009-2011 by Hannes Schueller > + (c) 2009-2012 by Hannes Schueller > (c) 2009-2010 by Matto Fransen > (c) 2010-2011 by Hans-Peter Deifel > (c) 2010-2011 by Thomas Adam > @@ -13,7 +13,7 @@ > /* max entries in command history */ > #define COMMANDHISTSIZE 50 > > -gboolean read_rcfile(const char *config); > +enum ConfigFileError read_rcfile(const char *config); > void save_command_history(char *line); > gboolean process_save_qmark(const char *bm, WebKitWebView *webview); > void make_keyslist(void); > @@ -31,6 +31,5 @@ Listelement * add_list(const char *element, Listelement *elementlist); > int count_list(Listelement *elementlist); > void free_list(Listelement *elementlist); > > -enum ConfigFileError read_searchengines(const char *filename); > char *find_uri_for_searchengine(const char *handle); > void make_searchengines_list(Searchengine *searchengines, int length); > diff --git a/vimprobable.h b/vimprobable.h > index b0176b7..1ac9030 100644 > --- a/vimprobable.h > +++ b/vimprobable.h > @@ -1,6 +1,6 @@ > /* > (c) 2009 by Leon Winter > - (c) 2009-2011 by Hannes Schueller > + (c) 2009-2012 by Hannes Schueller > (c) 2009-2010 by Matto Fransen > (c) 2010-2011 by Hans-Peter Deifel > (c) 2010-2011 by Thomas Adam > @@ -176,9 +176,6 @@ enum ConfigFileError { > #define HISTORY_STORAGE_FILENAME "%s/vimprobable/history", config_base > #define CLOSED_URL_FILENAME "%s/vimprobable/closed", config_base > > -/* searchengines */ > -#define SEARCHENGINES_STORAGE_FILENAME "%s/vimprobable/searchengines", config_base > - > /* Command size */ > #define COMMANDSIZE 1024 > > diff --git a/vimprobable2.1 b/vimprobable2.1 > index a780e6a..92706ac 100644 > --- a/vimprobable2.1 > +++ b/vimprobable2.1 > @@ -1,7 +1,7 @@ > .\" Process this file with > .\" groff -man -Tascii vimprobable2.1 > .\" > -.TH VIMPROBABLE2 1 "JANUARY 2010" "Linux User Manuals" > +.TH VIMPROBABLE2 1 "JANUARY 2012" "Linux User Manuals" > .SH NAME > Vimprobable \- A WWW browser based on webkit with keybindings inspired by Vim, the great editor. > > @@ -313,22 +313,13 @@ https://secure.wikimedia.org/wikipedia/de/w/index.php?title=Special%%3ASearch&se > .P > > You can always overwrite them or define your own in > -.I $HOME/.config/vimprobable/searchengines. > -In this file, every line defines one shortcut for one URL in the following > -format (without the angle brackets): > - > -.RS 4 > -<shortcut> <URL with exactly one %s> > -.RE > - > -where the %s serves as a placeholder for the search term. Other percent signs > -in the URL have to be escaped as %%\&. > - > +.I $HOME/.config/vimprobable/vimprobablerc. > +See vimprobablerc (5) for details. > .B Default search engine > > If Vimprobable doesn't recognize an address as a valid URL or query to one of the > defined search engines, it will use the default search engine instead. See > -.BR vimprobablerc (1) > +.BR vimprobablerc (5) > on how to set this default. > > .SH FILES > @@ -341,8 +332,6 @@ file is required if you want to use cookies. > > .I $HOME/.config/vimprobable/bookmarks > > -.I $HOME/.config/vimprobable/searchengines > - > .I $HOME/.config/vimprobable/cookies > > .I $HOME/.config/vimprobable/history > diff --git a/vimprobablerc.5 b/vimprobablerc.5 > index 31755aa..7d85bb2 100644 > --- a/vimprobablerc.5 > +++ b/vimprobablerc.5 > @@ -1,7 +1,7 @@ > .\" Process this file with > .\" groff -man -Tascii vimprobablerc.5 > .\" > -.TH VIMPROBABLERC 5 "December 2009" "Linux User Manuals" > +.TH VIMPROBABLERC 5 "January 2012" "Linux User Manuals" > .SH NAME > vimprobablerc \- The configuration file for Vimprobable > .SH DESCRIPTION > @@ -228,6 +228,18 @@ All settings can be changed on the fly by entering > :set followed by one of the commands in the SETTINGS section > above. > > +.SH SEARCH ENGINES > + > +You can define new search engine shortcuts or override the pre-defined ones > +using the following format (without the angle brackets): > + > +.RS 4 > +searchengine <shortcut> <URL with exactly one %s> > +.RE > + > +where the %s serves as a placeholder for the search term. Other percent signs > +in the URL have to be escaped as %%\&. > + > .SH BUGS > There has not been any significant bug-hunting yet. > .SH AUTHORS > ------------------------------------------------------------------------------ > RSA(R) Conference 2012 > Mar 27 - Feb 2 > Save $400 by Jan. 27 > Register now! > http://p.sf.net/sfu/rsa-sfdev2dev2 > _______________________________________________ > Vimprobable-users mailing list > Vim...@li... > https://lists.sourceforge.net/lists/listinfo/vimprobable-users -- Matthew Carter je...@gm... |