1: /* $Header: ngstuff.c,v 4.3.1.2 85/05/10 14:31:52 lwall Exp $
   2:  *
   3:  * $Log:	ngstuff.c,v $
   4:  * Revision 4.3.1.2  85/05/10  14:31:52  lwall
   5:  * Prevented "Junked" or "Marked unread" when no state change.
   6:  *
   7:  * Revision 4.3.1.1  85/05/10  11:36:45  lwall
   8:  * Branch for patches.
   9:  *
  10:  * Revision 4.3  85/05/01  11:45:03  lwall
  11:  * Baseline for release with 4.3bsd.
  12:  *
  13:  */
  14: 
  15: #include "EXTERN.h"
  16: #include "common.h"
  17: #include "term.h"
  18: #include "util.h"
  19: #include "ng.h"
  20: #include "bits.h"
  21: #include "intrp.h"
  22: #include "cheat.h"
  23: #include "head.h"
  24: #include "final.h"
  25: #include "sw.h"
  26: #include "INTERN.h"
  27: #include "ngstuff.h"
  28: 
  29: void
  30: ngstuff_init()
  31: {
  32:     ;
  33: }
  34: 
  35: /* do a shell escape */
  36: 
  37: int
  38: escapade()
  39: {
  40:     register char *s;
  41:     bool interactive = (buf[1] == FINISHCMD);
  42:     bool docd;
  43:     char whereiam[256];
  44: 
  45:     if (!finish_command(interactive))   /* get remainder of command */
  46:     return -1;
  47:     s = buf+1;
  48:     docd = *s != '!';
  49:     if (!docd) {
  50:     s++;
  51:     }
  52:     else {
  53:     getwd(whereiam);
  54:     if (chdir(cwd)) {
  55:         printf(nocd,cwd) FLUSH;
  56:         sig_catcher(0);
  57:     }
  58:     }
  59:     while (*s == ' ') s++;
  60:                     /* skip leading spaces */
  61:     interp(cmd_buf, (sizeof cmd_buf), s);/* interpret any % escapes */
  62:     resetty();              /* make sure tty is friendly */
  63:     doshell(Nullch,cmd_buf);    /* invoke the shell */
  64:     noecho();               /* and make terminal */
  65:     crmode();               /*   unfriendly again */
  66:     if (docd) {
  67:     if (chdir(whereiam)) {
  68:         printf(nocd,whereiam) FLUSH;
  69:         sig_catcher(0);
  70:     }
  71:     }
  72: #ifdef MAILCALL;
  73:     mailcount = 0;          /* force recheck */
  74: #endif
  75:     return 0;
  76: }
  77: 
  78: /* process & command */
  79: 
  80: int
  81: switcheroo()
  82: {
  83:     if (!finish_command(TRUE)) /* get rest of command */
  84:     return -1;  /* if rubbed out, try something else */
  85:     if (!buf[1])
  86:     pr_switches();
  87: #ifdef PUSHBACK
  88:     else if (buf[1] == '&') {
  89:     if (!buf[2]) {
  90:         page_init();
  91:         show_macros();
  92:     }
  93:     else {
  94:         char tmpbuf[LBUFLEN];
  95:         register char *s;
  96: 
  97:         for (s=buf+2; isspace(*s); s++);
  98:         mac_line(s,tmpbuf,(sizeof tmpbuf));
  99:     }
 100:     }
 101: #endif
 102:     else {
 103:     bool docd = (instr(buf,"-d") != Nullch);
 104:     char whereami[256];
 105: 
 106:     if (docd)
 107:         getwd(whereami);
 108:     sw_list(buf+1);
 109:     if (docd) {
 110:         cwd_check();
 111:         if (chdir(whereami)) {      /* -d does chdirs */
 112:         printf(nocd,whereami) FLUSH;
 113:         sig_catcher(0);
 114:         }
 115:     }
 116:     }
 117:     return 0;
 118: }
 119: 
 120: /* process range commands */
 121: 
 122: int
 123: numnum()
 124: {
 125:     ART_NUM min, max;
 126:     char *cmdlst = Nullch;
 127:     register char *s, *c;
 128:     ART_NUM oldart = art;
 129:     char tmpbuf[LBUFLEN];
 130:     bool justone = TRUE;        /* assume only one article */
 131: 
 132:     if (!finish_command(TRUE))  /* get rest of command */
 133:     return NN_INP;
 134:     if (lastart < 1) {
 135:         fputs("\nNo articles\n",stdout) FLUSH;
 136:         return NN_ASK;
 137:     }
 138: #ifdef ARTSRCH
 139:     if (srchahead)
 140:     srchahead = -1;
 141: #endif
 142:     for (s=buf; *s && (isdigit(*s) || index(" ,-.$",*s)); s++)
 143:     if (!isdigit(*s))
 144:         justone = FALSE;
 145:     if (*s) {
 146:     cmdlst = savestr(s);
 147:     justone = FALSE;
 148:     }
 149:     else if (!justone)
 150:     cmdlst = savestr("m");
 151:     *s++ = ',';
 152:     *s = '\0';
 153:     safecpy(tmpbuf,buf,LBUFLEN);
 154:     for (s = tmpbuf; c = index(s,','); s = ++c) {
 155:     *c = '\0';
 156:     if (*s == '.')
 157:         min = oldart;
 158:     else
 159:         min = atol(s);
 160:     if (min<absfirst) {     /* make sure it is reasonable */
 161:         min = absfirst;
 162:         printf("(First article is %ld)\n",(long)absfirst) FLUSH;
 163:         pad(just_a_sec/3);
 164:     }
 165:     if ((s=index(s,'-')) != Nullch) {
 166:         s++;
 167:         if (*s == '$')
 168:         max = lastart;
 169:         else if (*s == '.')
 170:         max = oldart;
 171:         else
 172:         max = atol(s);
 173:     }
 174:     else
 175:         max = min;
 176:     if (max>lastart) {
 177:         max = lastart;
 178:         if (min > max)
 179:         min = max;
 180:         printf("(Last article is %ld)\n",(long)lastart) FLUSH;
 181:         pad(just_a_sec/3);
 182:     }
 183:     if (max < min) {
 184:         fputs("\nBad range\n",stdout) FLUSH;
 185:         if (cmdlst)
 186:         free(cmdlst);
 187:         return NN_ASK;
 188:     }
 189:     if (justone) {
 190:         art = min;
 191:         return NN_REREAD;
 192:     }
 193:     check_first(min);
 194:     for (art=min; art<=max; art++) {
 195:         if (perform(cmdlst,TRUE)) {
 196: #ifdef VERBOSE
 197:         IF(verbose)
 198:             printf("\n(Interrupted at article %ld)\n",(long)art)
 199:               FLUSH;
 200:         ELSE
 201: #endif
 202: #ifdef TERSE
 203:             printf("\n(Intr at %ld)\n",(long)art) FLUSH;
 204: #endif
 205:         if (cmdlst)
 206:             free(cmdlst);
 207:         return NN_ASK;
 208:         }
 209:     }
 210:     }
 211:     art = oldart;
 212:     if (cmdlst)
 213:     free(cmdlst);
 214:     return NN_NORM;
 215: }
 216: 
 217: int
 218: perform(cmdlst,toplevel)
 219: register char *cmdlst;
 220: int toplevel;
 221: {
 222:     register int ch;
 223: 
 224:     if (toplevel) {
 225:     printf("%-6ld",art);
 226:     fflush(stdout);
 227:     }
 228:     for (; ch = *cmdlst; cmdlst++) {
 229:     if (isspace(ch) || ch == ':')
 230:         continue;
 231:     if (ch == 'j') {
 232:         if (!was_read(art)) {
 233:         mark_as_read(art);
 234: #ifdef VERBOSE
 235:         IF(verbose)
 236:             fputs("\tJunked",stdout);
 237: #endif
 238:         }
 239:     }
 240:     else if (ch == 'm') {
 241:         if (was_read(art)) {
 242:         unmark_as_read(art);
 243: #ifdef VERBOSE
 244:         IF(verbose)
 245:             fputs("\tMarked unread",stdout);
 246: #endif
 247:         }
 248:     }
 249:     else if (ch == 'M') {
 250: #ifdef DELAYMARK
 251:         delay_unmark(art);
 252: #ifdef VERBOSE
 253:         IF(verbose)
 254:             fputs("\tWill return",stdout);
 255: #endif
 256: #else
 257:         notincl("M");
 258:         return -1;
 259: #endif
 260:     }
 261:     else if (ch == '=') {
 262:         printf("\t%s",fetchsubj(art,FALSE,FALSE));
 263: #ifdef VERBOSE
 264:         IF(verbose)
 265:         ;
 266:         ELSE
 267: #endif
 268:         putchar('\n') FLUSH;        /* ghad! */
 269:     }
 270:     else if (ch == 'C') {
 271: #ifdef ASYNC_PARSE
 272:         printf("\t%sancelled",(cancel_article() ? "Not c" : "C"));
 273: #else
 274:         notincl("C");
 275:         return -1;
 276: #endif
 277:     }
 278:     else if (ch == '%') {
 279: #ifdef ASYNC_PARSE
 280:         char tmpbuf[512];
 281: 
 282:         cmdlst = dointerp(tmpbuf, (sizeof tmpbuf), cmdlst,":");
 283:         if (*cmdlst != ':')
 284:         --cmdlst;
 285:         if (perform(tmpbuf,FALSE))
 286:         return -1;
 287: #else
 288:         notincl("%");
 289:         return -1;
 290: #endif
 291:     }
 292:     else if (index("!&sSwW|",ch)) {
 293:         cmdlst = cpytill(buf,cmdlst,':') - 1;
 294:         /* we now have the command in buf */
 295:         if (ch == '!') {
 296:         escapade();
 297: #ifdef VERBOSE
 298:         IF(verbose)
 299:             fputs("\tShell escaped",stdout);
 300: #endif
 301:         }
 302:         else if (ch == '&') {
 303:         switcheroo();
 304: #ifdef VERBOSE
 305:         IF(verbose)
 306:             fputs("\tSwitched",stdout);
 307: #endif
 308:         }
 309:         else {
 310:         putchar('\t');
 311:         save_article();
 312:         }
 313:     }
 314:     else {
 315:         printf("\t???%s\n",cmdlst);
 316:         return -1;
 317:     }
 318: #ifdef VERBOSE
 319:     fflush(stdout);
 320: #endif
 321:     }
 322:     if (toplevel) {
 323: #ifdef VERBOSE
 324:     IF(verbose)
 325:         putchar('\n') FLUSH;
 326:     ELSE
 327: #endif
 328: #ifdef TERSE
 329:         putchar(' ');
 330: #endif
 331:     }
 332:     return 0;
 333: }

Defined functions

escapade defined in line 37; used 5 times
ngstuff_init defined in line 29; used 2 times
numnum defined in line 122; used 2 times
perform defined in line 217; used 4 times
switcheroo defined in line 80; used 5 times
Last modified: 1985-06-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1549
Valid CSS Valid XHTML 1.0 Strict