home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / rn_4_3_blars.lzh / ngstuff.c < prev    next >
Text File  |  1990-08-22  |  6KB  |  339 lines

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