New upstream release.
Debian Janitor
2 years ago
0 | 0 | /tags.c/1.16/Result of merge// |
1 | 1 | /undo.c/1.58/Tue Apr 10 04:57:08 2018// |
2 | /region.c/1.38/Result of merge// | |
3 | 2 | /Makefile/1.35/Result of merge// |
4 | /dired.c/1.93/Result of merge// | |
5 | /fileio.c/1.106/Result of merge// | |
6 | /main.c/1.87/Result of merge// | |
7 | /ttyio.c/1.38/Result of merge// | |
8 | /def.h/1.166/Result of merge+Sat Feb 15 14:26:34 2020// | |
9 | /README/1.14/Thu Mar 12 08:13:18 2020// | |
10 | /autoexec.c/1.17/Thu Mar 12 08:13:18 2020// | |
11 | /basic.c/1.49/Thu Mar 12 08:13:18 2020// | |
12 | /bell.c/1.5/Thu Mar 12 08:13:18 2020// | |
13 | /buffer.c/1.107/Thu Mar 12 08:13:18 2020// | |
14 | /chrdef.h/1.10/Thu Mar 12 08:13:18 2020// | |
15 | /cinfo.c/1.18/Thu Mar 12 08:13:18 2020// | |
16 | /cmode.c/1.17/Thu Mar 12 08:13:18 2020// | |
17 | /cscope.c/1.18/Thu Mar 12 08:13:18 2020// | |
18 | /dir.c/1.31/Thu Mar 12 08:13:18 2020// | |
19 | /display.c/1.48/Thu Mar 12 08:13:18 2020// | |
20 | /echo.c/1.66/Thu Mar 12 08:13:18 2020// | |
21 | /extend.c/1.71/Thu Mar 12 08:13:18 2020// | |
22 | /file.c/1.102/Thu Mar 12 08:13:18 2020// | |
23 | /funmap.c/1.59/Thu Mar 12 08:13:18 2020// | |
24 | /funmap.h/1.8/Thu Mar 12 08:13:18 2020// | |
25 | /grep.c/1.48/Thu Mar 12 08:13:18 2020// | |
26 | /help.c/1.35/Thu Mar 12 08:13:18 2020// | |
27 | /interpreter.c/1.5/Thu Mar 12 08:13:18 2020// | |
28 | /kbd.c/1.34/Thu Mar 12 08:13:18 2020// | |
29 | /kbd.h/1.19/Thu Mar 12 08:13:18 2020// | |
30 | /key.h/1.6/Thu Mar 12 08:13:18 2020// | |
31 | /keymap.c/1.58/Thu Mar 12 08:13:18 2020// | |
32 | /log.c/1.11/Thu Mar 12 08:13:18 2020// | |
33 | /log.h/1.5/Thu Mar 12 08:13:18 2020// | |
34 | /macro.c/1.16/Thu Mar 12 08:13:18 2020// | |
35 | /macro.h/1.7/Thu Mar 12 08:13:18 2020// | |
36 | /match.c/1.21/Thu Mar 12 08:13:18 2020// | |
37 | /mg.1/1.118/Thu Mar 12 08:13:18 2020// | |
38 | /modes.c/1.21/Thu Mar 12 08:13:18 2020// | |
39 | /paragraph.c/1.46/Thu Mar 12 08:13:18 2020// | |
40 | /pathnames.h/1.1/Thu Mar 12 08:13:18 2020// | |
41 | /search.c/1.47/Thu Mar 12 08:13:18 2020// | |
42 | /spawn.c/1.12/Thu Mar 12 08:13:18 2020// | |
43 | /tty.c/1.37/Thu Mar 12 08:13:18 2020// | |
44 | /ttykbd.c/1.19/Thu Mar 12 08:13:18 2020// | |
45 | /tutorial/1.18/Thu Mar 12 08:13:18 2020// | |
46 | /util.c/1.42/Thu Mar 12 08:13:18 2020// | |
47 | /version.c/1.10/Thu Mar 12 08:13:18 2020// | |
48 | /window.c/1.36/Thu Mar 12 08:13:18 2020// | |
49 | /word.c/1.19/Thu Mar 12 08:13:18 2020// | |
50 | /yank.c/1.14/Thu Mar 12 08:13:18 2020// | |
51 | /line.c/1.62/Thu Jul 23 17:18:45 2020// | |
52 | 3 | /re_search.c/1.35/Result of merge// |
4 | /README/1.14/Fri Jul 31 12:06:05 2020// | |
5 | /autoexec.c/1.17/Fri Jul 31 12:06:05 2020// | |
6 | /bell.c/1.5/Fri Jul 31 12:06:05 2020// | |
7 | /chrdef.h/1.10/Fri Jul 31 12:06:05 2020// | |
8 | /cinfo.c/1.18/Fri Jul 31 12:06:05 2020// | |
9 | /cmode.c/1.17/Fri Jul 31 12:06:05 2020// | |
10 | /dir.c/1.31/Fri Jul 31 12:06:05 2020// | |
11 | /display.c/1.48/Fri Jul 31 12:06:05 2020// | |
12 | /file.c/1.102/Fri Jul 31 12:06:05 2020// | |
13 | /funmap.c/1.59/Fri Jul 31 12:06:05 2020// | |
14 | /funmap.h/1.8/Fri Jul 31 12:06:05 2020// | |
15 | /help.c/1.35/Fri Jul 31 12:06:05 2020// | |
16 | /kbd.h/1.19/Fri Jul 31 12:06:05 2020// | |
17 | /key.h/1.6/Fri Jul 31 12:06:05 2020// | |
18 | /keymap.c/1.58/Fri Jul 31 12:06:05 2020// | |
19 | /macro.c/1.16/Fri Jul 31 12:06:05 2020// | |
20 | /macro.h/1.7/Fri Jul 31 12:06:05 2020// | |
21 | /modes.c/1.21/Fri Jul 31 12:06:05 2020// | |
22 | /paragraph.c/1.46/Fri Jul 31 12:06:05 2020// | |
23 | /pathnames.h/1.1/Fri Jul 31 12:06:05 2020// | |
24 | /search.c/1.47/Fri Jul 31 12:06:05 2020// | |
25 | /spawn.c/1.12/Fri Jul 31 12:06:05 2020// | |
26 | /tutorial/1.18/Fri Jul 31 12:06:05 2020// | |
27 | /version.c/1.10/Fri Jul 31 12:06:05 2020// | |
28 | /window.c/1.36/Fri Jul 31 12:06:05 2020// | |
29 | /word.c/1.19/Fri Jul 31 12:06:05 2020// | |
30 | /basic.c/1.50/Sun Feb 28 21:39:49 2021// | |
31 | /main.c/1.88/Result of merge// | |
32 | /mg.1/1.120/Sun Feb 28 21:39:49 2021// | |
33 | /ttykbd.c/1.20/Sun Feb 28 21:39:49 2021// | |
34 | /buffer.c/1.109/Sun Mar 14 13:15:43 2021// | |
35 | /cscope.c/1.20/Sun Mar 14 13:15:43 2021// | |
36 | /def.h/1.168/Result of merge// | |
37 | /dired.c/1.98/Result of merge// | |
38 | /echo.c/1.68/Sun Mar 14 13:15:43 2021// | |
39 | /extend.c/1.72/Sun Mar 14 13:15:43 2021// | |
40 | /fileio.c/1.108/Result of merge// | |
41 | /grep.c/1.49/Sun Mar 14 13:15:43 2021// | |
42 | /interpreter.c/1.9/Sun Mar 14 13:15:43 2021// | |
43 | /kbd.c/1.35/Sun Mar 14 13:15:43 2021// | |
44 | /line.c/1.63/Sun Mar 14 13:15:43 2021// | |
45 | /log.c/1.12/Sun Mar 14 13:15:43 2021// | |
46 | /log.h/1.6/Sun Mar 14 13:15:43 2021// | |
47 | /match.c/1.22/Sun Mar 14 13:15:43 2021// | |
48 | /region.c/1.39/Result of merge// | |
49 | /tty.c/1.38/Sun Mar 14 13:15:43 2021// | |
50 | /ttyio.c/1.39/Result of merge// | |
51 | /util.c/1.43/Sun Mar 14 13:15:44 2021// | |
52 | /yank.c/1.15/Sun Mar 14 13:15:44 2021// | |
53 | 53 | D |
0 | /* $OpenBSD: basic.c,v 1.49 2019/06/17 11:39:26 lum Exp $ */ | |
0 | /* $OpenBSD: basic.c,v 1.50 2021/02/27 13:24:52 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain */ |
3 | 3 | |
53 | 53 | while (n--) { |
54 | 54 | if (curwp->w_doto == 0) { |
55 | 55 | if ((lp = lback(curwp->w_dotp)) == curbp->b_headp) { |
56 | if (!(f & FFRAND)) { | |
57 | dobeep(); | |
58 | ewprintf("Beginning of buffer"); | |
59 | } | |
56 | if (!(f & FFRAND)) | |
57 | (void)dobeep_msg("Beginning " | |
58 | "of buffer"); | |
60 | 59 | return (FALSE); |
61 | 60 | } |
62 | 61 | curwp->w_dotp = lp; |
100 | 99 | curwp->w_dotp = lforw(curwp->w_dotp); |
101 | 100 | if (curwp->w_dotp == curbp->b_headp) { |
102 | 101 | curwp->w_dotp = lback(curwp->w_dotp); |
103 | if (!(f & FFRAND)) { | |
104 | dobeep(); | |
105 | ewprintf("End of buffer"); | |
106 | } | |
102 | if (!(f & FFRAND)) | |
103 | (void)dobeep_msg("End of buffer"); | |
107 | 104 | return (FALSE); |
108 | 105 | } |
109 | 106 | curwp->w_doto = 0; |
193 | 190 | if (n < 0) |
194 | 191 | return (backline(f | FFRAND, -n)); |
195 | 192 | if ((dlp = curwp->w_dotp) == curbp->b_headp) { |
196 | if (!(f & FFRAND)) { | |
197 | dobeep(); | |
198 | ewprintf("End of buffer"); | |
199 | } | |
193 | if (!(f & FFRAND)) | |
194 | (void)dobeep_msg("End of buffer"); | |
200 | 195 | return(TRUE); |
201 | 196 | } |
202 | 197 | if ((lastflag & CFCPCN) == 0) /* Fix goal. */ |
210 | 205 | curwp->w_dotp = lback(dlp); |
211 | 206 | curwp->w_doto = llength(curwp->w_dotp); |
212 | 207 | curwp->w_rflag |= WFMOVE; |
213 | if (!(f & FFRAND)) { | |
214 | dobeep(); | |
215 | ewprintf("End of buffer"); | |
216 | } | |
208 | if (!(f & FFRAND)) | |
209 | (void)dobeep_msg("End of buffer"); | |
217 | 210 | return (TRUE); |
218 | 211 | } |
219 | 212 | curwp->w_dotline++; |
245 | 238 | thisflag |= CFCPCN; |
246 | 239 | dlp = curwp->w_dotp; |
247 | 240 | if (lback(dlp) == curbp->b_headp) { |
248 | if (!(f & FFRAND)) { | |
249 | dobeep(); | |
250 | ewprintf("Beginning of buffer"); | |
251 | } | |
241 | if (!(f & FFRAND)) | |
242 | (void)dobeep_msg("Beginning of buffer"); | |
252 | 243 | return(TRUE); |
253 | 244 | } |
254 | 245 | while (n-- && lback(dlp) != curbp->b_headp) { |
255 | 246 | dlp = lback(dlp); |
256 | 247 | curwp->w_dotline--; |
257 | 248 | } |
258 | if (n > 0 && !(f & FFRAND)) { | |
259 | dobeep(); | |
260 | ewprintf("Beginning of buffer"); | |
261 | } | |
249 | if (n > 0 && !(f & FFRAND)) | |
250 | (void)dobeep_msg("Beginning of buffer"); | |
262 | 251 | curwp->w_dotp = dlp; |
263 | 252 | curwp->w_doto = getgoal(dlp); |
264 | 253 | curwp->w_rflag |= WFMOVE; |
337 | 326 | lp = curwp->w_linep; |
338 | 327 | while (n--) |
339 | 328 | if ((lp = lforw(lp)) == curbp->b_headp) { |
340 | dobeep(); | |
341 | ewprintf("End of buffer"); | |
329 | (void)dobeep_msg("End of buffer"); | |
342 | 330 | return(TRUE); |
343 | 331 | } |
344 | ||
345 | 332 | curwp->w_linep = lp; |
346 | 333 | curwp->w_rflag |= WFFULL; |
347 | 334 | |
385 | 372 | while (n-- && lback(lp) != curbp->b_headp) { |
386 | 373 | lp = lback(lp); |
387 | 374 | } |
388 | if (lp == curwp->w_linep) { | |
389 | dobeep(); | |
390 | ewprintf("Beginning of buffer"); | |
391 | } | |
375 | if (lp == curwp->w_linep) | |
376 | (void)dobeep_msg("Beginning of buffer"); | |
377 | ||
392 | 378 | curwp->w_linep = lp; |
393 | 379 | curwp->w_rflag |= WFFULL; |
394 | 380 | |
446 | 432 | { |
447 | 433 | struct mgwin *wp; |
448 | 434 | |
449 | if (wheadp->w_wndp == NULL) { | |
450 | dobeep(); | |
451 | ewprintf("No other window"); | |
452 | return (FALSE); | |
453 | } | |
435 | if (wheadp->w_wndp == NULL) | |
436 | return(dobeep_msg("No other window")); | |
437 | ||
454 | 438 | wp = curwp; |
455 | 439 | (void) nextwind(f, n); |
456 | 440 | (void) forwpage(f, n); |
513 | 497 | struct line *odotp; |
514 | 498 | int odoto, odotline; |
515 | 499 | |
516 | if (curwp->w_markp == NULL) { | |
517 | dobeep(); | |
518 | ewprintf("No mark in this window"); | |
519 | return (FALSE); | |
520 | } | |
500 | if (curwp->w_markp == NULL) | |
501 | return(dobeep_msg("No mark in this window")); | |
502 | ||
521 | 503 | odotp = curwp->w_dotp; |
522 | 504 | odoto = curwp->w_doto; |
523 | 505 | odotline = curwp->w_dotline; |
552 | 534 | if (bufp[0] == '\0') |
553 | 535 | return (ABORT); |
554 | 536 | n = (int)strtonum(buf, INT_MIN, INT_MAX, &err); |
555 | if (err) { | |
556 | dobeep(); | |
557 | ewprintf("Line number %s", err); | |
558 | return (FALSE); | |
559 | } | |
537 | if (err) | |
538 | return(dobeep_msgs("Line number %s", err)); | |
560 | 539 | } |
561 | 540 | return(setlineno(n)); |
562 | 541 | } |
397 | 397 | char *line = NULL; |
398 | 398 | int i, ret = FALSE; |
399 | 399 | |
400 | if (curwp->w_dotp->l_text[listbuf_ncol/2 - 1] == '$') { | |
401 | dobeep(); | |
402 | ewprintf("buffer name truncated"); | |
403 | return (FALSE); | |
404 | } | |
400 | if (curwp->w_dotp->l_text[listbuf_ncol/2 - 1] == '$') | |
401 | return(dobeep_msg("buffer name truncated")); | |
405 | 402 | |
406 | 403 | if ((line = malloc(listbuf_ncol/2)) == NULL) |
407 | 404 | return (FALSE); |
488 | 485 | ret = snprintf(pbuf, sizeof(pbuf), "Save file %s", |
489 | 486 | bp->b_fname); |
490 | 487 | if (ret < 0 || ret >= sizeof(pbuf)) { |
491 | dobeep(); | |
492 | ewprintf("Error: filename too long!"); | |
488 | (void)dobeep_msg("Error: filename too long!"); | |
493 | 489 | return (UERROR); |
494 | 490 | } |
495 | 491 | if ((f == TRUE || (save = eyorn(pbuf)) == TRUE) && |
588 | 584 | bheadp = bp; |
589 | 585 | bp->b_dotline = bp->b_markline = 1; |
590 | 586 | bp->b_lines = 1; |
587 | bp->b_nlseq = "\n"; /* use unix default */ | |
588 | bp->b_nlchr = bp->b_nlseq; | |
591 | 589 | if ((bp->b_bname = strdup(bname)) == NULL) { |
592 | 590 | dobeep(); |
593 | 591 | ewprintf("Can't get %d bytes", strlen(bname) + 1); |
778 | 776 | else if ((bp = bfind(bufn, FALSE)) == NULL) |
779 | 777 | return (FALSE); |
780 | 778 | |
781 | if (bp == curbp) { | |
782 | dobeep(); | |
783 | ewprintf("Cannot insert buffer into self"); | |
784 | return (FALSE); | |
785 | } | |
779 | if (bp == curbp) | |
780 | return(dobeep_msg("Cannot insert buffer into self")); | |
781 | ||
786 | 782 | /* insert the buffer */ |
787 | 783 | nline = 0; |
788 | 784 | clp = bfirstlp(bp); |
920 | 916 | { |
921 | 917 | char fbuf[NFILEN + 32]; |
922 | 918 | |
923 | if (curbp->b_fname[0] == 0) { | |
924 | dobeep(); | |
925 | ewprintf("Cannot revert buffer not associated with any files."); | |
926 | return (FALSE); | |
927 | } | |
919 | if (curbp->b_fname[0] == 0) | |
920 | return(dobeep_msg("Cannot revert buffer not associated " | |
921 | "with any files.")); | |
928 | 922 | |
929 | 923 | snprintf(fbuf, sizeof(fbuf), "Revert buffer from file %s", |
930 | 924 | curbp->b_fname); |
996 | 990 | return (FALSE); |
997 | 991 | } |
998 | 992 | |
999 | if (curbp->b_fname[0] == 0) { | |
1000 | dobeep(); | |
1001 | ewprintf("Cannot diff buffer not associated with any files."); | |
1002 | return (FALSE); | |
1003 | } | |
993 | if (curbp->b_fname[0] == 0) | |
994 | return(dobeep_msg("Cannot diff buffer not associated with " | |
995 | "any files.")); | |
1004 | 996 | |
1005 | 997 | lpend = curbp->b_headp; |
1006 | 998 | for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) { |
1008 | 1000 | if (lforw(lp) != lpend) /* no implied \n on last line */ |
1009 | 1001 | len++; |
1010 | 1002 | } |
1011 | if ((text = calloc(len + 1, sizeof(char))) == NULL) { | |
1012 | dobeep(); | |
1013 | ewprintf("Cannot allocate memory."); | |
1014 | return (FALSE); | |
1015 | } | |
1003 | if ((text = calloc(len + 1, sizeof(char))) == NULL) | |
1004 | return(dobeep_msg("Cannot allocate memory.")); | |
1005 | ||
1016 | 1006 | ttext = text; |
1017 | 1007 | |
1018 | 1008 | for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) { |
1021 | 1011 | ttext += llength(lp); |
1022 | 1012 | } |
1023 | 1013 | if (lforw(lp) != lpend) /* no implied \n on last line */ |
1024 | *ttext++ = '\n'; | |
1014 | *ttext++ = *curbp->b_nlchr; | |
1025 | 1015 | } |
1026 | 1016 | |
1027 | 1017 | bp = bfind("*Diff*", TRUE); |
1054 | 1044 | char bname[NBUFN], fname[NBUFN]; |
1055 | 1045 | |
1056 | 1046 | if (strlcpy(fname, fn, sizeof(fname)) >= sizeof(fname)) { |
1057 | dobeep(); | |
1058 | ewprintf("filename too long"); | |
1047 | (void)dobeep_msg("filename too long"); | |
1059 | 1048 | return (NULL); |
1060 | 1049 | } |
1061 | 1050 |
0 | /* $OpenBSD: cscope.c,v 1.18 2019/07/03 03:24:02 deraadt Exp $ */ | |
0 | /* $OpenBSD: cscope.c,v 1.20 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* |
3 | 3 | * This file is in the public domain. |
183 | 183 | else if (bufp[0] == '\0') |
184 | 184 | return (FALSE); |
185 | 185 | |
186 | if (stat(dir, &sb) == -1) { | |
187 | dobeep(); | |
188 | ewprintf("stat: %s", strerror(errno)); | |
189 | return (FALSE); | |
190 | } else if (S_ISDIR(sb.st_mode) == 0) { | |
191 | dobeep(); | |
192 | ewprintf("%s: Not a directory", dir); | |
193 | return (FALSE); | |
194 | } | |
195 | ||
196 | if (csexists("cscope-indexer") == FALSE) { | |
197 | dobeep(); | |
198 | ewprintf("no such file or directory, cscope-indexer"); | |
199 | return (FALSE); | |
200 | } | |
186 | if (stat(dir, &sb) == -1) | |
187 | return(dobeep_msgs("stat: %s", strerror(errno))); | |
188 | else if (S_ISDIR(sb.st_mode) == 0) | |
189 | return(dobeep_msgs("%s: Not a directory", dir)); | |
190 | ||
191 | if (csexists("cscope-indexer") == FALSE) | |
192 | return(dobeep_msg("no such file or directory, cscope-indexer")); | |
201 | 193 | |
202 | 194 | clen = snprintf(cmd, sizeof(cmd), "cscope-indexer -v %s", dir); |
203 | 195 | if (clen < 0 || clen >= sizeof(cmd)) |
204 | 196 | return (FALSE); |
205 | 197 | |
206 | if ((fpipe = popen(cmd, "r")) == NULL) { | |
207 | dobeep(); | |
208 | ewprintf("problem opening pipe"); | |
209 | return (FALSE); | |
210 | } | |
198 | if ((fpipe = popen(cmd, "r")) == NULL) | |
199 | return(dobeep_msg("problem opening pipe")); | |
211 | 200 | |
212 | 201 | bp = bfind("*cscope*", TRUE); |
213 | 202 | if (bclear(bp) != TRUE) { |
225 | 214 | addline(bp, title); |
226 | 215 | addline(bp, ""); |
227 | 216 | while ((len = getline(&line, &sz, fpipe)) != -1) { |
228 | if (line[len - 1] == '\n') | |
217 | if (line[len - 1] == *bp->b_nlchr) | |
229 | 218 | line[len - 1] = '\0'; |
230 | 219 | addline(bp, line); |
231 | 220 | } |
247 | 236 | struct csmatch *m; |
248 | 237 | |
249 | 238 | if (curmatch == NULL) { |
250 | if ((r = TAILQ_FIRST(&csrecords)) == NULL) { | |
251 | dobeep(); | |
252 | ewprintf("The *cscope* buffer does not exist yet"); | |
253 | return (FALSE); | |
254 | } | |
239 | if ((r = TAILQ_FIRST(&csrecords)) == NULL) | |
240 | return(dobeep_msg("The *cscope* buffer does " | |
241 | "not exist yet")); | |
242 | ||
255 | 243 | currecord = r; |
256 | 244 | curmatch = TAILQ_FIRST(&r->matches); |
257 | 245 | } else { |
259 | 247 | if (m == NULL) { |
260 | 248 | r = TAILQ_NEXT(currecord, entry); |
261 | 249 | if (r == NULL) { |
262 | dobeep(); | |
263 | ewprintf("The end of *cscope* buffer has been" | |
264 | " reached"); | |
265 | return (FALSE); | |
250 | return(dobeep_msg("The end of *cscope* buffer " | |
251 | "has been reached")); | |
266 | 252 | } else { |
267 | 253 | currecord = r; |
268 | 254 | curmatch = TAILQ_FIRST(&currecord->matches); |
292 | 278 | else { |
293 | 279 | r = TAILQ_PREV(currecord, csrecords, entry); |
294 | 280 | if (r == NULL) { |
295 | dobeep(); | |
296 | ewprintf("The beginning of *cscope* buffer has" | |
297 | " been reached"); | |
298 | return (FALSE); | |
281 | return(dobeep_msg("The beginning of *cscope* " | |
282 | "buffer has been reached")); | |
299 | 283 | } else { |
300 | 284 | currecord = r; |
301 | 285 | curmatch = TAILQ_LAST(&currecord->matches, |
315 | 299 | struct csrecord *r; |
316 | 300 | |
317 | 301 | if (curmatch == NULL) { |
318 | if ((r = TAILQ_FIRST(&csrecords)) == NULL) { | |
319 | dobeep(); | |
320 | ewprintf("The *cscope* buffer does not exist yet"); | |
321 | return (FALSE); | |
322 | } | |
323 | ||
302 | if ((r = TAILQ_FIRST(&csrecords)) == NULL) | |
303 | return(dobeep_msg("The *cscope* buffer does not " | |
304 | "exist yet")); | |
324 | 305 | } else { |
325 | if ((r = TAILQ_NEXT(currecord, entry)) == NULL) { | |
326 | dobeep(); | |
327 | ewprintf("The end of *cscope* buffer has been reached"); | |
328 | return (FALSE); | |
329 | } | |
306 | if ((r = TAILQ_NEXT(currecord, entry)) == NULL) | |
307 | return(dobeep_msg("The end of *cscope* buffer has " | |
308 | "been reached")); | |
330 | 309 | } |
331 | 310 | currecord = r; |
332 | 311 | curmatch = TAILQ_FIRST(&currecord->matches); |
342 | 321 | struct csrecord *r; |
343 | 322 | |
344 | 323 | if (curmatch == NULL) { |
345 | if ((r = TAILQ_FIRST(&csrecords)) == NULL) { | |
346 | dobeep(); | |
347 | ewprintf("The *cscope* buffer does not exist yet"); | |
348 | return (FALSE); | |
349 | } | |
350 | ||
324 | if ((r = TAILQ_FIRST(&csrecords)) == NULL) | |
325 | return(dobeep_msg("The *cscope* buffer does not" | |
326 | "exist yet")); | |
351 | 327 | } else { |
352 | if ((r = TAILQ_PREV(currecord, csrecords, entry)) == NULL) { | |
353 | dobeep(); | |
354 | ewprintf("The beginning of *cscope* buffer has been" | |
355 | " reached"); | |
356 | return (FALSE); | |
357 | } | |
328 | if ((r = TAILQ_PREV(currecord, csrecords, entry)) == NULL) | |
329 | return(dobeep_msg("The beginning of *cscope* buffer " | |
330 | "has been reached")); | |
358 | 331 | } |
359 | 332 | currecord = r; |
360 | 333 | curmatch = TAILQ_FIRST(&currecord->matches); |
410 | 383 | sz = 0; |
411 | 384 | |
412 | 385 | /* If current buffer isn't a source file just return */ |
413 | if (fnmatch("*.[chy]", curbp->b_fname, 0) != 0) { | |
414 | dobeep(); | |
415 | ewprintf("C-c s not defined"); | |
416 | return (FALSE); | |
417 | } | |
386 | if (fnmatch("*.[chy]", curbp->b_fname, 0) != 0) | |
387 | return(dobeep_msg("C-c s not defined")); | |
418 | 388 | |
419 | 389 | if (curtoken(0, 1, pattern) == FALSE) |
420 | 390 | return (FALSE); |
424 | 394 | else if (p[0] == '\0') |
425 | 395 | return (FALSE); |
426 | 396 | |
427 | if (csexists("cscope") == FALSE) { | |
428 | dobeep(); | |
429 | ewprintf("no such file or directory, cscope"); | |
430 | return (FALSE); | |
431 | } | |
397 | if (csexists("cscope") == FALSE) | |
398 | return(dobeep_msg("no such file or directory, cscope")); | |
432 | 399 | |
433 | 400 | csflush(); |
434 | 401 | clen = snprintf(cmd, sizeof(cmd), "cscope -L -%d %s 2>/dev/null", |
436 | 403 | if (clen < 0 || clen >= sizeof(cmd)) |
437 | 404 | return (FALSE); |
438 | 405 | |
439 | if ((fpipe = popen(cmd, "r")) == NULL) { | |
440 | dobeep(); | |
441 | ewprintf("problem opening pipe"); | |
442 | return (FALSE); | |
443 | } | |
406 | if ((fpipe = popen(cmd, "r")) == NULL) | |
407 | return(dobeep_msg("problem opening pipe")); | |
444 | 408 | |
445 | 409 | bp = bfind("*cscope*", TRUE); |
446 | 410 | if (bclear(bp) != TRUE) { |
458 | 422 | addline(bp, ""); |
459 | 423 | addline(bp, "-------------------------------------------------------------------------------"); |
460 | 424 | while ((len = getline(&buf, &sz, fpipe)) != -1) { |
461 | if (buf[len - 1] == '\n') | |
425 | if (buf[len - 1] == *bp->b_nlchr) | |
462 | 426 | buf[len - 1] = '\0'; |
463 | 427 | if (addentry(bp, buf) != TRUE) { |
464 | 428 | free(buf); |
619 | 583 | } |
620 | 584 | if ((tmp = getenv("PATH")) == NULL) |
621 | 585 | return (FALSE); |
622 | if ((pathc = path = strndup(tmp, NFILEN)) == NULL) { | |
623 | dobeep(); | |
624 | ewprintf("out of memory"); | |
625 | return (FALSE); | |
626 | } | |
586 | if ((pathc = path = strndup(tmp, NFILEN)) == NULL) | |
587 | return(dobeep_msg("out of memory")); | |
588 | ||
627 | 589 | while ((dir = strsep(&path, ":")) != NULL) { |
628 | 590 | if (*dir == '\0') |
629 | 591 | continue; |
634 | 596 | |
635 | 597 | len = snprintf(fname, sizeof(fname), "%s/%s", dir, cmd); |
636 | 598 | if (len < 0 || len >= sizeof(fname)) { |
637 | dobeep(); | |
638 | ewprintf("path too long"); | |
599 | (void)dobeep_msg("path too long"); | |
639 | 600 | goto cleanup; |
640 | 601 | } |
641 | 602 | if(access(fname, F_OK) == 0) { |
0 | mg (20210314-1) UNRELEASED; urgency=low | |
1 | ||
2 | * New upstream release. | |
3 | ||
4 | -- Debian Janitor <janitor@jelmer.uk> Thu, 15 Apr 2021 21:34:23 -0000 | |
5 | ||
0 | 6 | mg (20200723-1) unstable; urgency=medium |
1 | 7 | |
2 | 8 | * Use secure URI in Homepage field. |
0 | /* $OpenBSD: def.h,v 1.166 2020/02/09 10:13:13 florian Exp $ */ | |
0 | /* $OpenBSD: def.h,v 1.168 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
273 | 273 | char b_flag; /* Flags */ |
274 | 274 | char b_fname[NFILEN]; /* File name */ |
275 | 275 | char b_cwd[NFILEN]; /* working directory */ |
276 | char *b_nlseq; /* Newline sequence of chars */ | |
277 | char *b_nlchr; /* 1st newline character */ | |
276 | 278 | struct fileinfo b_fi; /* File attributes */ |
277 | 279 | struct undoq b_undo; /* Undo actions list */ |
278 | 280 | struct undo_rec *b_undoptr; |
481 | 483 | int ffgetline(FILE *, char *, int, int *); |
482 | 484 | int fbackupfile(const char *); |
483 | 485 | char *adjustname(const char *, int); |
484 | char *startupfile(char *); | |
486 | char *startupfile(char *, char *); | |
485 | 487 | int copy(char *, char *); |
486 | 488 | struct list *make_file_list(char *); |
487 | 489 | int fisdir(const char *); |
0 | /* $OpenBSD: dired.c,v 1.93 2019/07/11 18:20:18 lum Exp $ */ | |
0 | /* $OpenBSD: dired.c,v 1.98 2021/03/05 16:16:53 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
242 | 242 | dname[0] = '\0'; |
243 | 243 | } |
244 | 244 | |
245 | if ((bufp = eread("Dired: ", dname, NFILEN, | |
245 | if ((bufp = eread("Dired (directory): ", dname, NFILEN, | |
246 | 246 | EFDEF | EFNEW | EFCR)) == NULL) |
247 | 247 | return (ABORT); |
248 | 248 | if (bufp[0] == '\0') |
478 | 478 | topath = adjustname(toname, TRUE); |
479 | 479 | if (stat(topath, &statbuf) == 0) { |
480 | 480 | if (S_ISDIR(statbuf.st_mode)) { |
481 | off = snprintf(toname, sizeof(toname), "%s/%s", | |
481 | ret = snprintf(toname, sizeof(toname), "%s/%s", | |
482 | 482 | topath, sname); |
483 | if (off < 0 || off >= sizeof(toname) - 1) { | |
483 | if (ret < 0 || ret >= sizeof(toname) - 1) { | |
484 | 484 | dobeep(); |
485 | 485 | ewprintf("Directory name too long"); |
486 | 486 | return (FALSE); |
488 | 488 | topath = adjustname(toname, TRUE); |
489 | 489 | } |
490 | 490 | } |
491 | if (topath == NULL) | |
492 | return (FALSE); | |
491 | 493 | if (strcmp(frname, topath) == 0) { |
492 | 494 | ewprintf("Cannot copy to same file: %s", frname); |
493 | 495 | return (TRUE); |
522 | 524 | off = strlcpy(toname, curbp->b_fname, sizeof(toname)); |
523 | 525 | if (off >= sizeof(toname) - 1) { /* can't happen, really */ |
524 | 526 | dobeep(); |
525 | ewprintf("Directory name too long"); | |
527 | ewprintf("Name too long"); | |
526 | 528 | return (FALSE); |
527 | 529 | } |
528 | 530 | (void)xbasename(sname, frname, NFILEN); |
536 | 538 | topath = adjustname(toname, TRUE); |
537 | 539 | if (stat(topath, &statbuf) == 0) { |
538 | 540 | if (S_ISDIR(statbuf.st_mode)) { |
539 | off = snprintf(toname, sizeof(toname), "%s/%s", | |
541 | ret = snprintf(toname, sizeof(toname), "%s/%s", | |
540 | 542 | topath, sname); |
541 | if (off < 0 || off >= sizeof(toname) - 1) { | |
543 | if (ret < 0 || ret >= sizeof(toname) - 1) { | |
542 | 544 | dobeep(); |
543 | 545 | ewprintf("Directory name too long"); |
544 | 546 | return (FALSE); |
546 | 548 | topath = adjustname(toname, TRUE); |
547 | 549 | } |
548 | 550 | } |
551 | if (topath == NULL) | |
552 | return (FALSE); | |
549 | 553 | if (strcmp(frname, topath) == 0) { |
550 | 554 | ewprintf("Cannot move to same file: %s", frname); |
551 | 555 | return (TRUE); |
693 | 697 | if ((fin = fdopen(fds[0], "r")) == NULL) |
694 | 698 | goto out; |
695 | 699 | while (fgets(buf, sizeof(buf), fin) != NULL) { |
696 | cp = strrchr(buf, '\n'); | |
700 | cp = strrchr(buf, *bp->b_nlchr); | |
697 | 701 | if (cp == NULL && !feof(fin)) { /* too long a line */ |
698 | 702 | int c; |
699 | 703 | addlinef(bp, "%*s%s...", space, "", buf); |
700 | while ((c = getc(fin)) != EOF && c != '\n') | |
704 | while ((c = getc(fin)) != EOF && | |
705 | c != *bp->b_nlchr) | |
701 | 706 | ; |
702 | 707 | continue; |
703 | 708 | } else if (cp) |
813 | 818 | static int |
814 | 819 | d_makename(struct line *lp, char *fn, size_t len) |
815 | 820 | { |
816 | int start, nlen; | |
821 | int start, nlen, ret; | |
817 | 822 | char *namep; |
818 | 823 | |
819 | 824 | if (d_warpdot(lp, &start) == FALSE) |
821 | 826 | namep = &lp->l_text[start]; |
822 | 827 | nlen = llength(lp) - start; |
823 | 828 | |
824 | if (snprintf(fn, len, "%s%.*s", curbp->b_fname, nlen, namep) >= len) | |
829 | ret = snprintf(fn, len, "%s%.*s", curbp->b_fname, nlen, namep); | |
830 | if (ret < 0 || ret >= (int)len) | |
825 | 831 | return (ABORT); /* Name is too long. */ |
826 | 832 | |
827 | 833 | /* Return TRUE if the entry is a directory. */ |
921 | 927 | if (errno == EACCES) { |
922 | 928 | dobeep(); |
923 | 929 | ewprintf("Permission denied: %s", dname); |
930 | } else { | |
931 | dobeep(); | |
932 | ewprintf("Error opening: %s", dname); | |
924 | 933 | } |
925 | 934 | return (NULL); |
926 | 935 | } |
1072 | 1081 | free(d2); |
1073 | 1082 | return (ABORT); |
1074 | 1083 | } |
1075 | SLIST_INSERT_AFTER(d1, d2, entry); | |
1084 | if (!d1) | |
1085 | SLIST_INSERT_HEAD(&delhead, d2, entry); | |
1086 | else | |
1087 | SLIST_INSERT_AFTER(d1, d2, entry); | |
1076 | 1088 | d1 = d2; |
1077 | 1089 | } |
1078 | 1090 | ret = TRUE; |
1085 | 1097 | d_gotofile(int f, int n) |
1086 | 1098 | { |
1087 | 1099 | struct line *lp, *nlp; |
1088 | struct buffer *curbp; | |
1089 | 1100 | size_t lenfpath; |
1090 | 1101 | char fpath[NFILEN], fname[NFILEN]; |
1091 | 1102 | char *p, *fpth, *fnp = NULL; |
1101 | 1112 | else if (fnp[0] == '\0') |
1102 | 1113 | return (FALSE); |
1103 | 1114 | |
1104 | fpth = adjustname(fpath, TRUE); /* Removes last '/' if */ | |
1105 | if (strlen(fpth) == lenfpath - 1) { /* directory, hence -1. */ | |
1115 | fpth = adjustname(fpath, TRUE); /* Removes last '/' if dir... */ | |
1116 | if (fpth == NULL || strlen(fpth) == lenfpath - 1) { /* ...hence -1. */ | |
1106 | 1117 | ewprintf("No file to find"); /* Current directory given so */ |
1107 | 1118 | return (TRUE); /* return at present location. */ |
1108 | 1119 | } |
0 | /* $OpenBSD: echo.c,v 1.66 2016/10/24 17:18:42 jasper Exp $ */ | |
0 | /* $OpenBSD: echo.c,v 1.68 2021/03/02 15:03:35 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
322 | 322 | break; |
323 | 323 | case CCHR('Y'): /* yank from kill buffer */ |
324 | 324 | i = 0; |
325 | while ((y = kremove(i++)) >= 0 && y != '\n') { | |
325 | while ((y = kremove(i++)) >= 0 && y != *curbp->b_nlchr) { | |
326 | 326 | int t; |
327 | 327 | if (dynbuf && epos + 1 >= nbuf) { |
328 | 328 | void *newp; |
335 | 335 | } |
336 | 336 | if (!dynbuf && epos + 1 >= nbuf) { |
337 | 337 | dobeep(); |
338 | ewprintf("Line too long"); | |
339 | return (emptyval); | |
338 | ewprintf("Line too long. Press Control-g to escape."); | |
339 | goto skipkey; | |
340 | 340 | } |
341 | 341 | for (t = epos; t > cpos; t--) |
342 | 342 | buf[t] = buf[t - 1]; |
491 | 491 | } |
492 | 492 | if (!dynbuf && epos + 1 >= nbuf) { |
493 | 493 | dobeep(); |
494 | ewprintf("Line too long"); | |
495 | return (emptyval); | |
494 | ewprintf("Line too long. Press Control-g to escape."); | |
495 | goto skipkey; | |
496 | 496 | } |
497 | 497 | for (i = epos; i > cpos; i--) |
498 | 498 | buf[i] = buf[i - 1]; |
506 | 506 | ttmove(rr, cc); |
507 | 507 | ttflush(); |
508 | 508 | } |
509 | ||
510 | skipkey: /* ignore key press */ | |
511 | ; | |
509 | 512 | } |
510 | 513 | done: |
511 | 514 | if (cwin == TRUE) { |
0 | /* $OpenBSD: extend.c,v 1.71 2019/07/18 15:52:11 lum Exp $ */ | |
0 | /* $OpenBSD: extend.c,v 1.72 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | /* This file is in the public domain. */ |
2 | 2 | |
3 | 3 | /* |
41 | 41 | if (inmacro) { |
42 | 42 | while (--n >= 0) { |
43 | 43 | for (count = 0; count < maclcur->l_used; count++) { |
44 | if ((((c = maclcur->l_text[count]) == '\n') | |
44 | if ((((c = maclcur->l_text[count]) == | |
45 | *curbp->b_nlchr) | |
45 | 46 | ? lnewline() : linsert(1, c)) != TRUE) |
46 | 47 | return (FALSE); |
47 | 48 | } |
60 | 61 | while (--n >= 0) { |
61 | 62 | cp = buf; |
62 | 63 | while (*cp) { |
63 | if (((*cp == '\n') ? lnewline() : linsert(1, *cp)) | |
64 | if (((*cp == *curbp->b_nlchr) ? | |
65 | lnewline() : linsert(1, *cp)) | |
64 | 66 | != TRUE) |
65 | 67 | return (FALSE); |
66 | 68 | cp++; |
433 | 435 | break; |
434 | 436 | case 'n': |
435 | 437 | case 'N': |
436 | key.k_chars[i] = '\n'; | |
438 | key.k_chars[i] = *curbp->b_nlchr; | |
437 | 439 | break; |
438 | 440 | case 'r': |
439 | 441 | case 'R': |
0 | /* $OpenBSD: fileio.c,v 1.106 2019/06/22 10:21:57 lum Exp $ */ | |
0 | /* $OpenBSD: fileio.c,v 1.108 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
172 | 172 | return (FIOERR); |
173 | 173 | } |
174 | 174 | if (lforw(lp) != lpend) /* no implied \n on last line */ |
175 | putc('\n', ffp); | |
175 | putc(*bp->b_nlchr, ffp); | |
176 | 176 | } |
177 | 177 | if (eobnl) { |
178 | 178 | lnewline_at(lback(lpend), llength(lback(lpend))); |
179 | putc('\n', ffp); | |
179 | putc(*bp->b_nlchr, ffp); | |
180 | 180 | } |
181 | 181 | return (FIOSUC); |
182 | 182 | } |
194 | 194 | int c, i; |
195 | 195 | |
196 | 196 | i = 0; |
197 | while ((c = getc(ffp)) != EOF && c != '\n') { | |
197 | while ((c = getc(ffp)) != EOF && c != *curbp->b_nlchr) { | |
198 | 198 | buf[i++] = c; |
199 | 199 | if (i >= nbuf) |
200 | 200 | return (FIOLONG); |
339 | 339 | * to the startup file name. |
340 | 340 | */ |
341 | 341 | char * |
342 | startupfile(char *suffix) | |
342 | startupfile(char *suffix, char *conffile) | |
343 | 343 | { |
344 | 344 | static char file[NFILEN]; |
345 | 345 | char *home; |
348 | 348 | if ((home = getenv("HOME")) == NULL || *home == '\0') |
349 | 349 | goto nohome; |
350 | 350 | |
351 | if (suffix == NULL) { | |
351 | if (conffile != NULL) { | |
352 | (void)strncpy(file, conffile, NFILEN); | |
353 | } else if (suffix == NULL) { | |
352 | 354 | ret = snprintf(file, sizeof(file), _PATH_MG_STARTUP, home); |
353 | 355 | if (ret < 0 || ret >= sizeof(file)) |
354 | 356 | return (NULL); |
0 | /* $OpenBSD: grep.c,v 1.48 2019/07/11 18:20:18 lum Exp $ */ | |
0 | /* $OpenBSD: grep.c,v 1.49 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain */ |
3 | 3 | |
215 | 215 | return (NULL); |
216 | 216 | } |
217 | 217 | while ((len = getline(&buf, &sz, fpipe)) != -1) { |
218 | if (buf[len - 1] == '\n') | |
218 | if (buf[len - 1] == *bp->b_nlchr) | |
219 | 219 | buf[len - 1] = '\0'; |
220 | 220 | addline(bp, buf); |
221 | 221 | } |
0 | /* $OpenBSD: interpreter.c,v 1.5 2019/07/20 11:06:33 lum Exp $ */ | |
0 | /* $OpenBSD: interpreter.c,v 1.9 2021/03/08 20:01:43 lum Exp $ */ | |
1 | 1 | /* |
2 | 2 | * This file is in the public domain. |
3 | 3 | * |
21 | 21 | * 1. Give multiple arguments to a function that usually would accept only one: |
22 | 22 | * (find-file a.txt b.txt. c.txt) |
23 | 23 | * |
24 | * 2. Define a list: | |
25 | * (define myfiles(list d.txt e.txt)) | |
26 | * | |
27 | * 3. Use the previously defined list: | |
24 | * 2. Define a single value variable: | |
25 | * (define myfile d.txt) | |
26 | * | |
27 | * 3. Define a list: | |
28 | * (define myfiles(list e.txt f.txt)) | |
29 | * | |
30 | * 4. Use the previously defined variable or list: | |
28 | 31 | * (find-file myfiles) |
29 | 32 | * |
30 | 33 | * To do: |
55 | 58 | static int multiarg(char *); |
56 | 59 | static int isvar(char **, char **, int); |
57 | 60 | static int foundvar(char *); |
58 | static int foundlist(char *); | |
59 | ||
61 | static int doregex(char *, char *); | |
60 | 62 | |
61 | 63 | /* |
62 | 64 | * Structure for variables during buffer evaluation. |
75 | 77 | static int |
76 | 78 | multiarg(char *funstr) |
77 | 79 | { |
78 | regex_t regex_buff; | |
79 | 80 | PF funcp; |
80 | 81 | char excbuf[BUFSIZE], argbuf[BUFSIZE], *contbuf, tmpbuf[BUFSIZE]; |
81 | 82 | char *cmdp, *argp, *fendp, *endp, *p, *t, *s = " "; |
92 | 93 | if (*p != '\0') |
93 | 94 | *p = '\0'; |
94 | 95 | /* we now know that string starts with '(' and ends with ')' */ |
95 | if (regcomp(®ex_buff, "^[(][\t ]*[)]$", REG_EXTENDED)) { | |
96 | regfree(®ex_buff); | |
97 | return (dobeep_msg("Could not compile regex")); | |
98 | } | |
99 | if (!regexec(®ex_buff, funstr, 0, NULL, 0)) { | |
100 | regfree(®ex_buff); | |
101 | return (dobeep_msg("No command found")); | |
102 | } | |
103 | /* currently there are no mg commands that don't have a letter */ | |
104 | if (regcomp(®ex_buff, "^[(][\t ]*[A-Za-z-]+[\t ]*[)]$", | |
105 | REG_EXTENDED)) { | |
106 | regfree(®ex_buff); | |
107 | return (dobeep_msg("Could not compile regex")); | |
108 | } | |
109 | if (!regexec(®ex_buff, funstr, 0, NULL, 0)) | |
96 | if (doregex("^[(][\t ]*[)]$", funstr)) | |
97 | return(dobeep_msg("No command found")); | |
98 | ||
99 | if (doregex("^[(][\t ]*[A-Za-z-]+[\t ]*[)]$", funstr)) | |
110 | 100 | singlecmd = 1; |
111 | 101 | |
112 | regfree(®ex_buff); | |
113 | 102 | p = funstr + 1; /* move past first '(' char. */ |
114 | 103 | cmdp = skipwhite(p); /* find first char of command. */ |
115 | 104 | |
137 | 126 | return (dobeep_msgs("Command takes no arguments: ", cmdp)); |
138 | 127 | |
139 | 128 | /* now find the first argument */ |
140 | p = fendp + 1; | |
129 | if (fendp) | |
130 | p = fendp + 1; | |
131 | else | |
132 | p = ""; | |
141 | 133 | p = skipwhite(p); |
142 | 134 | if (strlcpy(argbuf, p, sizeof(argbuf)) >= sizeof(argbuf)) |
143 | 135 | return (dobeep_msg("strlcpy error")); |
264 | 256 | * the issues. |
265 | 257 | */ |
266 | 258 | static int |
267 | foundlist(char *defstr) | |
259 | foundvar(char *defstr) | |
268 | 260 | { |
269 | 261 | struct varentry *vt, *v1 = NULL; |
270 | const char e[1] = "e", t[1] = "t"; | |
262 | const char e[2] = "e", t[2] = "t"; | |
271 | 263 | char *p, *vnamep, *vendp = NULL, *valp, *o; |
272 | int spc; | |
273 | ||
264 | int spc, foundlist = 0; | |
274 | 265 | |
275 | 266 | p = defstr + 1; /* move past first '(' char. */ |
276 | 267 | p = skipwhite(p); /* find first char of 'define'. */ |
283 | 274 | /* now find the end of the list name */ |
284 | 275 | while (1) { |
285 | 276 | ++vendp; |
286 | if (*vendp == '(' || *vendp == ' ' || *vendp == '\t') | |
277 | if (*vendp == '(') { | |
278 | foundlist = 1; | |
279 | break; | |
280 | } else if (*vendp == ' ' || *vendp == '\t') | |
287 | 281 | break; |
288 | 282 | } |
289 | 283 | *vendp = '\0'; |
295 | 289 | return(dobeep_msgs("Variable/function name clash:", vnamep)); |
296 | 290 | |
297 | 291 | p = ++vendp; |
298 | p = strstr(p, t); /* find 't' in 'list'. */ | |
299 | valp = skipwhite(++p); /* find first value */ | |
292 | p = skipwhite(p); | |
293 | if (foundlist) { | |
294 | p = strstr(p, t); /* find 't' in 'list'. */ | |
295 | valp = skipwhite(++p); /* find first value */ | |
296 | } else | |
297 | valp = p; | |
300 | 298 | /* |
301 | 299 | * Now we have the name of the list starting at 'vnamep', |
302 | 300 | * and the first value is at 'valp', record the details |
335 | 333 | spc = 0; |
336 | 334 | } |
337 | 335 | } |
338 | *vendp = '\0'; | |
336 | if (vendp) | |
337 | *vendp = '\0'; | |
338 | ||
339 | 339 | if ((v1->vals = strndup(valp, BUFSIZE)) == NULL) |
340 | 340 | return(dobeep_msg("strndup error")); |
341 | 341 | |
342 | return (TRUE); | |
343 | } | |
344 | ||
345 | ||
346 | /* | |
347 | * to do | |
348 | */ | |
349 | static int | |
350 | foundvar(char *funstr) | |
351 | { | |
352 | ewprintf("to do"); | |
342 | #ifdef MGLOG | |
343 | mglog_misc("var:%s\t#items:%d\tvals:%s\n", vnamep, v1->count, v1->vals); | |
344 | #endif | |
345 | ||
353 | 346 | return (TRUE); |
354 | 347 | } |
355 | 348 | |
379 | 372 | int |
380 | 373 | foundparen(char *funstr) |
381 | 374 | { |
382 | regex_t regex_buff; | |
383 | char *regs; | |
375 | char *regs, *p; | |
376 | int pctr; | |
377 | ||
378 | pctr = 0; | |
379 | ||
380 | /* | |
381 | * Check for blocks of code with opening and closing (). | |
382 | * One block = (cmd p a r a m) | |
383 | * Two blocks = (cmd p a r a m s)(hola) | |
384 | * Two blocks = (cmd p a r (list a m s))(hola) | |
385 | * Only single line at moment, but more for multiline. | |
386 | */ | |
387 | p = funstr; | |
388 | while (*p != '\0') { | |
389 | if (*p == '(') { | |
390 | pctr++; | |
391 | } else if (*p == ')') { | |
392 | pctr--; | |
393 | } | |
394 | p++; | |
395 | } | |
396 | if (pctr != 0) | |
397 | return(dobeep_msg("Opening and closing parentheses error")); | |
384 | 398 | |
385 | 399 | /* Does the line have a list 'define' like: */ |
386 | 400 | /* (define alist(list 1 2 3 4)) */ |
387 | 401 | regs = "^[(][\t ]*define[\t ]+[^\t (]+[\t ]*[(][\t ]*list[\t ]+"\ |
388 | 402 | "[^\t ]+.*[)][\t ]*[)]"; |
389 | if (regcomp(®ex_buff, regs, REG_EXTENDED)) { | |
390 | regfree(®ex_buff); | |
391 | return(dobeep_msg("Could not compile regex")); | |
392 | } | |
393 | if (!regexec(®ex_buff, funstr, 0, NULL, 0)) { | |
394 | regfree(®ex_buff); | |
395 | return(foundlist(funstr)); | |
396 | } | |
403 | if (doregex(regs, funstr)) | |
404 | return(foundvar(funstr)); | |
405 | ||
397 | 406 | /* Does the line have a single variable 'define' like: */ |
398 | 407 | /* (define i 0) */ |
399 | 408 | regs = "^[(][\t ]*define[\t ]+[^\t (]+[\t ]*[^\t (]+[\t ]*[)]"; |
400 | if (regcomp(®ex_buff, regs, REG_EXTENDED)) { | |
401 | regfree(®ex_buff); | |
402 | return(dobeep_msg("Could not compile regex")); | |
403 | } | |
404 | if (!regexec(®ex_buff, funstr, 0, NULL, 0)) { | |
405 | regfree(®ex_buff); | |
406 | return(foundvar(funstr)); | |
407 | } | |
409 | if (doregex(regs, funstr)) | |
410 | return(foundvar(funstr)); | |
411 | ||
408 | 412 | /* Does the line have an unrecognised 'define' */ |
409 | 413 | regs = "^[(][\t ]*define[\t ]+"; |
410 | if (regcomp(®ex_buff, regs, REG_EXTENDED)) { | |
414 | if (doregex(regs, funstr)) | |
415 | return(dobeep_msg("Invalid use of define")); | |
416 | ||
417 | return(multiarg(funstr)); | |
418 | } | |
419 | ||
420 | /* | |
421 | * Test a string against a regular expression. | |
422 | */ | |
423 | int | |
424 | doregex(char *r, char *e) | |
425 | { | |
426 | regex_t regex_buff; | |
427 | ||
428 | if (regcomp(®ex_buff, r, REG_EXTENDED)) { | |
411 | 429 | regfree(®ex_buff); |
412 | return(dobeep_msg("Could not compile regex")); | |
413 | } | |
414 | if (!regexec(®ex_buff, funstr, 0, NULL, 0)) { | |
430 | return(dobeep_msg("Regex compilation error")); | |
431 | } | |
432 | if (!regexec(®ex_buff, e, 0, NULL, 0)) { | |
415 | 433 | regfree(®ex_buff); |
416 | return(dobeep_msg("Invalid use of define")); | |
434 | return(TRUE); | |
417 | 435 | } |
418 | 436 | regfree(®ex_buff); |
419 | return(multiarg(funstr)); | |
420 | } | |
437 | return(FALSE); | |
438 | } |
0 | /* $OpenBSD: kbd.c,v 1.34 2020/02/09 10:13:13 florian Exp $ */ | |
0 | /* $OpenBSD: kbd.c,v 1.35 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
370 | 370 | } |
371 | 371 | thisflag |= CFINS; |
372 | 372 | } |
373 | if (c == '\n') { | |
373 | if (c == *curbp->b_nlchr) { | |
374 | 374 | do { |
375 | 375 | count = lnewline(); |
376 | 376 | } while (--n && count == TRUE); |
0 | /* $OpenBSD: line.c,v 1.62 2020/07/22 13:22:53 tb Exp $ */ | |
0 | /* $OpenBSD: line.c,v 1.63 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
396 | 396 | lchange(WFFULL); |
397 | 397 | if (ldelnewline() == FALSE) |
398 | 398 | goto out; |
399 | end = strlcat(sv, "\n", len + 1); | |
399 | end = strlcat(sv, curbp->b_nlchr, len + 1); | |
400 | 400 | --n; |
401 | 401 | continue; |
402 | 402 | } |
0 | /* $OpenBSD: log.c,v 1.11 2019/07/18 10:50:24 lum Exp $ */ | |
0 | /* $OpenBSD: log.c,v 1.12 2021/03/02 13:06:50 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* |
3 | 3 | * This file is in the public domain. |
45 | 45 | #include <stdlib.h> |
46 | 46 | #include <string.h> |
47 | 47 | #include <unistd.h> |
48 | #include <stdarg.h> | |
48 | 49 | |
49 | 50 | #include "def.h" |
50 | 51 | #include "key.h" |
54 | 55 | |
55 | 56 | #include "log.h" |
56 | 57 | |
57 | static char *mglogfiles_create(char *); | |
58 | static char *mglogfiles_create(FILE **, char *); | |
58 | 59 | static int mglog_lines(PF); |
59 | 60 | static int mglog_undo(void); |
60 | 61 | static int mglog_window(void); |
61 | 62 | static int mglog_key(KEYMAP *map); |
62 | 63 | |
63 | char *mglogdir; | |
64 | extern char *mglogpath_lines; | |
65 | extern char *mglogpath_undo; | |
66 | extern char *mglogpath_window; | |
67 | extern char *mglogpath_key; | |
68 | extern char *mglogpath_interpreter; | |
64 | const char *mglogdir; | |
65 | const char *mglogpath_lines; | |
66 | const char *mglogpath_undo; | |
67 | const char *mglogpath_window; | |
68 | const char *mglogpath_key; | |
69 | const char *mglogpath_interpreter; | |
70 | const char *mglogpath_misc; | |
69 | 71 | int mgloglevel; |
70 | 72 | |
73 | FILE *fd_lines; | |
74 | FILE *fd_undo; | |
75 | FILE *fd_window; | |
76 | FILE *fd_key; | |
77 | FILE *fd_interpreter; | |
78 | FILE *fd_misc; | |
79 | ||
71 | 80 | int |
72 | mglog(PF funct, KEYMAP *map) | |
81 | mglog(PF funct, void *map) | |
73 | 82 | { |
74 | 83 | if(!mglog_lines(funct)) |
75 | 84 | ewprintf("Problem logging lines"); |
87 | 96 | static int |
88 | 97 | mglog_key(KEYMAP *map) |
89 | 98 | { |
90 | struct stat sb; | |
91 | FILE *fd; | |
92 | 99 | PF *pfp; |
93 | 100 | |
94 | if(stat(mglogpath_key, &sb)) | |
95 | return (FALSE); | |
96 | fd = fopen(mglogpath_key, "a"); | |
97 | ||
98 | 101 | if (ISWORD(*key.k_chars)) { |
99 | if (fprintf(fd, "k_count:%d k_chars:%hd\tchr:%c\t", key.k_count, | |
100 | *key.k_chars, CHARMASK(*key.k_chars)) == -1) { | |
101 | fclose(fd); | |
102 | return (FALSE); | |
103 | } | |
102 | fprintf(fd_key, "k_count:%d k_chars:%hd\tchr:%c\t", key.k_count, | |
103 | *key.k_chars, CHARMASK(*key.k_chars)); | |
104 | 104 | } else { |
105 | if (fprintf(fd, "k_count:%d k_chars:%hd\t\t", key.k_count, | |
106 | *key.k_chars) == -1) { | |
107 | fclose(fd); | |
108 | return (FALSE); | |
109 | } | |
105 | fprintf(fd_key, "k_count:%d k_chars:%hd\t\t", key.k_count, | |
106 | *key.k_chars); | |
110 | 107 | } |
111 | if (fprintf(fd, "map:%p %d %d %p %hd %hd\n", | |
108 | fprintf(fd_key, "map:%p %d %d %p %hd %hd\n", | |
112 | 109 | map, |
113 | 110 | map->map_num, |
114 | 111 | map->map_max, |
115 | 112 | map->map_default, |
116 | 113 | map->map_element->k_base, |
117 | 114 | map->map_element->k_num |
118 | ) == -1) { | |
119 | fclose(fd); | |
120 | return (FALSE); | |
121 | } | |
122 | for (pfp = map->map_element->k_funcp; *pfp != '\0'; pfp++) | |
123 | fprintf(fd, "%s ", function_name(*pfp)); | |
124 | ||
125 | fprintf(fd, "\n\n"); | |
126 | fclose(fd); | |
115 | ); | |
116 | for (pfp = map->map_element->k_funcp; *pfp != NULL; pfp++) | |
117 | fprintf(fd_key, "%s ", function_name(*pfp)); | |
118 | ||
119 | fprintf(fd_key, "\n\n"); | |
120 | fflush(fd_key); | |
127 | 121 | return (TRUE); |
128 | 122 | } |
129 | 123 | |
131 | 125 | mglog_window(void) |
132 | 126 | { |
133 | 127 | struct mgwin *wp; |
134 | struct stat sb; | |
135 | FILE *fd; | |
136 | 128 | int i; |
137 | 129 | |
138 | if(stat(mglogpath_window, &sb)) | |
139 | return (FALSE); | |
140 | fd = fopen(mglogpath_window, "a"); | |
141 | ||
142 | 130 | for (wp = wheadp, i = 0; wp != NULL; wp = wp->w_wndp, ++i) { |
143 | if (fprintf(fd, | |
131 | fprintf(fd_window, | |
144 | 132 | "%d wh%p wlst%p wbfp%p wlp%p wdtp%p wmkp%p wdto%d wmko%d" \ |
145 | 133 | " wtpr%d wntr%d wfrm%d wrfl%c wflg%c wwrl%p wdtl%d" \ |
146 | 134 | " wmkl%d\n", |
160 | 148 | wp->w_flag, |
161 | 149 | wp->w_wrapline, |
162 | 150 | wp->w_dotline, |
163 | wp->w_markline) == -1) { | |
164 | fclose(fd); | |
165 | return (FALSE); | |
166 | } | |
151 | wp->w_markline | |
152 | ); | |
167 | 153 | } |
168 | fclose(fd); | |
154 | fflush(fd_window); | |
169 | 155 | return (TRUE); |
170 | 156 | } |
171 | 157 | |
173 | 159 | mglog_undo(void) |
174 | 160 | { |
175 | 161 | struct undo_rec *rec; |
176 | struct stat sb; | |
177 | FILE *fd; | |
178 | 162 | char buf[4096], tmp[1024]; |
179 | 163 | int num; |
180 | 164 | char *jptr; |
181 | 165 | |
182 | 166 | jptr = "^J"; /* :) */ |
183 | ||
184 | if(stat(mglogpath_undo, &sb)) | |
185 | return (FALSE); | |
186 | fd = fopen(mglogpath_undo, "a"); | |
187 | ||
188 | 167 | /* |
189 | 168 | * From undo_dump() |
190 | 169 | */ |
191 | 170 | num = 0; |
192 | 171 | TAILQ_FOREACH(rec, &curbp->b_undo, next) { |
193 | 172 | num++; |
194 | if (fprintf(fd, "%d:\t %s at %d ", num, | |
173 | fprintf(fd_undo, "%d:\t %s at %d ", num, | |
195 | 174 | (rec->type == DELETE) ? "DELETE": |
196 | 175 | (rec->type == DELREG) ? "DELREGION": |
197 | 176 | (rec->type == INSERT) ? "INSERT": |
198 | 177 | (rec->type == BOUNDARY) ? "----" : |
199 | 178 | (rec->type == MODIFIED) ? "MODIFIED": "UNKNOWN", |
200 | rec->pos) == -1) { | |
201 | fclose(fd); | |
202 | return (FALSE); | |
203 | } | |
179 | rec->pos | |
180 | ); | |
204 | 181 | if (rec->content) { |
205 | 182 | (void)strlcat(buf, "\"", sizeof(buf)); |
206 | 183 | snprintf(tmp, sizeof(tmp), "%.*s", |
215 | 192 | ewprintf("Undo record too large. Aborted."); |
216 | 193 | return (FALSE); |
217 | 194 | } |
218 | if (fprintf(fd, "%s\n", buf) == -1) { | |
219 | fclose(fd); | |
220 | return (FALSE); | |
221 | } | |
195 | fprintf(fd_undo, "%s\n", buf); | |
222 | 196 | tmp[0] = buf[0] = '\0'; |
223 | 197 | } |
224 | if (fprintf(fd, "\t [end-of-undo]\n\n") == -1) { | |
225 | fclose(fd); | |
226 | return (FALSE); | |
227 | } | |
228 | fclose(fd); | |
198 | fprintf(fd_undo, "\t [end-of-undo]\n\n"); | |
199 | fflush(fd_undo); | |
229 | 200 | |
230 | 201 | return (TRUE); |
231 | 202 | } |
234 | 205 | mglog_lines(PF funct) |
235 | 206 | { |
236 | 207 | struct line *lp; |
237 | struct stat sb; | |
238 | 208 | char *curline, *tmp, o; |
239 | FILE *fd; | |
240 | 209 | int i; |
241 | 210 | |
242 | 211 | i = 0; |
243 | 212 | |
244 | if(stat(mglogpath_lines, &sb)) | |
245 | return (FALSE); | |
246 | ||
247 | fd = fopen(mglogpath_lines, "a"); | |
248 | if (fprintf(fd, "%s\n", function_name(funct)) == -1) { | |
249 | fclose(fd); | |
250 | return (FALSE); | |
251 | } | |
213 | fprintf(fd_lines, "%s\n", function_name(funct)); | |
252 | 214 | lp = bfirstlp(curbp); |
253 | 215 | |
254 | 216 | for(;;) { |
268 | 230 | tmp = lp->l_text; |
269 | 231 | |
270 | 232 | /* segv on fprintf below with long lines */ |
271 | if (fprintf(fd, "%s%p b^%p f.%p %d %d\t%c|%s\n", curline, | |
233 | fprintf(fd_lines, "%s%p b^%p f.%p %d %d\t%c|%s\n", curline, | |
272 | 234 | lp, lp->l_bp, lp->l_fp, |
273 | lp->l_size, lp->l_used, o, tmp) == -1) { | |
274 | fclose(fd); | |
275 | return (FALSE); | |
276 | } | |
235 | lp->l_size, lp->l_used, o, tmp); | |
236 | ||
277 | 237 | lp = lforw(lp); |
278 | 238 | if (lp == curbp->b_headp) { |
279 | if (fprintf(fd, " %p b^%p f.%p [bhead]\n(EOB)\n", | |
280 | lp, lp->l_bp, lp->l_fp) == -1) { | |
281 | fclose(fd); | |
282 | return (FALSE); | |
283 | } | |
284 | if (fprintf(fd, "lines:raw:%d buf:%d wdot:%d\n\n", | |
285 | i, curbp->b_lines, curwp->w_dotline) == -1) { | |
286 | fclose(fd); | |
287 | return (FALSE); | |
288 | } | |
239 | fprintf(fd_lines, " %p b^%p f.%p [bhead]\n(EOB)\n", | |
240 | lp, lp->l_bp, lp->l_fp); | |
241 | ||
242 | fprintf(fd_lines, "lines:raw:%d buf:%d wdot:%d\n\n", | |
243 | i, curbp->b_lines, curwp->w_dotline); | |
244 | ||
289 | 245 | break; |
290 | 246 | } |
291 | 247 | } |
292 | fclose(fd); | |
248 | fflush(fd_lines); | |
293 | 249 | |
294 | 250 | return (TRUE); |
295 | 251 | } |
304 | 260 | const int sizof |
305 | 261 | ) |
306 | 262 | { |
307 | FILE *fd; | |
308 | ||
309 | fd = fopen(mglogpath_interpreter, "a"); | |
310 | ||
311 | if (fprintf(fd, " argbuf:%s,argp:%s,sizof:%d<\n", | |
263 | ||
264 | fprintf(fd_interpreter, " argbuf:%s,argp:%s,sizof:%d<\n", | |
312 | 265 | argbuf, |
313 | 266 | argp, |
314 | sizof | |
315 | ) == -1) { | |
316 | fclose(fd); | |
317 | return (FALSE); | |
318 | } | |
319 | fclose(fd); | |
267 | sizof); | |
268 | ||
269 | fflush(fd_interpreter); | |
320 | 270 | return (TRUE); |
321 | 271 | } |
322 | 272 | |
336 | 286 | const char* const contbuf |
337 | 287 | ) |
338 | 288 | { |
339 | FILE *fd; | |
340 | ||
341 | fd = fopen(mglogpath_interpreter, "a"); | |
342 | ||
343 | if (fprintf(fd, "%sexcbuf:%s,argbuf:%s,argp:%s,last:%d,inlist:%d,"\ | |
289 | fprintf(fd_interpreter, "%sexcbuf:%s,argbuf:%s,argp:%s,last:%d,inlist:%d,"\ | |
344 | 290 | "cmdp:%s,p:%s,contbuf:%s<\n", |
345 | 291 | pre, |
346 | 292 | excbuf, |
351 | 297 | cmdp, |
352 | 298 | p, |
353 | 299 | contbuf |
354 | ) == -1) { | |
355 | fclose(fd); | |
356 | return (FALSE); | |
357 | } | |
358 | fclose(fd); | |
359 | return (TRUE); | |
360 | } | |
300 | ); | |
301 | fflush(fd_interpreter); | |
302 | return (TRUE); | |
303 | } | |
304 | ||
305 | /* | |
306 | * Misc. logging for various subsystems | |
307 | */ | |
308 | int | |
309 | mglog_misc( | |
310 | const char *fmt, | |
311 | ... | |
312 | ) | |
313 | { | |
314 | va_list ap; | |
315 | int rc; | |
316 | ||
317 | va_start(ap, fmt); | |
318 | rc = vfprintf(fd_misc, fmt, ap); | |
319 | va_end(ap); | |
320 | fflush(fd_misc); | |
321 | ||
322 | if (rc < 0) | |
323 | return (FALSE); | |
324 | ||
325 | return (TRUE); | |
326 | } | |
327 | ||
328 | ||
361 | 329 | |
362 | 330 | /* |
363 | 331 | * Make sure logging to log files can happen. |
368 | 336 | struct stat sb; |
369 | 337 | mode_t dir_mode, f_mode, oumask; |
370 | 338 | char *mglogfile_lines, *mglogfile_undo, *mglogfile_window; |
371 | char *mglogfile_key, *mglogfile_interpreter; | |
339 | char *mglogfile_key, *mglogfile_interpreter, *mglogfile_misc; | |
372 | 340 | |
373 | 341 | mglogdir = "./log/"; |
374 | 342 | mglogfile_lines = "line.log"; |
376 | 344 | mglogfile_window = "window.log"; |
377 | 345 | mglogfile_key = "key.log"; |
378 | 346 | mglogfile_interpreter = "interpreter.log"; |
347 | mglogfile_misc = "misc.log"; | |
379 | 348 | |
380 | 349 | /* |
381 | 350 | * Change mgloglevel for desired level of logging. |
393 | 362 | if (chmod(mglogdir, f_mode) == -1) |
394 | 363 | return (FALSE); |
395 | 364 | } |
396 | mglogpath_lines = mglogfiles_create(mglogfile_lines); | |
365 | mglogpath_lines = mglogfiles_create(&fd_lines, mglogfile_lines); | |
397 | 366 | if (mglogpath_lines == NULL) |
398 | 367 | return (FALSE); |
399 | mglogpath_undo = mglogfiles_create(mglogfile_undo); | |
368 | mglogpath_undo = mglogfiles_create(&fd_undo, mglogfile_undo); | |
400 | 369 | if (mglogpath_undo == NULL) |
401 | 370 | return (FALSE); |
402 | mglogpath_window = mglogfiles_create(mglogfile_window); | |
371 | mglogpath_window = mglogfiles_create(&fd_window, mglogfile_window); | |
403 | 372 | if (mglogpath_window == NULL) |
404 | 373 | return (FALSE); |
405 | mglogpath_key = mglogfiles_create(mglogfile_key); | |
374 | mglogpath_key = mglogfiles_create(&fd_key, mglogfile_key); | |
406 | 375 | if (mglogpath_key == NULL) |
407 | 376 | return (FALSE); |
408 | mglogpath_interpreter = mglogfiles_create(mglogfile_interpreter); | |
377 | mglogpath_interpreter = mglogfiles_create(&fd_interpreter, | |
378 | mglogfile_interpreter); | |
409 | 379 | if (mglogpath_interpreter == NULL) |
410 | 380 | return (FALSE); |
381 | mglogpath_misc = mglogfiles_create(&fd_misc, mglogfile_misc); | |
382 | if (mglogpath_misc == NULL) | |
383 | return (FALSE); | |
411 | 384 | |
412 | 385 | return (TRUE); |
413 | 386 | } |
414 | 387 | |
415 | 388 | |
416 | 389 | static char * |
417 | mglogfiles_create(char *mglogfile) | |
418 | { | |
419 | struct stat sb; | |
390 | mglogfiles_create(FILE ** fd, char *mglogfile) | |
391 | { | |
420 | 392 | char tmp[NFILEN], *tmp2; |
421 | int fd; | |
422 | 393 | |
423 | 394 | if (strlcpy(tmp, mglogdir, sizeof(tmp)) > |
424 | 395 | sizeof(tmp)) |
429 | 400 | if ((tmp2 = strndup(tmp, NFILEN)) == NULL) |
430 | 401 | return (NULL); |
431 | 402 | |
432 | if(stat(tmp2, &sb)) | |
433 | fd = open(tmp2, O_RDWR | O_CREAT | O_TRUNC, 0644); | |
434 | else | |
435 | fd = open(tmp2, O_RDWR | O_TRUNC, 0644); | |
436 | ||
437 | if (fd == -1) | |
403 | if ((*fd = fopen(tmp2, "w")) == NULL) | |
438 | 404 | return (NULL); |
439 | 405 | |
440 | close(fd); | |
441 | ||
442 | 406 | return (tmp2); |
443 | 407 | } |
444 | ||
445 | /* | |
446 | * Template log function. | |
447 | */ | |
448 | /* | |
449 | int | |
450 | mglog_?(void) | |
451 | { | |
452 | struct stat sb; | |
453 | FILE *fd; | |
454 | ||
455 | if(stat(mglogpath_?, &sb)) | |
456 | fd = fopen(mglogpath_?, "a"); | |
457 | ||
458 | if (fprintf(fd, "%?", ??) == -1) { | |
459 | fclose(fd); | |
460 | return (FALSE); | |
461 | } | |
462 | fclose(fd); | |
463 | return (TRUE); | |
464 | } | |
465 | */ |
0 | /* $OpenBSD: log.h,v 1.5 2019/07/18 10:50:24 lum Exp $ */ | |
0 | /* $OpenBSD: log.h,v 1.6 2021/03/02 13:06:50 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
5 | 5 | * Specifically for mg logging functionality. |
6 | 6 | * |
7 | 7 | */ |
8 | int mglog(PF, KEYMAP *); | |
8 | int mglog(PF, void *); | |
9 | 9 | int mgloginit(void); |
10 | 10 | int mglog_execbuf( const char* const, |
11 | 11 | const char* const, |
22 | 22 | const char* const, |
23 | 23 | const int |
24 | 24 | ); |
25 | int mglog_misc( const char *, ...); | |
25 | 26 | |
26 | char *mglogpath_lines; | |
27 | char *mglogpath_undo; | |
28 | char *mglogpath_window; | |
29 | char *mglogpath_key; | |
30 | char *mglogpath_interpreter; | |
27 | extern const char *mglogpath_lines; | |
28 | extern const char *mglogpath_undo; | |
29 | extern const char *mglogpath_window; | |
30 | extern const char *mglogpath_key; | |
31 | extern const char *mglogpath_interpreter; | |
32 | extern const char *mglogpath_misc; |
0 | /* $OpenBSD: main.c,v 1.87 2019/06/22 15:38:15 lum Exp $ */ | |
0 | /* $OpenBSD: main.c,v 1.88 2021/02/23 08:10:51 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
51 | 51 | static __dead void |
52 | 52 | usage() |
53 | 53 | { |
54 | fprintf(stderr, "usage: %s [-nR] [-f mode] [+number] [file ...]\n", | |
54 | fprintf(stderr, "usage: %s [-nR] [-f mode] [-u file] [+number] " | |
55 | "[file ...]\n", | |
55 | 56 | __progname); |
56 | 57 | exit(1); |
57 | 58 | } |
59 | 60 | int |
60 | 61 | main(int argc, char **argv) |
61 | 62 | { |
62 | char *cp, *init_fcn_name = NULL; | |
63 | char *cp, *conffile = NULL, *init_fcn_name = NULL; | |
63 | 64 | PF init_fcn = NULL; |
64 | 65 | int o, i, nfiles; |
65 | 66 | int nobackups = 0; |
71 | 72 | err(1, "pledge"); |
72 | 73 | #endif |
73 | 74 | |
74 | while ((o = getopt(argc, argv, "nRf:")) != -1) | |
75 | while ((o = getopt(argc, argv, "nRf:u:")) != -1) | |
75 | 76 | switch (o) { |
76 | 77 | case 'R': |
77 | 78 | allbro = 1; |
84 | 85 | errx(1, "cannot specify more than one " |
85 | 86 | "initial function"); |
86 | 87 | init_fcn_name = optarg; |
88 | break; | |
89 | case 'u': | |
90 | conffile = optarg; | |
87 | 91 | break; |
88 | 92 | default: |
89 | 93 | usage(); |
134 | 138 | update(CMODE); |
135 | 139 | |
136 | 140 | /* user startup file. */ |
137 | if ((cp = startupfile(NULL)) != NULL) | |
141 | if ((cp = startupfile(NULL, conffile)) != NULL) | |
138 | 142 | (void)load(cp); |
139 | 143 | |
140 | 144 | /* |
0 | /* $OpenBSD: match.c,v 1.21 2019/07/02 16:25:39 lum Exp $ */ | |
0 | /* $OpenBSD: match.c,v 1.22 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
98 | 98 | cbo = llength(clp) + 1; |
99 | 99 | } |
100 | 100 | if (--cbo == llength(clp)) |
101 | c = '\n'; /* end of line */ | |
101 | c = *curbp->b_nlchr; /* end of line */ | |
102 | 102 | else |
103 | 103 | c = lgetc(clp, cbo); /* somewhere in middle */ |
104 | 104 |
0 | .\" $OpenBSD: mg.1,v 1.118 2019/11/08 19:54:40 solene Exp $ | |
0 | .\" $OpenBSD: mg.1,v 1.120 2021/02/23 18:45:33 lum Exp $ | |
1 | 1 | .\" This file is in the public domain. |
2 | 2 | .\" |
3 | .Dd $Mdocdate: November 8 2019 $ | |
3 | .Dd $Mdocdate: February 23 2021 $ | |
4 | 4 | .Dt MG 1 |
5 | 5 | .Os |
6 | 6 | .Sh NAME |
10 | 10 | .Nm mg |
11 | 11 | .Op Fl nR |
12 | 12 | .Op Fl f Ar mode |
13 | .Op Fl u Ar file | |
13 | 14 | .Op + Ns Ar number |
14 | 15 | .Op Ar |
15 | 16 | .Sh DESCRIPTION |
41 | 42 | Turn off backup file generation. |
42 | 43 | .It Fl R |
43 | 44 | Files specified on the command line will be opened read-only. |
45 | .It Fl u Ar file | |
46 | Use | |
47 | .Ar file | |
48 | as the startup file, instead of the default | |
49 | .Pa ~/.mg . | |
44 | 50 | .El |
45 | 51 | .Sh WINDOWS AND BUFFERS |
46 | 52 | When a file is loaded into |
0 | /* $OpenBSD: region.c,v 1.38 2019/06/17 11:39:26 lum Exp $ */ | |
0 | /* $OpenBSD: region.c,v 1.39 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
90 | 90 | |
91 | 91 | while (region.r_size--) { |
92 | 92 | if (loffs == llength(linep)) { /* End of line. */ |
93 | if ((s = kinsert('\n', KFORW)) != TRUE) | |
93 | if ((s = kinsert(*curbp->b_nlchr, KFORW)) != TRUE) | |
94 | 94 | return (s); |
95 | 95 | linep = lforw(linep); |
96 | 96 | loffs = 0; |
371 | 371 | if (lp == curbp->b_headp) |
372 | 372 | break; |
373 | 373 | off = 0; |
374 | buf[i] = '\n'; | |
374 | buf[i] = *curbp->b_nlchr; | |
375 | 375 | } else { |
376 | 376 | buf[i] = lgetc(lp, off); |
377 | 377 | off++; |
387 | 387 | int i; |
388 | 388 | |
389 | 389 | for (i = 0; buf[i] != '\0' && i < len; i++) { |
390 | if (buf[i] == '\n') | |
390 | if (buf[i] == *curbp->b_nlchr) | |
391 | 391 | lnewline(); |
392 | 392 | else |
393 | 393 | linsert(1, buf[i]); |
660 | 660 | |
661 | 661 | buf[len] = '\0'; |
662 | 662 | p = q = buf; |
663 | if (leftover[0] != '\0' && ((q = strchr(p, '\n')) != NULL)) { | |
663 | if (leftover[0] != '\0' && ((q = strchr(p, *bp->b_nlchr)) != NULL)) { | |
664 | 664 | *q++ = '\0'; |
665 | 665 | if (strlcat(leftover, p, sizeof(leftover)) >= |
666 | 666 | sizeof(leftover)) { |
672 | 672 | leftover[0] = '\0'; |
673 | 673 | p = q; |
674 | 674 | } |
675 | while ((q = strchr(p, '\n')) != NULL) { | |
675 | while ((q = strchr(p, *bp->b_nlchr)) != NULL) { | |
676 | 676 | *q++ = '\0'; |
677 | 677 | addline(bp, p); |
678 | 678 | p = q; |
0 | /* $OpenBSD: tty.c,v 1.37 2020/02/09 10:13:13 florian Exp $ */ | |
0 | /* $OpenBSD: tty.c,v 1.38 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
40 | 40 | |
41 | 41 | static int cci; |
42 | 42 | static int insdel; /* Do we have both insert & delete line? */ |
43 | static const char *scroll_fwd; /* How to scroll forward. */ | |
43 | static char *scroll_fwd; /* How to scroll forward. */ | |
44 | 44 | |
45 | 45 | static void winchhandler(int); |
46 | 46 | |
77 | 77 | /* this is what GNU Emacs does */ |
78 | 78 | scroll_fwd = parm_down_cursor; |
79 | 79 | if (scroll_fwd == NULL || *scroll_fwd == '\0') |
80 | scroll_fwd = "\n"; | |
80 | scroll_fwd = curbp->b_nlchr; | |
81 | 81 | } |
82 | 82 | |
83 | 83 | if (cursor_address == NULL || cursor_up == NULL) |
0 | /* $OpenBSD: ttyio.c,v 1.38 2019/06/28 13:35:02 deraadt Exp $ */ | |
0 | /* $OpenBSD: ttyio.c,v 1.39 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
210 | 210 | ttclose(); |
211 | 211 | (void) fputs("panic: ", stderr); |
212 | 212 | (void) fputs(s, stderr); |
213 | (void) fputc('\n', stderr); | |
213 | (void) fputc('\n', stderr); /* Use '\n' as no buffers now. */ | |
214 | 214 | exit(1); |
215 | 215 | } |
216 | 216 |
0 | /* $OpenBSD: ttykbd.c,v 1.19 2017/12/17 14:37:57 bcallah Exp $ */ | |
0 | /* $OpenBSD: ttykbd.c,v 1.20 2021/02/23 08:10:51 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
57 | 57 | dobindkey(fundamental_map, "delete-char", key_dc); |
58 | 58 | |
59 | 59 | if ((cp = getenv("TERM"))) { |
60 | if (((cp = startupfile(cp)) != NULL) && (load(cp) != TRUE)) | |
60 | if (((cp = startupfile(cp, NULL)) != NULL) && | |
61 | (load(cp) != TRUE)) | |
61 | 62 | ewprintf("Error reading key initialization file"); |
62 | 63 | } |
63 | 64 | if (keypad_xmit) |
0 | /* $OpenBSD: util.c,v 1.42 2019/06/22 15:38:15 lum Exp $ */ | |
0 | /* $OpenBSD: util.c,v 1.43 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
55 | 55 | cchar = nchar + curwp->w_doto; |
56 | 56 | if (curwp->w_doto == llength(clp)) |
57 | 57 | /* fake a \n at end of line */ |
58 | cbyte = '\n'; | |
58 | cbyte = *curbp->b_nlchr; | |
59 | 59 | else |
60 | 60 | cbyte = lgetc(clp, curwp->w_doto); |
61 | 61 | } |
63 | 63 | nchar += llength(clp); |
64 | 64 | clp = lforw(clp); |
65 | 65 | if (clp == curbp->b_headp) { |
66 | if (cbyte == '\n' && cline == curbp->b_lines) { | |
66 | if (cbyte == *curbp->b_nlchr && | |
67 | cline == curbp->b_lines) { | |
67 | 68 | /* swap faked \n for EOB msg */ |
68 | 69 | cbyte = EOF; |
69 | 70 | msg = "(EOB)"; |
0 | /* $OpenBSD: yank.c,v 1.14 2015/12/11 20:21:23 mmcc Exp $ */ | |
0 | /* $OpenBSD: yank.c,v 1.15 2021/03/01 10:51:14 lum Exp $ */ | |
1 | 1 | |
2 | 2 | /* This file is in the public domain. */ |
3 | 3 | |
238 | 238 | isetmark(); |
239 | 239 | i = 0; |
240 | 240 | while ((c = kremove(i)) >= 0) { |
241 | if (c == '\n') { | |
241 | if (c == *curbp->b_nlchr) { | |
242 | 242 | if (enewline(FFRAND, 1) == FALSE) |
243 | 243 | return (FALSE); |
244 | 244 | ++nline; |