1: #include "parms.h" 2: #include "structs.h" 3: #include <sys/types.h> 4: #include <sys/stat.h> 5: 6: #ifdef RCSIDENT 7: static char rcsid[] = "$Header: readem.c,v 1.7.0.3 85/10/06 01:42:00 notes Rel $"; 8: #endif RCSIDENT 9: 10: 11: /* 12: * this particular collection of junk handles the basic idea 13: * of what to do when you are showing a note. 14: * It displays the note, and then manages to collect enough info 15: * from the terminal to either progress to the next note or 16: * show some of the responses. 17: * 18: * original author : rob kolstad 19: * modified : ray essick may 22, 1981 20: * modified (again): Ray Essick December 1981 21: * modified (more): Ray Essick, February 1982 22: * 23: */ 24: readem (io, readnum, firstdis, resp) 25: struct io_f *io; 26: int *firstdis; 27: { 28: struct note_f note; 29: struct resp_f rsprec; 30: struct io_f io2; 31: FILE * txtfile; 32: int rrecnum, 33: roffset; 34: char tonf[WDLEN + 1]; /* for forwarding */ 35: char ntitle[TITLEN + 20]; /* scratch space */ 36: char nfsave[WDLEN + 1]; /* path name for 's' and 'S' */ 37: int c; /* input char */ 38: char *p, 39: *q; /* scratch pointers */ 40: int replot; /* whether to change what's on the screen */ 41: int toresp; /* init entry as resp */ 42: int forward; /* scroll forward/backward on deleted note */ 43: int toauth, /* send to author */ 44: znum, /* forward as resp to this note */ 45: znote, 46: zresp, /* scratch for asearch */ 47: i, 48: j, 49: wtext; /* send mail with text */ 50: char cmdline[CMDLEN]; /* leggo brand build-a-command */ 51: int retcode; 52: 53: 54: replot = 1; /* first pass always writes to the screen */ 55: retcode = -1; /* init so grabs character */ 56: forward = 1; /* default to scroll forward */ 57: toresp = (resp != 0); /* for entry */ 58: while (1) 59: { 60: x (readnum < 0, "readem: given bad readnum"); 61: if (readnum > io -> descr.d_nnote) 62: readnum = io -> descr.d_nnote; 63: if (readnum == 0 && io -> descr.d_plcy == 0) /* empty notesfile */ 64: return 0; /* so back to the index */ 65: getnrec (io, readnum, ¬e); 66: if (note.n_stat & DELETED) 67: if (forward) 68: goto nextnt; /* forward scroll */ 69: else 70: goto prevnote; /* backward scroll */ 71: if (toresp) 72: { 73: toresp = 0; 74: goto showit; 75: } 76: if (replot) 77: retcode = dspnote (io, ¬e, readnum); /* show the note if we need new one */ 78: replot = 1; /* reset later if don't want replot */ 79: forward = 1; 80: if (retcode < 0) 81: { 82: input: at (0, 1); 83: #ifdef PROMPT 84: printf (PROMPT); /* let him know we're ready */ 85: #endif PROMPT 86: c = gchar (); 87: printf ("\10 \10"); /* Kurt wants this to go away */ 88: } 89: else 90: { 91: c = retcode; 92: retcode = (-1); /* make sure don't loop! */ 93: } 94: switch (c) 95: { 96: case '?': /* if he doesn't know what to type */ 97: case 'h': 98: help (RDMHLP); /* print the pseudo-man page */ 99: goto showit; 100: 101: case 'D': /* delete this note/response */ 102: if (resp) /* check to see if his note */ 103: { 104: if ((rsprec.r_auth[roffset].aid & UIDMASK) != globuid) 105: { 106: at (0, PROMPTMSGX); 107: printf ("Not your response"); 108: replot = 0; 109: continue; 110: } 111: } 112: else 113: { 114: if ((note.n_auth.aid & UIDMASK) != globuid) 115: { 116: at (0, PROMPTMSGX); 117: printf ("Not your note"); 118: replot = 0; 119: continue; 120: } 121: if (readnum == 0) 122: { 123: at (0, PROMPTMSGX); 124: printf ("Use 'Z' to delete policy"); 125: replot = 0; 126: continue; 127: } 128: } 129: 130: at (0, 1); 131: if (askyn ("Delete? (y/n): \b\b") == 'n') 132: goto showit; 133: printf ("\r \r"); 134: 135: locknf (io, DSCRLOCK); /* CRITICAL section */ 136: getnrec (io, readnum, ¬e); /* this should catch most */ 137: getdscr (io, &io -> descr); /* and an up to date descriptor */ 138: if (resp) /* go about deleting it */ 139: { 140: if (resp == note.n_nresp && inorder (&io -> descr.d_lstxmit, &rsprec.r_when[roffset])) 141: { 142: delresp (io, readnum, rrecnum, roffset, 0); 143: note.n_nresp--; /* adjust note response count */ 144: unlocknf (io, DSCRLOCK); /* must free up the lock */ 145: break; /* show next response */ 146: } 147: else 148: { 149: at (0, PROMPTMSGX); 150: printf ("Can't delete: networked, or not last response"); 151: replot = 0; 152: unlocknf (io, DSCRLOCK); /* release lock here too */ 153: continue; 154: } 155: } 156: else /* its a note */ 157: { 158: if (note.n_nresp || inorder (¬e.n_date, &io -> descr.d_lstxmit)) 159: { 160: at (0, PROMPTMSGX); 161: printf ("Can't delete; note has responses or is networked"); 162: replot = 0; 163: unlocknf (io, DSCRLOCK); /* release the lock */ 164: continue; 165: } 166: delnote (io, readnum++, 0); 167: resp = 0; 168: unlocknf (io, DSCRLOCK); /* release the lock */ 169: continue; 170: } 171: 172: case 'E': /* edit an article */ 173: if (resp) /* check to see if his note */ 174: { 175: if ((rsprec.r_auth[roffset].aid & UIDMASK) != globuid) 176: { 177: at (0, PROMPTMSGX); 178: printf ("Not your response"); 179: replot = 0; 180: continue; 181: } 182: } 183: else 184: { 185: if ((note.n_auth.aid & UIDMASK) != globuid) 186: { 187: at (0, PROMPTMSGX); 188: printf ("Not your note"); 189: replot = 0; 190: continue; 191: } 192: if (readnum == 0) 193: { 194: at (0, PROMPTMSGX); 195: printf ("Sorry, E doesn't work for policy notes yet"); 196: replot = 0; 197: continue; 198: } 199: } 200: 201: locknf (io, DSCRLOCK); /* CRITICAL section */ 202: getnrec (io, readnum, ¬e); /* this should catch most */ 203: getdscr (io, &io -> descr); /* and an up to date descriptor */ 204: if (resp) /* go about deleting it */ 205: { 206: if (resp == note.n_nresp && inorder (&io -> descr.d_lstxmit, &rsprec.r_when[roffset])) 207: { 208: delresp (io, readnum, rrecnum, roffset, 0); 209: note.n_nresp--; /* adjust note response count */ 210: unlocknf (io, DSCRLOCK); /* must free up the lock */ 211: sprintf (nfsave, "/tmp/nfe%d", getpid ()); 212: /* build scr file */ 213: x ((txtfile = fopen (nfsave, "w")) == NULL, "readem: scrfile"); 214: x (chmod (nfsave, 0666) < 0, "readem: chmod"); 215: pageout (io, &rsprec.r_addr[roffset], txtfile); 216: /* dump it */ 217: fclose (txtfile); /* also flushes it */ 218: x ((txtfile = fopen (nfsave, "r")) == NULL, "readem: edit reopen"); 219: resp = addresp (io, txtfile, readnum, EDIT); 220: getnrec (io, readnum, ¬e); /* up to date */ 221: /* add it back in ! */ 222: x (unlink (nfsave) < 0, "readem: edit unlink"); 223: break; /* show next response */ 224: } 225: else 226: { 227: at (0, PROMPTMSGX); 228: printf ("Can't edit: networked, or not last response"); 229: replot = 0; 230: unlocknf (io, DSCRLOCK); /* release lock here too */ 231: continue; 232: } 233: } 234: else /* its a note */ 235: { 236: if (note.n_nresp || inorder (¬e.n_date, &io -> descr.d_lstxmit)) 237: { 238: at (0, PROMPTMSGX); 239: printf ("Can't edit; note has responses or is networked"); 240: replot = 0; 241: unlocknf (io, DSCRLOCK); /* release the lock */ 242: continue; 243: } 244: delnote (io, readnum++, 0); 245: resp = 0; 246: unlocknf (io, DSCRLOCK); /* release the lock */ 247: sprintf (nfsave, "/tmp/nfe%d", getpid ()); 248: /* build scr file */ 249: x ((txtfile = fopen (nfsave, "w")) == NULL, "readem: scrfile"); 250: x (chmod (nfsave, 0666) < 0, "readem: chmod"); 251: pageout (io, ¬e.n_addr, txtfile); 252: /* dump it */ 253: fclose (txtfile); /* also flushes it */ 254: x ((txtfile = fopen (nfsave, "r")) == NULL, "readem: edit reopen"); 255: znum = addnote (io, txtfile, "Edit note text:", 256: "Note title: ", ¬e.ntitle, EDIT); 257: x (unlink (nfsave) < 0, "readem: edit unlink"); 258: if (znum > 0) 259: readnum = znum; /* this is the one */ 260: continue; 261: } 262: 263: case 'Z': /* zap notes/responses - directors only */ 264: /* kills any note/response */ 265: getdscr (io, &io -> descr); /* up to date descriptor */ 266: if (allow (io, DRCTOK) == 0) 267: { 268: at (0, PROMPTMSGX); 269: printf ("Not a director"); 270: replot = 0; 271: continue; 272: } 273: 274: at (0, 1); 275: if (askyn ("Delete? (y/n): \b\b") == 'n') 276: goto showit; /* replotter */ 277: printf ("\r \r"); 278: /* 279: * should log the deletion here, so the "meta-director" can 280: * watch for fascist directors preying on the peasants. 281: */ 282: if (readnum == 0) /* deleting policy */ 283: { 284: locknf (io, DSCRLOCK); /* lock us up */ 285: getdscr (io, &io -> descr); /* grab up-to-date */ 286: io -> descr.d_plcy = 0; /* its gone now */ 287: putdscr (io, &io -> descr); /* replace descriptor */ 288: unlocknf (io, DSCRLOCK); 289: return 0; /* back to the index */ 290: } 291: if (resp) /* delete a response */ 292: { 293: delresp (io, readnum, rrecnum, roffset, 1); 294: /* kill it */ 295: note.n_nresp--; /* and response count */ 296: break; /* display next response */ 297: } 298: else 299: delnote (io, readnum++, 1); 300: continue; 301: 302: case 'r': /* replot the current note/response */ 303: case '\f': /* everyone else uses ^L, might as well */ 304: showit: /* come here to refill screen */ 305: if (replot == 0) 306: continue; /* screen appears fine */ 307: if (resp) 308: break; /* show him the response */ 309: else 310: { 311: replot = 1; /* make sure it gets done */ 312: continue; 313: } 314: 315: nextnt: 316: case '\r': /* wants the next note */ 317: case '\n': 318: if (readnum == 0) 319: return 0; /* policy leaves */ 320: if (++readnum > io -> descr.d_nnote) 321: { 322: *firstdis = io -> descr.d_nnote; 323: return 0; 324: } 325: resp = 0; /* reset response index */ 326: continue; 327: 328: case 'm': /* mail a note/response via Unix mail */ 329: toauth = 0; 330: wtext = 0; /* to others and no text */ 331: goto sendmail; 332: case 'M': /* same as 'm' but with text */ 333: toauth = 0; 334: wtext = 1; /* to others with text */ 335: goto sendmail; 336: case 'P': 337: toauth = 1; 338: wtext = 1; /* to author with text */ 339: goto sendmail; 340: case 'p': 341: toauth = 1; 342: wtext = 0; /* to author, no text */ 343: goto sendmail; 344: 345: sendmail: /* jump to here once set mail parms */ 346: if (resp) 347: { 348: strcpy (ntitle, "Re: "); /* prefix */ 349: strcat (ntitle, note.ntitle); /* append title */ 350: mailit (io, &rsprec.r_addr[roffset], &rsprec.r_auth[roffset], 351: &rsprec.r_when[roffset], ntitle, toauth, wtext); 352: break; 353: } 354: else 355: { 356: strncpy (ntitle, note.ntitle, TITLEN); 357: mailit (io, ¬e.n_addr, ¬e.n_auth, 358: ¬e.n_date, ntitle, toauth, wtext); 359: } 360: goto showit; /* replot current page */ 361: 362: case '!': /* wants to fork a shell */ 363: gshell (); 364: goto showit; 365: 366: case 'q': /* quit this, maybe whole system */ 367: #ifdef K_KEY 368: case 'k': 369: #endif K_KEY 370: return QUITSEQ; 371: 372: case '\04': 373: return QUITFAST; /* leave totally */ 374: 375: case 'z': /* total exit w/update */ 376: return QUITUPD; 377: 378: case 'Q': /* exit system without updating sequencer */ 379: #ifdef K_KEY 380: case 'K': 381: #endif K_KEY 382: return QUITNOSEQ; 383: 384: case 'i': /* go back to note index */ 385: *firstdis = readnum; 386: return 0; 387: 388: case '\b': 389: case '-': /* display previous response */ 390: if (resp <= 0) 391: goto prevnote; /* '-' at base note */ 392: if (--resp) 393: break; /* show the previous response */ 394: continue; /* show him the base note */ 395: 396: prevnote: /* display previous note */ 397: if (readnum == 0) 398: return 0; /* policy leaves */ 399: forward = 0; /* set to scroll backwards on deleted note */ 400: if (--readnum < 1) 401: { 402: readnum = 1; /* zero is policy, so stop at 1 */ 403: forward = 1; /* bounce off bottom end */ 404: continue; /* go hunt for the right note */ 405: } 406: resp = 0; 407: continue; 408: 409: case 'x': 410: case 'X': 411: if (readnum == 0) 412: return 0; /* policy leaves */ 413: retcode = tsearch (io, readnum - 1, c == 'x'); 414: /* look it up */ 415: if (retcode <= 0) 416: replot = 0; 417: else 418: { 419: readnum = retcode; 420: resp = 0; 421: } 422: goto showit; 423: 424: case 'a': 425: case 'A': /* author search from current spot */ 426: if (readnum == 0) 427: return 0; /* not from policy ! */ 428: znote = readnum; 429: zresp = resp; 430: if (zresp == 0) 431: znote--; 432: else 433: zresp++; /* select 'next' */ 434: retcode = asearch (io, &znote, &zresp, (c == 'a')); 435: /* look */ 436: if (retcode < 0) 437: { 438: replot = 0; 439: goto showit; /* didn't want anything */ 440: } 441: if (retcode == 0) 442: { 443: replot = 0; 444: } 445: else 446: { 447: readnum = znote; 448: resp = zresp; /* set returned values */ 449: getnrec (io, readnum, ¬e); /* grab right descriptor */ 450: } 451: goto showit; /* and display them */ 452: 453: case 'd': /* toggle a notes director status */ 454: if (allow (io, DRCTOK) == 0) 455: { /* tell him what's up */ 456: at (0, PROMPTMSGX); 457: printf (" Anonymous: %s Networked: %s", 458: (io -> descr.d_stat & ANONOK) ? "YES" : "NO", 459: (io -> descr.d_stat & NETWRKD) ? "YES" : "NO"); 460: replot = 0; /* leave on screen */ 461: goto showit; 462: } 463: if (resp == 0) /* toggle a note */ 464: { 465: locknf (io, DSCRLOCK); 466: getnrec (io, readnum, ¬e); 467: if (note.n_stat & DIRMES) 468: note.n_stat &= NOT DIRMES; 469: else 470: note.n_stat |= DIRMES; 471: putnrec (io, readnum, ¬e); /* replace */ 472: unlocknf (io, DSCRLOCK); 473: goto showit; 474: } 475: else /* toggle a response */ 476: { 477: locknf (io, DSCRLOCK); /* this locks the resp index too */ 478: getrrec (io, rrecnum, &rsprec); /* grab that block */ 479: if (rsprec.r_stat[roffset] & DIRMES) 480: rsprec.r_stat[roffset] &= NOT DIRMES; 481: else 482: rsprec.r_stat[roffset] |= DIRMES; 483: putrrec (io, rrecnum, &rsprec); /* replace */ 484: unlocknf (io, DSCRLOCK); 485: goto showit; /* and redisplay */ 486: } 487: 488: case 'e': /* allow him to edit his title */ 489: if (readnum == 0) 490: continue; /* don't touch */ 491: if (resp) 492: goto badkey; /* bell and reinput */ 493: else 494: { 495: if (allow (io, DRCTOK) == 0 && 496: (globuid != (note.n_auth.aid & UIDMASK) || 497: /* check uid */ 498: strcmp (System, note.n_id.sys) != 0)) 499: /* other sys */ 500: { 501: at (0, PROMPTMSGX); 502: printf ("Not your note"); 503: replot = 0; 504: continue; 505: } 506: at (0, 1); 507: printf ("New Title: "); 508: if ((i = gline (ntitle, TITLEN - 1)) == 1) 509: /* glom onto a title */ 510: continue; /* empty title, leave alone */ 511: strclean (ntitle); /* zip controls */ 512: locknf (io, DSCRLOCK); 513: getnrec (io, readnum, ¬e); /* well, update it */ 514: strncpy (note.ntitle, ntitle, TITLEN); 515: note.ntitle[TITLEN - 1] = '\0'; /* null for sure */ 516: putnrec (io, readnum, ¬e); /* and replace */ 517: unlocknf (io, DSCRLOCK); 518: goto showit; /* replot the message */ 519: } 520: 521: case 't': /* talk to the author of a note */ 522: if (resp) 523: talkto (&rsprec.r_auth[roffset]); 524: else 525: talkto (¬e.n_auth); 526: goto showit; /* and replot the current message */ 527: 528: case 'W': /* write a response with the text */ 529: case 'w': /* let him write a response */ 530: getdscr (io, &io -> descr); /* get up to date */ 531: if (allow (io, RESPOK) == 0) 532: { 533: at (0, PROMPTMSGX); 534: printf ("Sorry, you are not allowed to write"); 535: replot = 0; 536: continue; /* back to key processing */ 537: } 538: if (readnum == 0) 539: { 540: at (0, PROMPTMSGX); 541: printf ("No responses allowed to policy note"); 542: replot = 0; 543: continue; /* no responses to policy note */ 544: } 545: 546: if (c == 'w') 547: txtfile = NULL; /* no preface text */ 548: else 549: { 550: sprintf (cmdline, "/tmp/nfx%d", getpid ()); 551: x ((txtfile = fopen (cmdline, "w")) == NULL, "readem: bad scrfile"); 552: x (chmod (cmdline, 0666) < 0, "readem: chmod failed"); 553: if (resp) 554: { 555: preptxt (io, txtfile, &rsprec.r_auth[roffset], 556: &rsprec.r_when[roffset], &rsprec.r_addr[roffset], NULL); 557: } 558: else 559: { 560: preptxt (io, txtfile, ¬e.n_auth, ¬e.n_date, ¬e.n_addr, note.ntitle); 561: } 562: fclose (txtfile); 563: x ((txtfile = fopen (cmdline, "r")) == NULL, "readem: reopen"); 564: } 565: zresp = addresp (io, txtfile, readnum, EDIT);/* put it in */ 566: if (zresp > 0) 567: getnrec (io, readnum, ¬e); /* update descriptor */ 568: 569: if (txtfile != NULL) 570: { 571: fclose (txtfile); /* toss out scratch */ 572: x (unlink (cmdline) < 0, "readem: couldnt unlink scratch"); 573: } 574: if (zresp) 575: resp = zresp; /* show the new */ 576: goto showit; 577: 578: case 'B': /* bitch, bitch, bitch */ 579: if (init (&io2, GRIPES) < 0) /* check gripe file */ 580: { 581: at (0, PROMPTMSGX); 582: printf ("No gripe file"); 583: replot = 0; 584: } 585: else 586: { 587: addnote (&io2, NULL, "Edit Gripe text:", "Gripe Header: ", NULL, EDIT); 588: /* let him put the note in */ 589: finish (&io2); /* close up the gripe file */ 590: } 591: goto showit; 592: 593: case 'C': /* copy to other notesfile with editing */ 594: case 'c': /* copy to other notefile without editing */ 595: if (c == 'C') 596: wtext = 1; 597: else 598: wtext = 0; /* determine which */ 599: while (1) 600: { 601: printf ("\nCopy to: "); 602: if (gline (tonf, NNLEN) == 1) 603: goto showit; /* gave up */ 604: if (init (&io2, tonf) >= 0) 605: break; 606: printf ("Can't find notesfile %s\n", tonf); 607: } 608: sprintf (cmdline, "/tmp/nfx%d", getpid ()); 609: x ((txtfile = fopen (cmdline, "w")) == NULL, "readem:creat scratch failed"); 610: x (chmod (cmdline, 0666) < 0, "readem: chmod failed"); 611: if (resp) 612: { 613: preptxt (io, txtfile, &rsprec.r_auth[roffset], 614: &rsprec.r_when[roffset], &rsprec.r_addr[roffset], NULL); 615: } 616: else 617: { 618: preptxt (io, txtfile, ¬e.n_auth, ¬e.n_date, ¬e.n_addr, note.ntitle); 619: } 620: fclose (txtfile); /* close it */ 621: x ((txtfile = fopen (cmdline, "r")) == NULL, "readem: couldnt reopen"); 622: c = 'n'; /* default to note */ 623: if (allow (&io2, WRITOK) && allow (&io2, READOK) && allow (&io2, RESPOK)) 624: c = askyn ("Copy as Response (y/n)? "); 625: if (c == 'n' && allow (&io2, WRITOK)) 626: if (!resp && wtext == 0) /* use old title */ 627: addnote (&io2, txtfile, NULL, NULL, note.ntitle, wtext); 628: else 629: addnote (&io2, txtfile, "Edit copied text:", "Copy Title: ", NULL, wtext); 630: else 631: if (c == 'y') 632: { 633: if (znum = limindx (&io2)) 634: addresp (&io2, txtfile, znum, wtext); 635: } 636: else 637: { 638: printf ("You haven't permission"); 639: c = 'b'; /* leave message */ 640: } 641: if (strcmp (io -> nf, io2.nf) == 0) /* if was this notefile */ 642: getdscr (io, &io -> descr); /* get new descriptor */ 643: finish (&io2); /* close up that notefile */ 644: if (txtfile != NULL) 645: { 646: fclose (txtfile); /* throw it away */ 647: x (unlink (cmdline) < 0, "readem: couldnt unlink scratch"); 648: } 649: if (c == 'b') 650: { 651: replot = 0; 652: continue; /* leave on screen */ 653: } 654: else 655: goto showit; /* redo the screen */ 656: 657: case 'f': /* Forward (copy) string to other notefile w/o edit */ 658: case 'F': /* Forward (copy) string to other notefile w/edit */ 659: if (resp) 660: { 661: at (0, PROMPTMSGX); 662: printf ("f/F only allowed from base note"); 663: replot = 0; 664: continue; 665: } 666: if (c == 'F') 667: wtext = 1; 668: else 669: wtext = 0; /* determine which */ 670: while (1) 671: { 672: printf ("\nForward to: "); 673: if (gline (tonf, NNLEN) == 1) 674: goto showit; /* gave up */ 675: if (init (&io2, tonf) >= 0) 676: break; 677: printf ("Can't find notesfile %s\n", tonf); 678: } 679: sprintf (cmdline, "/tmp/nfx%d", getpid ()); 680: x ((txtfile = fopen (cmdline, "w")) == NULL, "readem:creat scratch failed"); 681: x (chmod (cmdline, 0666) < 0, "readem: chmod failed"); 682: preptxt (io, txtfile, ¬e.n_auth, ¬e.n_date, ¬e.n_addr, note.ntitle); 683: fclose (txtfile); /* close it */ 684: x ((txtfile = fopen (cmdline, "r")) == NULL, "readem: couldnt reopen"); 685: c = 'n'; 686: if (allow (&io2, WRITOK)) 687: { 688: if (wtext == 0) 689: znum = addnote (&io2, txtfile, NULL, NULL, note.ntitle, NOEDIT); 690: else 691: znum = addnote (&io2, txtfile, "Edit copy text:", "Copy Title:", NULL, EDIT); 692: fclose (txtfile); 693: x ((txtfile = fopen (cmdline, "w")) == NULL, "readem:creat scratch failed"); 694: for (i = 1; i <= note.n_nresp; i++) 695: { 696: if (wtext) /* if editing */ 697: printf ("Forwarding response %d of %d", 698: i, note.n_nresp); /* \n by addresp() below */ 699: if (lrsp (io, readnum, i, &rsprec, &roffset, &rrecnum) == -1) 700: continue; /* hit end of chain */ 701: preptxt (io, txtfile, &rsprec.r_auth[roffset], 702: &rsprec.r_when[roffset], &rsprec.r_addr[roffset], NULL); 703: fclose (txtfile); 704: x ((txtfile = fopen (cmdline, "r")) == NULL, "readem:creat scratch failed"); 705: addresp (&io2, txtfile, znum, wtext); 706: fclose (txtfile); 707: x ((txtfile = fopen (cmdline, "w")) == NULL, "readem:creat scratch failed"); 708: } 709: } 710: else 711: { 712: printf ("You haven't permission"); 713: c = 'b'; /* leave message */ 714: } 715: if (strcmp (io -> nf, io2.nf) == 0) /* if was this notefile */ 716: getdscr (io, &io -> descr); /* get new descriptor */ 717: finish (&io2); /* close up that notefile */ 718: if (txtfile != NULL) 719: { 720: fclose (txtfile); /* throw it away */ 721: x (unlink (cmdline) < 0, "readem: couldnt unlink scratch"); 722: } 723: if (c == 'b') 724: { 725: replot = 0; 726: continue; /* leave on screen */ 727: } 728: else 729: goto showit; /* redo the screen */ 730: 731: 732: case 'N': /* go to an archive */ 733: sprintf (tonf, "%s/%s", ARCHDIR, io -> nf);/* build dest */ 734: goto donest; /* share common code */ 735: 736: 737: case 'n': /* nest notesfiles - a stack */ 738: at (-1, 10); 739: printf (" New notesfile: "); 740: printf (" \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); 741: if (gline (tonf, NNLEN) == 1) 742: goto showit; /* forget it, replot */ 743: donest: /* used by N */ 744: closenf (io); /* save fids */ 745: if ((i = control (tonf, NOSEQ)) == -1) /* do the other */ 746: sleep (1); /* some error there */ 747: if (opennf (io, 0) < 0) 748: { 749: at (0, PROMPTMSGX); 750: printf ("Couldn't reopen notesfile %s", io -> fullname); 751: fflush (stdout); 752: sleep (2); 753: return QUITNOSEQ; /* don't update */ 754: } 755: if (i == QUITFAST) /* he in a hurry? */ 756: return QUITFAST; /* oblige him */ 757: goto showit; /* redisplay page */ 758: 759: case 's': /* place text at end of 'nfsave' */ 760: case 'S': /* place the whole string */ 761: at (-1, 1); 762: printf ("File name: \b\b\b\b\b\b\b\b\b\b\b\b"); 763: znum = gline (nfsave, WDLEN); 764: at (-1, 1); 765: printf ("%*s", znum + 11, " "); /* overwrite */ 766: if (znum == 1) /* no file */ 767: { 768: at (0, PROMPTMSGX); /* tell him didn't do */ 769: printf ("No Text Saved"); 770: replot = 0; 771: continue; 772: } 773: p = q = nfsave; /* kill leading spaces */ 774: while (*p == ' ') 775: p++; /* skip them */ 776: for (; *p; p++, q++) 777: *q = *p; /* move down */ 778: *q = '\0'; /* terminate */ 779: for (--q;; q--) /* strip trailing */ 780: { 781: if (*q != ' ') 782: break; 783: *q = '\0'; /* strip trailing */ 784: } 785: if (nfsave[0] == '|') /* pipe */ 786: { 787: p = "Pipe"; 788: } 789: else 790: { 791: struct stat sb; /* hold stat result */ 792: 793: if (stat (nfsave, &sb) == 0) /* find it? */ 794: p = "Appended"; 795: else 796: p = "New File"; /* prolly new */ 797: } 798: if (c == 's') /* save single page */ 799: { 800: if (resp) 801: { 802: znum = savtxt (io, nfsave, &rsprec.r_auth[roffset], 803: &rsprec.r_when[roffset], &rsprec.r_addr[roffset], (char *) NULL); 804: } 805: else 806: { 807: znum = savtxt (io, nfsave, ¬e.n_auth, ¬e.n_date, ¬e.n_addr, note.ntitle); 808: } 809: } 810: else /* save whole string */ 811: { 812: znum = savtxt (io, nfsave, ¬e.n_auth, ¬e.n_date, ¬e.n_addr, note.ntitle); 813: 814: for (i = 1; i <= note.n_nresp; i++) 815: { 816: if (lrsp (io, readnum, i, &rsprec, &roffset, &rrecnum) == -1) 817: continue; /* hit end of chain */ 818: znum += savtxt (io, nfsave, &rsprec.r_auth[roffset], 819: &rsprec.r_when[roffset], &rsprec.r_addr[roffset], (char *) NULL); 820: } 821: } 822: at (0, PROMPTMSGX); 823: printf ("Saved %d lines in \"%s\" [%s]", znum, nfsave, p); 824: replot = 0; /* dont erase it */ 825: continue; /* don't replot */ 826: 827: case 'j': /* goto next note/resp */ 828: case 'l': 829: if (readnum == 0) 830: return 0; /* policy returns */ 831: if (resp == note.n_nresp) 832: goto findnext; /* at end of the responses for this note */ 833: if ((resp = nxtresp (io, readnum, resp, &io -> stime)) > 0) 834: break; /* go show it */ 835: else 836: goto findnext; /* try next note ! */ 837: 838: findnext: 839: case 'J': /* next unread note */ 840: case 'L': /* like J */ 841: if (readnum == 0) 842: return 0; /* policy note returns */ 843: resp = 0; 844: if ((readnum = nxtnote (io, readnum, &io -> stime)) > 0) 845: continue; 846: else 847: { 848: if (c == 'L' || c == 'l') /* leave */ 849: return QUITSEQ; /* and update... */ 850: *firstdis = io -> descr.d_nnote; /* last index page */ 851: return 0; /* and show it */ 852: } 853: 854: case '+': 855: case ';': 856: case ' ': 857: if (readnum == 0) 858: return 0; /* such is the fate of policy notes */ 859: resp++; 860: if (resp > note.n_nresp) 861: goto nextnt; 862: break; 863: 864: case '*': /* skip to last note */ 865: resp = note.n_nresp; 866: break; /* and show it */ 867: 868: case '=': /* go back to the base note */ 869: resp = 0; /* reset index into responses */ 870: continue; 871: 872: case '1': /* skip n responses */ 873: case '2': 874: case '3': 875: case '4': 876: case '5': 877: case '6': 878: case '7': 879: case '8': 880: case '9': 881: if (note.n_nresp < 1) 882: goto nextnt; 883: resp += c - '0'; /* let him skip all over responses */ 884: if (resp > note.n_nresp) 885: resp = note.n_nresp; /* dont go past end */ 886: break; 887: 888: 889: default: /* something we haven't covered */ 890: badkey: /* so can jump down here */ 891: printf ("\07"); 892: replot = 0; /* leave whatever is up on the screen */ 893: continue; 894: } 895: if (resp > note.n_nresp) 896: resp = note.n_nresp; /* set to the end */ 897: if (resp == 0) 898: continue; /* wound up at base note */ 899: if (lrsp (io, readnum, resp, &rsprec, &roffset, &rrecnum) == -1) 900: { 901: getnrec (io, readnum, ¬e); /* get a new descriptor */ 902: goto showit; /* dropped something */ 903: } 904: retcode = dspresp (io, ¬e, &rsprec, roffset, resp, readnum); 905: /* show the darn thing */ 906: replot = 0; /* leave the response on the screen */ 907: } 908: }