home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 211.lha / Spiff / command.c < prev    next >
C/C++ Source or Header  |  1996-02-14  |  3KB  |  193 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2. **                            All Rights Reserved
  3. **       Permission is granted to copy or use this program, EXCEPT that it
  4. **       may not be sold for profit, the copyright notice must be reproduced
  5. **       on copies, and credit should be given to Bellcore where it is due.
  6. **       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7. */
  8.  
  9.  
  10. #ifndef lint
  11. static char rcsid[]= "$Header: command.c,v 1.1 88/09/15 11:33:58 daniel Rel $";
  12. #endif
  13.  
  14.  
  15. #include "misc.h"
  16. #include "tol.h"
  17. #include "comment.h"
  18. #include "command.h"
  19. #include "strings.h"
  20. #include "parse.h"
  21.  
  22. /*
  23. **    storage for the string that signals an embedded command
  24. */
  25. static char _C_cmdword[Z_WORDLEN];
  26.  
  27. /*
  28. **    storage for the command script
  29. */
  30. static int _C_nextcmd = 0;
  31. static char *_C_cmds[_C_CMDMAX];
  32.  
  33.  
  34. /*
  35. **    add a string to the command buffer
  36. */
  37. void
  38. C_addcmd(str)
  39. char *str;
  40. {
  41.     S_savestr(&_C_cmds[_C_nextcmd++],str);
  42.     return;
  43. }
  44.  
  45. /*
  46. **    execute a single command
  47. */
  48. static void
  49. _C_do_a_cmd(str)
  50. char *str;
  51. {
  52.     /*
  53.     **    place holder for the beginning of the string
  54.     */
  55.     char *beginning = str;
  56.  
  57.     S_skipspace(&str);
  58.  
  59.     /*
  60.     **    set the command string to allow embedded commands
  61.     */
  62.     if     (!S_wordcmp(str,"command"))
  63.     {
  64.         S_nextword(&str);
  65.         if (strlen(str) >= Z_WORDLEN)
  66.         {
  67.             Z_fatal("command word is too long");
  68.         }
  69.         S_wordcpy(_C_cmdword,str);
  70.     }
  71.     /*
  72.     **    set the tolerances
  73.     */
  74.     else if (!S_wordcmp(str,"tol"))
  75.     {
  76.         S_nextword(&str);
  77.         T_tolline(str);
  78.     }
  79.     /*
  80.     **    add a comment specification
  81.     */
  82.     else if (!S_wordcmp(str,"comment"))
  83.     {
  84.         S_nextword(&str);
  85.         if (strlen(str) >= Z_WORDLEN)
  86.         {
  87.             Z_fatal("command word is too long");
  88.         }
  89.         W_addcom(str,0);
  90.     }
  91.     else if (!S_wordcmp(str,"nestcom"))
  92.     {
  93.         S_nextword(&str);
  94.         if (strlen(str) >= Z_WORDLEN)
  95.         {
  96.             Z_fatal("command word is too long");
  97.         }
  98.         W_addcom(str,1);
  99.     }
  100.     /*
  101.     **    add a literal string specification
  102.     */
  103.     else if (!S_wordcmp(str,"literal"))
  104.     {
  105.         S_nextword(&str);
  106.         if (strlen(str) >= Z_WORDLEN)
  107.         {
  108.             Z_fatal("command word is too long");
  109.         }
  110.         W_addlit(str);
  111.     }
  112.     else if (!S_wordcmp(str,"resetcomments"))
  113.     {
  114.         W_clearcoms();
  115.     }
  116.     else if (!S_wordcmp(str,"resetliterals"))
  117.     {
  118.         W_clearlits();
  119.     }
  120.     else if (!S_wordcmp(str,"beginchar"))
  121.     {
  122.         S_nextword(&str);
  123.         W_setbolchar(*str);
  124.     }
  125.     else if (!S_wordcmp(str,"endchar"))
  126.     {
  127.         S_nextword(&str);
  128.         W_seteolchar(*str);
  129.     }
  130.     else if (!S_wordcmp(str,"addalpha"))
  131.     {
  132.         S_nextword(&str);
  133.         P_addalpha(str);
  134.     }
  135.     else if ((0 == strlen(str)) || !S_wordcmp(str,"rem") 
  136.                     || ('#' == *str))
  137.     {
  138.         /* do nothing */
  139.     }
  140.     else
  141.     {
  142.         (void) sprintf(Z_err_buf,
  143.                    "don't understand command %s\n",
  144.                    beginning);
  145.         Z_fatal(Z_err_buf);
  146.     }
  147.     return;
  148. }
  149.  
  150. /*
  151. **    execute the commands in the command buffer
  152. */
  153. void
  154. C_docmds()
  155. {
  156.     int i;
  157.     for (i=0;i<_C_nextcmd;i++)
  158.     {
  159.         _C_do_a_cmd(_C_cmds[i]);
  160.     }
  161.     return;
  162. }
  163.  
  164. /*
  165. **    disable embedded command key word recognition
  166. */
  167. void
  168. C_clear_cmd()
  169. {
  170.     _C_cmdword[0] = '\0';
  171.     return;
  172. }
  173.  
  174. int
  175. C_is_cmd(inline)
  176. char *inline;
  177. {
  178.     char *ptr;
  179.     /*
  180.     **    see if this is a command line
  181.     **    and if so, do the command right away
  182.     */
  183.     if (('\0' != _C_cmdword[0]) && (!S_wordcmp(inline,_C_cmdword)))
  184.     {
  185.         ptr = inline;
  186.         S_nextword(&ptr);
  187.         _C_do_a_cmd(ptr);
  188.         return(1);
  189.     }
  190.     return(0);
  191. }
  192.  
  193.