Codebase list mg / d8e02f6
New upstream release. Debian Janitor 2 years ago
25 changed file(s) with 435 addition(s) and 506 deletion(s). Raw diff Collapse all Expand all
00 /tags.c/1.16/Result of merge//
11 /undo.c/1.58/Tue Apr 10 04:57:08 2018//
2 /region.c/1.38/Result of merge//
32 /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//
523 /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//
5353 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 $ */
11
22 /* This file is in the public domain */
33
5353 while (n--) {
5454 if (curwp->w_doto == 0) {
5555 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");
6059 return (FALSE);
6160 }
6261 curwp->w_dotp = lp;
10099 curwp->w_dotp = lforw(curwp->w_dotp);
101100 if (curwp->w_dotp == curbp->b_headp) {
102101 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");
107104 return (FALSE);
108105 }
109106 curwp->w_doto = 0;
193190 if (n < 0)
194191 return (backline(f | FFRAND, -n));
195192 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");
200195 return(TRUE);
201196 }
202197 if ((lastflag & CFCPCN) == 0) /* Fix goal. */
210205 curwp->w_dotp = lback(dlp);
211206 curwp->w_doto = llength(curwp->w_dotp);
212207 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");
217210 return (TRUE);
218211 }
219212 curwp->w_dotline++;
245238 thisflag |= CFCPCN;
246239 dlp = curwp->w_dotp;
247240 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");
252243 return(TRUE);
253244 }
254245 while (n-- && lback(dlp) != curbp->b_headp) {
255246 dlp = lback(dlp);
256247 curwp->w_dotline--;
257248 }
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");
262251 curwp->w_dotp = dlp;
263252 curwp->w_doto = getgoal(dlp);
264253 curwp->w_rflag |= WFMOVE;
337326 lp = curwp->w_linep;
338327 while (n--)
339328 if ((lp = lforw(lp)) == curbp->b_headp) {
340 dobeep();
341 ewprintf("End of buffer");
329 (void)dobeep_msg("End of buffer");
342330 return(TRUE);
343331 }
344
345332 curwp->w_linep = lp;
346333 curwp->w_rflag |= WFFULL;
347334
385372 while (n-- && lback(lp) != curbp->b_headp) {
386373 lp = lback(lp);
387374 }
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
392378 curwp->w_linep = lp;
393379 curwp->w_rflag |= WFFULL;
394380
446432 {
447433 struct mgwin *wp;
448434
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
454438 wp = curwp;
455439 (void) nextwind(f, n);
456440 (void) forwpage(f, n);
513497 struct line *odotp;
514498 int odoto, odotline;
515499
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
521503 odotp = curwp->w_dotp;
522504 odoto = curwp->w_doto;
523505 odotline = curwp->w_dotline;
552534 if (bufp[0] == '\0')
553535 return (ABORT);
554536 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));
560539 }
561540 return(setlineno(n));
562541 }
397397 char *line = NULL;
398398 int i, ret = FALSE;
399399
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"));
405402
406403 if ((line = malloc(listbuf_ncol/2)) == NULL)
407404 return (FALSE);
488485 ret = snprintf(pbuf, sizeof(pbuf), "Save file %s",
489486 bp->b_fname);
490487 if (ret < 0 || ret >= sizeof(pbuf)) {
491 dobeep();
492 ewprintf("Error: filename too long!");
488 (void)dobeep_msg("Error: filename too long!");
493489 return (UERROR);
494490 }
495491 if ((f == TRUE || (save = eyorn(pbuf)) == TRUE) &&
588584 bheadp = bp;
589585 bp->b_dotline = bp->b_markline = 1;
590586 bp->b_lines = 1;
587 bp->b_nlseq = "\n"; /* use unix default */
588 bp->b_nlchr = bp->b_nlseq;
591589 if ((bp->b_bname = strdup(bname)) == NULL) {
592590 dobeep();
593591 ewprintf("Can't get %d bytes", strlen(bname) + 1);
778776 else if ((bp = bfind(bufn, FALSE)) == NULL)
779777 return (FALSE);
780778
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
786782 /* insert the buffer */
787783 nline = 0;
788784 clp = bfirstlp(bp);
920916 {
921917 char fbuf[NFILEN + 32];
922918
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."));
928922
929923 snprintf(fbuf, sizeof(fbuf), "Revert buffer from file %s",
930924 curbp->b_fname);
996990 return (FALSE);
997991 }
998992
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."));
1004996
1005997 lpend = curbp->b_headp;
1006998 for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) {
10081000 if (lforw(lp) != lpend) /* no implied \n on last line */
10091001 len++;
10101002 }
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
10161006 ttext = text;
10171007
10181008 for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) {
10211011 ttext += llength(lp);
10221012 }
10231013 if (lforw(lp) != lpend) /* no implied \n on last line */
1024 *ttext++ = '\n';
1014 *ttext++ = *curbp->b_nlchr;
10251015 }
10261016
10271017 bp = bfind("*Diff*", TRUE);
10541044 char bname[NBUFN], fname[NBUFN];
10551045
10561046 if (strlcpy(fname, fn, sizeof(fname)) >= sizeof(fname)) {
1057 dobeep();
1058 ewprintf("filename too long");
1047 (void)dobeep_msg("filename too long");
10591048 return (NULL);
10601049 }
10611050
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 $ */
11
22 /*
33 * This file is in the public domain.
183183 else if (bufp[0] == '\0')
184184 return (FALSE);
185185
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"));
201193
202194 clen = snprintf(cmd, sizeof(cmd), "cscope-indexer -v %s", dir);
203195 if (clen < 0 || clen >= sizeof(cmd))
204196 return (FALSE);
205197
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"));
211200
212201 bp = bfind("*cscope*", TRUE);
213202 if (bclear(bp) != TRUE) {
225214 addline(bp, title);
226215 addline(bp, "");
227216 while ((len = getline(&line, &sz, fpipe)) != -1) {
228 if (line[len - 1] == '\n')
217 if (line[len - 1] == *bp->b_nlchr)
229218 line[len - 1] = '\0';
230219 addline(bp, line);
231220 }
247236 struct csmatch *m;
248237
249238 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
255243 currecord = r;
256244 curmatch = TAILQ_FIRST(&r->matches);
257245 } else {
259247 if (m == NULL) {
260248 r = TAILQ_NEXT(currecord, entry);
261249 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"));
266252 } else {
267253 currecord = r;
268254 curmatch = TAILQ_FIRST(&currecord->matches);
292278 else {
293279 r = TAILQ_PREV(currecord, csrecords, entry);
294280 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"));
299283 } else {
300284 currecord = r;
301285 curmatch = TAILQ_LAST(&currecord->matches,
315299 struct csrecord *r;
316300
317301 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"));
324305 } 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"));
330309 }
331310 currecord = r;
332311 curmatch = TAILQ_FIRST(&currecord->matches);
342321 struct csrecord *r;
343322
344323 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"));
351327 } 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"));
358331 }
359332 currecord = r;
360333 curmatch = TAILQ_FIRST(&currecord->matches);
410383 sz = 0;
411384
412385 /* 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"));
418388
419389 if (curtoken(0, 1, pattern) == FALSE)
420390 return (FALSE);
424394 else if (p[0] == '\0')
425395 return (FALSE);
426396
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"));
432399
433400 csflush();
434401 clen = snprintf(cmd, sizeof(cmd), "cscope -L -%d %s 2>/dev/null",
436403 if (clen < 0 || clen >= sizeof(cmd))
437404 return (FALSE);
438405
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"));
444408
445409 bp = bfind("*cscope*", TRUE);
446410 if (bclear(bp) != TRUE) {
458422 addline(bp, "");
459423 addline(bp, "-------------------------------------------------------------------------------");
460424 while ((len = getline(&buf, &sz, fpipe)) != -1) {
461 if (buf[len - 1] == '\n')
425 if (buf[len - 1] == *bp->b_nlchr)
462426 buf[len - 1] = '\0';
463427 if (addentry(bp, buf) != TRUE) {
464428 free(buf);
619583 }
620584 if ((tmp = getenv("PATH")) == NULL)
621585 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
627589 while ((dir = strsep(&path, ":")) != NULL) {
628590 if (*dir == '\0')
629591 continue;
634596
635597 len = snprintf(fname, sizeof(fname), "%s/%s", dir, cmd);
636598 if (len < 0 || len >= sizeof(fname)) {
637 dobeep();
638 ewprintf("path too long");
599 (void)dobeep_msg("path too long");
639600 goto cleanup;
640601 }
641602 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
06 mg (20200723-1) unstable; urgency=medium
17
28 * 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 $ */
11
22 /* This file is in the public domain. */
33
273273 char b_flag; /* Flags */
274274 char b_fname[NFILEN]; /* File name */
275275 char b_cwd[NFILEN]; /* working directory */
276 char *b_nlseq; /* Newline sequence of chars */
277 char *b_nlchr; /* 1st newline character */
276278 struct fileinfo b_fi; /* File attributes */
277279 struct undoq b_undo; /* Undo actions list */
278280 struct undo_rec *b_undoptr;
481483 int ffgetline(FILE *, char *, int, int *);
482484 int fbackupfile(const char *);
483485 char *adjustname(const char *, int);
484 char *startupfile(char *);
486 char *startupfile(char *, char *);
485487 int copy(char *, char *);
486488 struct list *make_file_list(char *);
487489 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 $ */
11
22 /* This file is in the public domain. */
33
242242 dname[0] = '\0';
243243 }
244244
245 if ((bufp = eread("Dired: ", dname, NFILEN,
245 if ((bufp = eread("Dired (directory): ", dname, NFILEN,
246246 EFDEF | EFNEW | EFCR)) == NULL)
247247 return (ABORT);
248248 if (bufp[0] == '\0')
478478 topath = adjustname(toname, TRUE);
479479 if (stat(topath, &statbuf) == 0) {
480480 if (S_ISDIR(statbuf.st_mode)) {
481 off = snprintf(toname, sizeof(toname), "%s/%s",
481 ret = snprintf(toname, sizeof(toname), "%s/%s",
482482 topath, sname);
483 if (off < 0 || off >= sizeof(toname) - 1) {
483 if (ret < 0 || ret >= sizeof(toname) - 1) {
484484 dobeep();
485485 ewprintf("Directory name too long");
486486 return (FALSE);
488488 topath = adjustname(toname, TRUE);
489489 }
490490 }
491 if (topath == NULL)
492 return (FALSE);
491493 if (strcmp(frname, topath) == 0) {
492494 ewprintf("Cannot copy to same file: %s", frname);
493495 return (TRUE);
522524 off = strlcpy(toname, curbp->b_fname, sizeof(toname));
523525 if (off >= sizeof(toname) - 1) { /* can't happen, really */
524526 dobeep();
525 ewprintf("Directory name too long");
527 ewprintf("Name too long");
526528 return (FALSE);
527529 }
528530 (void)xbasename(sname, frname, NFILEN);
536538 topath = adjustname(toname, TRUE);
537539 if (stat(topath, &statbuf) == 0) {
538540 if (S_ISDIR(statbuf.st_mode)) {
539 off = snprintf(toname, sizeof(toname), "%s/%s",
541 ret = snprintf(toname, sizeof(toname), "%s/%s",
540542 topath, sname);
541 if (off < 0 || off >= sizeof(toname) - 1) {
543 if (ret < 0 || ret >= sizeof(toname) - 1) {
542544 dobeep();
543545 ewprintf("Directory name too long");
544546 return (FALSE);
546548 topath = adjustname(toname, TRUE);
547549 }
548550 }
551 if (topath == NULL)
552 return (FALSE);
549553 if (strcmp(frname, topath) == 0) {
550554 ewprintf("Cannot move to same file: %s", frname);
551555 return (TRUE);
693697 if ((fin = fdopen(fds[0], "r")) == NULL)
694698 goto out;
695699 while (fgets(buf, sizeof(buf), fin) != NULL) {
696 cp = strrchr(buf, '\n');
700 cp = strrchr(buf, *bp->b_nlchr);
697701 if (cp == NULL && !feof(fin)) { /* too long a line */
698702 int c;
699703 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)
701706 ;
702707 continue;
703708 } else if (cp)
813818 static int
814819 d_makename(struct line *lp, char *fn, size_t len)
815820 {
816 int start, nlen;
821 int start, nlen, ret;
817822 char *namep;
818823
819824 if (d_warpdot(lp, &start) == FALSE)
821826 namep = &lp->l_text[start];
822827 nlen = llength(lp) - start;
823828
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)
825831 return (ABORT); /* Name is too long. */
826832
827833 /* Return TRUE if the entry is a directory. */
921927 if (errno == EACCES) {
922928 dobeep();
923929 ewprintf("Permission denied: %s", dname);
930 } else {
931 dobeep();
932 ewprintf("Error opening: %s", dname);
924933 }
925934 return (NULL);
926935 }
10721081 free(d2);
10731082 return (ABORT);
10741083 }
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);
10761088 d1 = d2;
10771089 }
10781090 ret = TRUE;
10851097 d_gotofile(int f, int n)
10861098 {
10871099 struct line *lp, *nlp;
1088 struct buffer *curbp;
10891100 size_t lenfpath;
10901101 char fpath[NFILEN], fname[NFILEN];
10911102 char *p, *fpth, *fnp = NULL;
11011112 else if (fnp[0] == '\0')
11021113 return (FALSE);
11031114
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. */
11061117 ewprintf("No file to find"); /* Current directory given so */
11071118 return (TRUE); /* return at present location. */
11081119 }
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 $ */
11
22 /* This file is in the public domain. */
33
322322 break;
323323 case CCHR('Y'): /* yank from kill buffer */
324324 i = 0;
325 while ((y = kremove(i++)) >= 0 && y != '\n') {
325 while ((y = kremove(i++)) >= 0 && y != *curbp->b_nlchr) {
326326 int t;
327327 if (dynbuf && epos + 1 >= nbuf) {
328328 void *newp;
335335 }
336336 if (!dynbuf && epos + 1 >= nbuf) {
337337 dobeep();
338 ewprintf("Line too long");
339 return (emptyval);
338 ewprintf("Line too long. Press Control-g to escape.");
339 goto skipkey;
340340 }
341341 for (t = epos; t > cpos; t--)
342342 buf[t] = buf[t - 1];
491491 }
492492 if (!dynbuf && epos + 1 >= nbuf) {
493493 dobeep();
494 ewprintf("Line too long");
495 return (emptyval);
494 ewprintf("Line too long. Press Control-g to escape.");
495 goto skipkey;
496496 }
497497 for (i = epos; i > cpos; i--)
498498 buf[i] = buf[i - 1];
506506 ttmove(rr, cc);
507507 ttflush();
508508 }
509
510 skipkey: /* ignore key press */
511 ;
509512 }
510513 done:
511514 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 $ */
11 /* This file is in the public domain. */
22
33 /*
4141 if (inmacro) {
4242 while (--n >= 0) {
4343 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)
4546 ? lnewline() : linsert(1, c)) != TRUE)
4647 return (FALSE);
4748 }
6061 while (--n >= 0) {
6162 cp = buf;
6263 while (*cp) {
63 if (((*cp == '\n') ? lnewline() : linsert(1, *cp))
64 if (((*cp == *curbp->b_nlchr) ?
65 lnewline() : linsert(1, *cp))
6466 != TRUE)
6567 return (FALSE);
6668 cp++;
433435 break;
434436 case 'n':
435437 case 'N':
436 key.k_chars[i] = '\n';
438 key.k_chars[i] = *curbp->b_nlchr;
437439 break;
438440 case 'r':
439441 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 $ */
11
22 /* This file is in the public domain. */
33
172172 return (FIOERR);
173173 }
174174 if (lforw(lp) != lpend) /* no implied \n on last line */
175 putc('\n', ffp);
175 putc(*bp->b_nlchr, ffp);
176176 }
177177 if (eobnl) {
178178 lnewline_at(lback(lpend), llength(lback(lpend)));
179 putc('\n', ffp);
179 putc(*bp->b_nlchr, ffp);
180180 }
181181 return (FIOSUC);
182182 }
194194 int c, i;
195195
196196 i = 0;
197 while ((c = getc(ffp)) != EOF && c != '\n') {
197 while ((c = getc(ffp)) != EOF && c != *curbp->b_nlchr) {
198198 buf[i++] = c;
199199 if (i >= nbuf)
200200 return (FIOLONG);
339339 * to the startup file name.
340340 */
341341 char *
342 startupfile(char *suffix)
342 startupfile(char *suffix, char *conffile)
343343 {
344344 static char file[NFILEN];
345345 char *home;
348348 if ((home = getenv("HOME")) == NULL || *home == '\0')
349349 goto nohome;
350350
351 if (suffix == NULL) {
351 if (conffile != NULL) {
352 (void)strncpy(file, conffile, NFILEN);
353 } else if (suffix == NULL) {
352354 ret = snprintf(file, sizeof(file), _PATH_MG_STARTUP, home);
353355 if (ret < 0 || ret >= sizeof(file))
354356 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 $ */
11
22 /* This file is in the public domain */
33
215215 return (NULL);
216216 }
217217 while ((len = getline(&buf, &sz, fpipe)) != -1) {
218 if (buf[len - 1] == '\n')
218 if (buf[len - 1] == *bp->b_nlchr)
219219 buf[len - 1] = '\0';
220220 addline(bp, buf);
221221 }
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 $ */
11 /*
22 * This file is in the public domain.
33 *
2121 * 1. Give multiple arguments to a function that usually would accept only one:
2222 * (find-file a.txt b.txt. c.txt)
2323 *
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:
2831 * (find-file myfiles)
2932 *
3033 * To do:
5558 static int multiarg(char *);
5659 static int isvar(char **, char **, int);
5760 static int foundvar(char *);
58 static int foundlist(char *);
59
61 static int doregex(char *, char *);
6062
6163 /*
6264 * Structure for variables during buffer evaluation.
7577 static int
7678 multiarg(char *funstr)
7779 {
78 regex_t regex_buff;
7980 PF funcp;
8081 char excbuf[BUFSIZE], argbuf[BUFSIZE], *contbuf, tmpbuf[BUFSIZE];
8182 char *cmdp, *argp, *fendp, *endp, *p, *t, *s = " ";
9293 if (*p != '\0')
9394 *p = '\0';
9495 /* we now know that string starts with '(' and ends with ')' */
95 if (regcomp(&regex_buff, "^[(][\t ]*[)]$", REG_EXTENDED)) {
96 regfree(&regex_buff);
97 return (dobeep_msg("Could not compile regex"));
98 }
99 if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
100 regfree(&regex_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(&regex_buff, "^[(][\t ]*[A-Za-z-]+[\t ]*[)]$",
105 REG_EXTENDED)) {
106 regfree(&regex_buff);
107 return (dobeep_msg("Could not compile regex"));
108 }
109 if (!regexec(&regex_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))
110100 singlecmd = 1;
111101
112 regfree(&regex_buff);
113102 p = funstr + 1; /* move past first '(' char. */
114103 cmdp = skipwhite(p); /* find first char of command. */
115104
137126 return (dobeep_msgs("Command takes no arguments: ", cmdp));
138127
139128 /* now find the first argument */
140 p = fendp + 1;
129 if (fendp)
130 p = fendp + 1;
131 else
132 p = "";
141133 p = skipwhite(p);
142134 if (strlcpy(argbuf, p, sizeof(argbuf)) >= sizeof(argbuf))
143135 return (dobeep_msg("strlcpy error"));
264256 * the issues.
265257 */
266258 static int
267 foundlist(char *defstr)
259 foundvar(char *defstr)
268260 {
269261 struct varentry *vt, *v1 = NULL;
270 const char e[1] = "e", t[1] = "t";
262 const char e[2] = "e", t[2] = "t";
271263 char *p, *vnamep, *vendp = NULL, *valp, *o;
272 int spc;
273
264 int spc, foundlist = 0;
274265
275266 p = defstr + 1; /* move past first '(' char. */
276267 p = skipwhite(p); /* find first char of 'define'. */
283274 /* now find the end of the list name */
284275 while (1) {
285276 ++vendp;
286 if (*vendp == '(' || *vendp == ' ' || *vendp == '\t')
277 if (*vendp == '(') {
278 foundlist = 1;
279 break;
280 } else if (*vendp == ' ' || *vendp == '\t')
287281 break;
288282 }
289283 *vendp = '\0';
295289 return(dobeep_msgs("Variable/function name clash:", vnamep));
296290
297291 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;
300298 /*
301299 * Now we have the name of the list starting at 'vnamep',
302300 * and the first value is at 'valp', record the details
335333 spc = 0;
336334 }
337335 }
338 *vendp = '\0';
336 if (vendp)
337 *vendp = '\0';
338
339339 if ((v1->vals = strndup(valp, BUFSIZE)) == NULL)
340340 return(dobeep_msg("strndup error"));
341341
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
353346 return (TRUE);
354347 }
355348
379372 int
380373 foundparen(char *funstr)
381374 {
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"));
384398
385399 /* Does the line have a list 'define' like: */
386400 /* (define alist(list 1 2 3 4)) */
387401 regs = "^[(][\t ]*define[\t ]+[^\t (]+[\t ]*[(][\t ]*list[\t ]+"\
388402 "[^\t ]+.*[)][\t ]*[)]";
389 if (regcomp(&regex_buff, regs, REG_EXTENDED)) {
390 regfree(&regex_buff);
391 return(dobeep_msg("Could not compile regex"));
392 }
393 if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
394 regfree(&regex_buff);
395 return(foundlist(funstr));
396 }
403 if (doregex(regs, funstr))
404 return(foundvar(funstr));
405
397406 /* Does the line have a single variable 'define' like: */
398407 /* (define i 0) */
399408 regs = "^[(][\t ]*define[\t ]+[^\t (]+[\t ]*[^\t (]+[\t ]*[)]";
400 if (regcomp(&regex_buff, regs, REG_EXTENDED)) {
401 regfree(&regex_buff);
402 return(dobeep_msg("Could not compile regex"));
403 }
404 if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
405 regfree(&regex_buff);
406 return(foundvar(funstr));
407 }
409 if (doregex(regs, funstr))
410 return(foundvar(funstr));
411
408412 /* Does the line have an unrecognised 'define' */
409413 regs = "^[(][\t ]*define[\t ]+";
410 if (regcomp(&regex_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(&regex_buff, r, REG_EXTENDED)) {
411429 regfree(&regex_buff);
412 return(dobeep_msg("Could not compile regex"));
413 }
414 if (!regexec(&regex_buff, funstr, 0, NULL, 0)) {
430 return(dobeep_msg("Regex compilation error"));
431 }
432 if (!regexec(&regex_buff, e, 0, NULL, 0)) {
415433 regfree(&regex_buff);
416 return(dobeep_msg("Invalid use of define"));
434 return(TRUE);
417435 }
418436 regfree(&regex_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 $ */
11
22 /* This file is in the public domain. */
33
370370 }
371371 thisflag |= CFINS;
372372 }
373 if (c == '\n') {
373 if (c == *curbp->b_nlchr) {
374374 do {
375375 count = lnewline();
376376 } 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 $ */
11
22 /* This file is in the public domain. */
33
396396 lchange(WFFULL);
397397 if (ldelnewline() == FALSE)
398398 goto out;
399 end = strlcat(sv, "\n", len + 1);
399 end = strlcat(sv, curbp->b_nlchr, len + 1);
400400 --n;
401401 continue;
402402 }
+99
-157
log.c less more
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 $ */
11
22 /*
33 * This file is in the public domain.
4545 #include <stdlib.h>
4646 #include <string.h>
4747 #include <unistd.h>
48 #include <stdarg.h>
4849
4950 #include "def.h"
5051 #include "key.h"
5455
5556 #include "log.h"
5657
57 static char *mglogfiles_create(char *);
58 static char *mglogfiles_create(FILE **, char *);
5859 static int mglog_lines(PF);
5960 static int mglog_undo(void);
6061 static int mglog_window(void);
6162 static int mglog_key(KEYMAP *map);
6263
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;
6971 int mgloglevel;
7072
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
7180 int
72 mglog(PF funct, KEYMAP *map)
81 mglog(PF funct, void *map)
7382 {
7483 if(!mglog_lines(funct))
7584 ewprintf("Problem logging lines");
8796 static int
8897 mglog_key(KEYMAP *map)
8998 {
90 struct stat sb;
91 FILE *fd;
9299 PF *pfp;
93100
94 if(stat(mglogpath_key, &sb))
95 return (FALSE);
96 fd = fopen(mglogpath_key, "a");
97
98101 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));
104104 } 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);
110107 }
111 if (fprintf(fd, "map:%p %d %d %p %hd %hd\n",
108 fprintf(fd_key, "map:%p %d %d %p %hd %hd\n",
112109 map,
113110 map->map_num,
114111 map->map_max,
115112 map->map_default,
116113 map->map_element->k_base,
117114 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);
127121 return (TRUE);
128122 }
129123
131125 mglog_window(void)
132126 {
133127 struct mgwin *wp;
134 struct stat sb;
135 FILE *fd;
136128 int i;
137129
138 if(stat(mglogpath_window, &sb))
139 return (FALSE);
140 fd = fopen(mglogpath_window, "a");
141
142130 for (wp = wheadp, i = 0; wp != NULL; wp = wp->w_wndp, ++i) {
143 if (fprintf(fd,
131 fprintf(fd_window,
144132 "%d wh%p wlst%p wbfp%p wlp%p wdtp%p wmkp%p wdto%d wmko%d" \
145133 " wtpr%d wntr%d wfrm%d wrfl%c wflg%c wwrl%p wdtl%d" \
146134 " wmkl%d\n",
160148 wp->w_flag,
161149 wp->w_wrapline,
162150 wp->w_dotline,
163 wp->w_markline) == -1) {
164 fclose(fd);
165 return (FALSE);
166 }
151 wp->w_markline
152 );
167153 }
168 fclose(fd);
154 fflush(fd_window);
169155 return (TRUE);
170156 }
171157
173159 mglog_undo(void)
174160 {
175161 struct undo_rec *rec;
176 struct stat sb;
177 FILE *fd;
178162 char buf[4096], tmp[1024];
179163 int num;
180164 char *jptr;
181165
182166 jptr = "^J"; /* :) */
183
184 if(stat(mglogpath_undo, &sb))
185 return (FALSE);
186 fd = fopen(mglogpath_undo, "a");
187
188167 /*
189168 * From undo_dump()
190169 */
191170 num = 0;
192171 TAILQ_FOREACH(rec, &curbp->b_undo, next) {
193172 num++;
194 if (fprintf(fd, "%d:\t %s at %d ", num,
173 fprintf(fd_undo, "%d:\t %s at %d ", num,
195174 (rec->type == DELETE) ? "DELETE":
196175 (rec->type == DELREG) ? "DELREGION":
197176 (rec->type == INSERT) ? "INSERT":
198177 (rec->type == BOUNDARY) ? "----" :
199178 (rec->type == MODIFIED) ? "MODIFIED": "UNKNOWN",
200 rec->pos) == -1) {
201 fclose(fd);
202 return (FALSE);
203 }
179 rec->pos
180 );
204181 if (rec->content) {
205182 (void)strlcat(buf, "\"", sizeof(buf));
206183 snprintf(tmp, sizeof(tmp), "%.*s",
215192 ewprintf("Undo record too large. Aborted.");
216193 return (FALSE);
217194 }
218 if (fprintf(fd, "%s\n", buf) == -1) {
219 fclose(fd);
220 return (FALSE);
221 }
195 fprintf(fd_undo, "%s\n", buf);
222196 tmp[0] = buf[0] = '\0';
223197 }
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);
229200
230201 return (TRUE);
231202 }
234205 mglog_lines(PF funct)
235206 {
236207 struct line *lp;
237 struct stat sb;
238208 char *curline, *tmp, o;
239 FILE *fd;
240209 int i;
241210
242211 i = 0;
243212
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));
252214 lp = bfirstlp(curbp);
253215
254216 for(;;) {
268230 tmp = lp->l_text;
269231
270232 /* 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,
272234 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
277237 lp = lforw(lp);
278238 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
289245 break;
290246 }
291247 }
292 fclose(fd);
248 fflush(fd_lines);
293249
294250 return (TRUE);
295251 }
304260 const int sizof
305261 )
306262 {
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",
312265 argbuf,
313266 argp,
314 sizof
315 ) == -1) {
316 fclose(fd);
317 return (FALSE);
318 }
319 fclose(fd);
267 sizof);
268
269 fflush(fd_interpreter);
320270 return (TRUE);
321271 }
322272
336286 const char* const contbuf
337287 )
338288 {
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,"\
344290 "cmdp:%s,p:%s,contbuf:%s<\n",
345291 pre,
346292 excbuf,
351297 cmdp,
352298 p,
353299 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
361329
362330 /*
363331 * Make sure logging to log files can happen.
368336 struct stat sb;
369337 mode_t dir_mode, f_mode, oumask;
370338 char *mglogfile_lines, *mglogfile_undo, *mglogfile_window;
371 char *mglogfile_key, *mglogfile_interpreter;
339 char *mglogfile_key, *mglogfile_interpreter, *mglogfile_misc;
372340
373341 mglogdir = "./log/";
374342 mglogfile_lines = "line.log";
376344 mglogfile_window = "window.log";
377345 mglogfile_key = "key.log";
378346 mglogfile_interpreter = "interpreter.log";
347 mglogfile_misc = "misc.log";
379348
380349 /*
381350 * Change mgloglevel for desired level of logging.
393362 if (chmod(mglogdir, f_mode) == -1)
394363 return (FALSE);
395364 }
396 mglogpath_lines = mglogfiles_create(mglogfile_lines);
365 mglogpath_lines = mglogfiles_create(&fd_lines, mglogfile_lines);
397366 if (mglogpath_lines == NULL)
398367 return (FALSE);
399 mglogpath_undo = mglogfiles_create(mglogfile_undo);
368 mglogpath_undo = mglogfiles_create(&fd_undo, mglogfile_undo);
400369 if (mglogpath_undo == NULL)
401370 return (FALSE);
402 mglogpath_window = mglogfiles_create(mglogfile_window);
371 mglogpath_window = mglogfiles_create(&fd_window, mglogfile_window);
403372 if (mglogpath_window == NULL)
404373 return (FALSE);
405 mglogpath_key = mglogfiles_create(mglogfile_key);
374 mglogpath_key = mglogfiles_create(&fd_key, mglogfile_key);
406375 if (mglogpath_key == NULL)
407376 return (FALSE);
408 mglogpath_interpreter = mglogfiles_create(mglogfile_interpreter);
377 mglogpath_interpreter = mglogfiles_create(&fd_interpreter,
378 mglogfile_interpreter);
409379 if (mglogpath_interpreter == NULL)
410380 return (FALSE);
381 mglogpath_misc = mglogfiles_create(&fd_misc, mglogfile_misc);
382 if (mglogpath_misc == NULL)
383 return (FALSE);
411384
412385 return (TRUE);
413386 }
414387
415388
416389 static char *
417 mglogfiles_create(char *mglogfile)
418 {
419 struct stat sb;
390 mglogfiles_create(FILE ** fd, char *mglogfile)
391 {
420392 char tmp[NFILEN], *tmp2;
421 int fd;
422393
423394 if (strlcpy(tmp, mglogdir, sizeof(tmp)) >
424395 sizeof(tmp))
429400 if ((tmp2 = strndup(tmp, NFILEN)) == NULL)
430401 return (NULL);
431402
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)
438404 return (NULL);
439405
440 close(fd);
441
442406 return (tmp2);
443407 }
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 $ */
11
22 /* This file is in the public domain. */
33
55 * Specifically for mg logging functionality.
66 *
77 */
8 int mglog(PF, KEYMAP *);
8 int mglog(PF, void *);
99 int mgloginit(void);
1010 int mglog_execbuf( const char* const,
1111 const char* const,
2222 const char* const,
2323 const int
2424 );
25 int mglog_misc( const char *, ...);
2526
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 $ */
11
22 /* This file is in the public domain. */
33
5151 static __dead void
5252 usage()
5353 {
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",
5556 __progname);
5657 exit(1);
5758 }
5960 int
6061 main(int argc, char **argv)
6162 {
62 char *cp, *init_fcn_name = NULL;
63 char *cp, *conffile = NULL, *init_fcn_name = NULL;
6364 PF init_fcn = NULL;
6465 int o, i, nfiles;
6566 int nobackups = 0;
7172 err(1, "pledge");
7273 #endif
7374
74 while ((o = getopt(argc, argv, "nRf:")) != -1)
75 while ((o = getopt(argc, argv, "nRf:u:")) != -1)
7576 switch (o) {
7677 case 'R':
7778 allbro = 1;
8485 errx(1, "cannot specify more than one "
8586 "initial function");
8687 init_fcn_name = optarg;
88 break;
89 case 'u':
90 conffile = optarg;
8791 break;
8892 default:
8993 usage();
134138 update(CMODE);
135139
136140 /* user startup file. */
137 if ((cp = startupfile(NULL)) != NULL)
141 if ((cp = startupfile(NULL, conffile)) != NULL)
138142 (void)load(cp);
139143
140144 /*
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 $ */
11
22 /* This file is in the public domain. */
33
9898 cbo = llength(clp) + 1;
9999 }
100100 if (--cbo == llength(clp))
101 c = '\n'; /* end of line */
101 c = *curbp->b_nlchr; /* end of line */
102102 else
103103 c = lgetc(clp, cbo); /* somewhere in middle */
104104
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 $
11 .\" This file is in the public domain.
22 .\"
3 .Dd $Mdocdate: November 8 2019 $
3 .Dd $Mdocdate: February 23 2021 $
44 .Dt MG 1
55 .Os
66 .Sh NAME
1010 .Nm mg
1111 .Op Fl nR
1212 .Op Fl f Ar mode
13 .Op Fl u Ar file
1314 .Op + Ns Ar number
1415 .Op Ar
1516 .Sh DESCRIPTION
4142 Turn off backup file generation.
4243 .It Fl R
4344 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 .
4450 .El
4551 .Sh WINDOWS AND BUFFERS
4652 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 $ */
11
22 /* This file is in the public domain. */
33
9090
9191 while (region.r_size--) {
9292 if (loffs == llength(linep)) { /* End of line. */
93 if ((s = kinsert('\n', KFORW)) != TRUE)
93 if ((s = kinsert(*curbp->b_nlchr, KFORW)) != TRUE)
9494 return (s);
9595 linep = lforw(linep);
9696 loffs = 0;
371371 if (lp == curbp->b_headp)
372372 break;
373373 off = 0;
374 buf[i] = '\n';
374 buf[i] = *curbp->b_nlchr;
375375 } else {
376376 buf[i] = lgetc(lp, off);
377377 off++;
387387 int i;
388388
389389 for (i = 0; buf[i] != '\0' && i < len; i++) {
390 if (buf[i] == '\n')
390 if (buf[i] == *curbp->b_nlchr)
391391 lnewline();
392392 else
393393 linsert(1, buf[i]);
660660
661661 buf[len] = '\0';
662662 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)) {
664664 *q++ = '\0';
665665 if (strlcat(leftover, p, sizeof(leftover)) >=
666666 sizeof(leftover)) {
672672 leftover[0] = '\0';
673673 p = q;
674674 }
675 while ((q = strchr(p, '\n')) != NULL) {
675 while ((q = strchr(p, *bp->b_nlchr)) != NULL) {
676676 *q++ = '\0';
677677 addline(bp, p);
678678 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 $ */
11
22 /* This file is in the public domain. */
33
4040
4141 static int cci;
4242 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. */
4444
4545 static void winchhandler(int);
4646
7777 /* this is what GNU Emacs does */
7878 scroll_fwd = parm_down_cursor;
7979 if (scroll_fwd == NULL || *scroll_fwd == '\0')
80 scroll_fwd = "\n";
80 scroll_fwd = curbp->b_nlchr;
8181 }
8282
8383 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 $ */
11
22 /* This file is in the public domain. */
33
210210 ttclose();
211211 (void) fputs("panic: ", stderr);
212212 (void) fputs(s, stderr);
213 (void) fputc('\n', stderr);
213 (void) fputc('\n', stderr); /* Use '\n' as no buffers now. */
214214 exit(1);
215215 }
216216
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 $ */
11
22 /* This file is in the public domain. */
33
5757 dobindkey(fundamental_map, "delete-char", key_dc);
5858
5959 if ((cp = getenv("TERM"))) {
60 if (((cp = startupfile(cp)) != NULL) && (load(cp) != TRUE))
60 if (((cp = startupfile(cp, NULL)) != NULL) &&
61 (load(cp) != TRUE))
6162 ewprintf("Error reading key initialization file");
6263 }
6364 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 $ */
11
22 /* This file is in the public domain. */
33
5555 cchar = nchar + curwp->w_doto;
5656 if (curwp->w_doto == llength(clp))
5757 /* fake a \n at end of line */
58 cbyte = '\n';
58 cbyte = *curbp->b_nlchr;
5959 else
6060 cbyte = lgetc(clp, curwp->w_doto);
6161 }
6363 nchar += llength(clp);
6464 clp = lforw(clp);
6565 if (clp == curbp->b_headp) {
66 if (cbyte == '\n' && cline == curbp->b_lines) {
66 if (cbyte == *curbp->b_nlchr &&
67 cline == curbp->b_lines) {
6768 /* swap faked \n for EOB msg */
6869 cbyte = EOF;
6970 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 $ */
11
22 /* This file is in the public domain. */
33
238238 isetmark();
239239 i = 0;
240240 while ((c = kremove(i)) >= 0) {
241 if (c == '\n') {
241 if (c == *curbp->b_nlchr) {
242242 if (enewline(FFRAND, 1) == FALSE)
243243 return (FALSE);
244244 ++nline;