8 #if defined(unix) && !defined(GO32)
9 #define RCNAME ".tweakrc"
11 #define RCNAME "tweak.rc"
14 static char *default_rc
[] = {
15 "# Default "RCNAME
" generated by `tweak -D'.",
17 "# Key bindings: movement keys",
18 "bind top-of-file ^[<",
19 #if defined(unix) && !defined(GO32)
28 #if defined(unix) && !defined(GO32)
34 #if defined(unix) && !defined(GO32)
35 "bind begin-line ^[[H",
36 "bind begin-line ^[[1~",
38 "bind begin-line ^@G",
41 #if defined(unix) && !defined(GO32)
42 "bind move-left ^[[D",
47 #if defined(unix) && !defined(GO32)
48 "bind move-right ^[[C",
50 "bind move-right ^@M",
53 #if defined(unix) && !defined(GO32)
55 "bind end-line ^[[4~",
60 #if defined(unix) && !defined(GO32)
61 "bind move-down ^[[B",
66 #if defined(unix) && !defined(GO32)
67 "bind page-down ^[[6~",
71 "bind bottom-of-file ^[>",
73 "# Key bindings: miscellaneous editing keys",
74 "bind toggle-insert ^X^I",
75 #if defined(unix) && !defined(GO32)
76 "bind toggle-insert ^[[2~",
78 "bind toggle-insert ^@R",
80 "bind change-mode ^M",
81 "bind change-mode ^J",
83 "bind toggle-status ^XH",
84 "bind toggle-status ^Xh",
85 "bind toggle-status ^XX",
86 "bind toggle-status ^Xx",
88 "# Key bindings: deletion keys",
89 "bind delete-left ^?",
90 "bind delete-left ^H",
91 "bind delete-right ^D",
92 #if defined(unix) && !defined(GO32)
93 "bind delete-right ^[[3~",
95 "bind delete-right ^@S",
98 "# Key bindings: cut and paste keys",
99 #if defined(unix) && !defined(GO32)
100 "bind mark-place ^@",
102 "bind mark-place ^@^C",
112 "# Key bindings: additional movement keys",
114 "bind goto-position ^XG",
115 "bind goto-position ^Xg",
116 "bind screen-recentre ^L",
118 "# Standard screen size parameters, plus keybindings to alter them",
121 "bind new-width ^XW",
122 "bind new-width ^Xw",
123 "bind new-offset ^XO",
124 "bind new-offset ^Xo",
126 "# Key bindings: overall program/file control",
129 "bind save-file ^X^S",
130 "# unbound by default: exit-and-save",
133 "bind diagnostics ^X^D",
136 "# End of default "RCNAME
,
142 void read_rc (void) {
144 char **p
, *q
, *r
, *s
, *keyseq
;
146 char rcname
[FILENAME_MAX
];
148 int errors
= FALSE
, errors_here
;
150 #if defined(unix) && !defined(GO32)
153 strcpy (rcname
, getenv("HOME"));
154 strcat (rcname
, "/.tweakrc");
157 * Use environment variable TWEAKRC if set. Otherwise, look for
158 * TWEAK.RC in the same directory as TWEAK.EXE, if _that_ exists,
159 * and failing everything else, try C:\TWEAK\TWEAK.RC.
161 if (getenv("TWEAKRC"))
162 strcpy (rcname
, getenv("TWEAKRC"));
164 if ( (q
= strrchr(pname
, '\\')) != NULL
) {
167 strncpy (rcname
, pname
, q
+1-pname
);
168 strcpy (rcname
+(q
+1-pname
), "TWEAK.RC");
169 if ( (tempfp
= fopen(rcname
, "r")) != NULL
)
172 strcpy (rcname
, "C:\\TWEAK\\TWEAK.RC");
174 strcpy (rcname
, "C:\\TWEAK\\TWEAK.RC");
178 { /* easy keybindings: self inserts */
181 for (i
=32; i
<127; i
++) {
183 bind_key (&c
, 1, act_self_ins
);
187 fp
= fopen(rcname
, "r");
191 if (!fgets(rcbuffer
, sizeof(rcbuffer
), fp
)) {
195 rcbuffer
[strcspn(rcbuffer
, "\r\n")] = '\0';
199 strcpy (rcbuffer
, *p
++);
205 * Now we have a line from the .rc file, wherever it's
206 * really come from. Process it.
209 while (*q
&& isspace(*q
))
212 if (!*q
|| *q
== '#')
213 continue; /* comment or blank line */
216 while (*r
&& !isspace(*r
))
222 * Now "q" points to the command word, "r" to the rest of
225 if (!strcmp(q
, "bind")) {
227 * It's a "bind" directive. The rest of the line should
228 * consist of an action name, then a single whitespace
229 * character, then a key sequence.
233 while (*r
&& isspace(*r
))
237 while (*q
&& !isspace(*q
))
242 fprintf(stderr
, "%s: no key sequence after \"bind\" command"
243 " on line %d of "RCNAME
, pname
, lineno
);
249 * "r" points to the action name; "q" to the key sequence.
255 fprintf(stderr
, "%s: nothing follows `^' on line %d"
256 " of "RCNAME
, pname
, lineno
);
262 } else if (*q
== '\\') {
264 fprintf(stderr
, "%s: nothing follows `\\' on line %d"
265 " of "RCNAME
, pname
, lineno
);
268 } else if (*q
== '\\' || *q
== '^') {
270 } else if (isxdigit(*q
) && q
[1] && isxdigit(q
[1])) {
275 *s
++ = strtol (buf
, NULL
, 16);
277 fprintf(stderr
, "%s: badly formed `\\' sequence on"
278 " line %d of "RCNAME
, pname
, lineno
);
288 if (!strcmp(r
, "quote-next")) {
290 * The "quote next" sequence requires special
295 for (i
=0; i
<256; i
++) {
297 bind_key (keyseq
, s
-keyseq
+1, act_self_ins
);
299 } else if ( (action
= parse_action (r
)) ) {
301 * An ordinary action, requiring ordinary treatment.
303 bind_key (keyseq
, s
-keyseq
, action
);
305 fprintf(stderr
, "%s: unrecognised key action \"%s\""
306 " at line %d of "RCNAME
"\n",
310 } else if (!strcmp(q
, "width")) {
312 } else if (!strcmp(q
, "offset")) {
313 realoffset
= atoi(r
);
315 fprintf(stderr
, "%s: unrecognised "RCNAME
" directive \"%s\""
316 " at line %d of "RCNAME
"\n",
325 void write_default_rc (void) {
328 for (p
= default_rc
; *p
; p
++)