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 search-back ^R",
115 "bind goto-position ^XG",
116 "bind goto-position ^Xg",
117 "bind screen-recentre ^L",
119 "# Standard screen size parameters, plus keybindings to alter them",
122 "bind new-width ^XW",
123 "bind new-width ^Xw",
124 "bind new-offset ^XO",
125 "bind new-offset ^Xo",
127 "# Key bindings: overall program/file control",
130 "bind save-file ^X^S",
131 "# unbound by default: exit-and-save",
134 "bind diagnostics ^X^D",
137 "# End of default "RCNAME
,
143 void read_rc (void) {
145 char **p
, *q
, *r
, *s
, *keyseq
;
147 char rcname
[FILENAME_MAX
];
149 int errors
= FALSE
, errors_here
;
151 #if defined(unix) && !defined(GO32)
154 strcpy (rcname
, getenv("HOME"));
155 strcat (rcname
, "/.tweakrc");
158 * Use environment variable TWEAKRC if set. Otherwise, look for
159 * TWEAK.RC in the same directory as TWEAK.EXE, if _that_ exists,
160 * and failing everything else, try C:\TWEAK\TWEAK.RC.
162 if (getenv("TWEAKRC"))
163 strcpy (rcname
, getenv("TWEAKRC"));
165 if ( (q
= strrchr(pname
, '\\')) != NULL
) {
168 strncpy (rcname
, pname
, q
+1-pname
);
169 strcpy (rcname
+(q
+1-pname
), "TWEAK.RC");
170 if ( (tempfp
= fopen(rcname
, "r")) != NULL
)
173 strcpy (rcname
, "C:\\TWEAK\\TWEAK.RC");
175 strcpy (rcname
, "C:\\TWEAK\\TWEAK.RC");
179 { /* easy keybindings: self inserts */
182 for (i
=32; i
<127; i
++) {
184 bind_key (&c
, 1, act_self_ins
);
188 fp
= fopen(rcname
, "r");
192 if (!fgets(rcbuffer
, sizeof(rcbuffer
), fp
)) {
196 rcbuffer
[strcspn(rcbuffer
, "\r\n")] = '\0';
200 strcpy (rcbuffer
, *p
++);
206 * Now we have a line from the .rc file, wherever it's
207 * really come from. Process it.
210 while (*q
&& isspace((unsigned char)*q
))
213 if (!*q
|| *q
== '#')
214 continue; /* comment or blank line */
217 while (*r
&& !isspace((unsigned char)*r
))
223 * Now "q" points to the command word, "r" to the rest of
226 if (!strcmp(q
, "bind")) {
228 * It's a "bind" directive. The rest of the line should
229 * consist of an action name, then a single whitespace
230 * character, then a key sequence.
234 while (*r
&& isspace((unsigned char)*r
))
238 while (*q
&& !isspace((unsigned char)*q
))
243 fprintf(stderr
, "%s: no key sequence after \"bind\" command"
244 " on line %d of "RCNAME
, pname
, lineno
);
250 * "r" points to the action name; "q" to the key sequence.
256 fprintf(stderr
, "%s: nothing follows `^' on line %d"
257 " of "RCNAME
, pname
, lineno
);
263 } else if (*q
== '\\') {
265 fprintf(stderr
, "%s: nothing follows `\\' on line %d"
266 " of "RCNAME
, pname
, lineno
);
269 } else if (*q
== '\\' || *q
== '^') {
271 } else if (isxdigit((unsigned char)*q
) &&
272 q
[1] && isxdigit((unsigned char)q
[1])) {
277 *s
++ = strtol (buf
, NULL
, 16);
279 fprintf(stderr
, "%s: badly formed `\\' sequence on"
280 " line %d of "RCNAME
, pname
, lineno
);
290 if (!strcmp(r
, "quote-next")) {
292 * The "quote next" sequence requires special
297 for (i
=0; i
<256; i
++) {
299 bind_key (keyseq
, s
-keyseq
+1, act_self_ins
);
301 } else if ( (action
= parse_action (r
)) ) {
303 * An ordinary action, requiring ordinary treatment.
305 bind_key (keyseq
, s
-keyseq
, action
);
307 fprintf(stderr
, "%s: unrecognised key action \"%s\""
308 " at line %d of "RCNAME
"\n",
312 } else if (!strcmp(q
, "width")) {
314 } else if (!strcmp(q
, "offset")) {
315 realoffset
= atoi(r
);
317 fprintf(stderr
, "%s: unrecognised "RCNAME
" directive \"%s\""
318 " at line %d of "RCNAME
"\n",
327 void write_default_rc (void) {
330 for (p
= default_rc
; *p
; p
++)