don't change internal mode if the window doesn't have focus (fixes the bug/incompatib...
[vimprobable2.git] / utilities.c
blob9fdbc26e85136ae881ce89e72f8ea7174aa514f5
1 /*
2 (c) 2009 by Leon Winter
3 (c) 2009, 2010 by Hannes Schueller
4 (c) 2009, 2010 by Matto Fransen
5 see LICENSE file
6 */
8 #include "includes.h"
9 #include "vimprobable.h"
10 #include "main.h"
11 #include "utilities.h"
13 extern char commandhistory[COMMANDHISTSIZE][255];
14 extern int lastcommand, maxcommands, commandpointer;
16 gboolean read_rcfile(void)
18 int t;
19 char s[255];
20 const char *rcfile;
21 FILE *fpin;
22 gboolean returnval = TRUE;
24 rcfile = g_strdup_printf(RCFILE);
25 if ((fpin = fopen(rcfile, "r")) == NULL)
26 return TRUE;
27 while (fgets(s, 254, fpin)) {
29 * ignore lines that begin with #, / and such
31 if (!isalpha(s[0]))
32 continue;
33 t = strlen(s);
34 s[t - 1] = '\0';
35 if (!process_line(s))
36 returnval = FALSE;
38 fclose(fpin);
39 return returnval;
42 void save_command_history(char *line)
44 char *c;
46 c = line;
47 while (isspace(*c) && *c)
48 c++;
49 if (!strlen(c))
50 return;
51 strncpy(commandhistory[lastcommand], c, 254);
52 lastcommand++;
53 if (maxcommands < COMMANDHISTSIZE - 1)
54 maxcommands++;
55 if (lastcommand == COMMANDHISTSIZE)
56 lastcommand = 0;
57 commandpointer = lastcommand;
60 gboolean
61 process_save_qmark(const char *bm, WebKitWebView *webview)
63 FILE *fp;
64 const char *filename;
65 const char *uri = webkit_web_view_get_uri(webview);
66 char qmarks[10][101];
67 char buf[100];
68 int i, mark, l=0;
69 Arg a;
70 mark = -1;
71 mark = atoi(bm);
72 if ( mark < 1 || mark > 9 )
74 a.i = Error;
75 a.s = g_strdup_printf("Invalid quickmark, only 1-9");
76 echo(&a);
77 g_free(a.s);
78 return TRUE;
80 if ( uri == NULL ) return FALSE;
81 for( i=0; i < 9; ++i ) strcpy( qmarks[i], "");
83 filename = g_strdup_printf(QUICKMARK_FILE);
85 /* get current quickmarks */
87 fp = fopen(filename, "r");
88 if (fp != NULL){
89 for( i=0; i < 10; ++i ) {
90 if (feof(fp)) {
91 break;
93 fgets(buf, 100, fp);
94 l = 0;
95 while (buf[l] && l < 100 && buf[l] != '\n') {
96 qmarks[i][l]=buf[l];
97 l++;
99 qmarks[i][l]='\0';
101 fclose(fp);
104 /* save quickmarks */
105 strcpy( qmarks[mark-1], uri );
106 fp = fopen(filename, "w");
107 if (fp == NULL) return FALSE;
108 for( i=0; i < 10; ++i )
109 fprintf(fp, "%s\n", qmarks[i]);
110 fclose(fp);
111 a.i = Error;
112 a.s = g_strdup_printf("Saved as quickmark %d: %s", mark, uri);
113 echo(&a);
114 g_free(a.s);
116 return TRUE;