home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / ccmd / cmtxt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-19  |  4.0 KB  |  134 lines

  1. /*
  2.  Author: Andrew Lowry
  3.  
  4.  Columbia University Center for Computing Activities, July 1986.
  5.  Copyright (C) 1986, 1987, Trustees of Columbia University in the City
  6.  of New York.  Permission is granted to any individual or institution
  7.  to use, copy, or redistribute this software so long as it is not sold
  8.  for profit, provided this copyright notice is retained.
  9. */
  10. /* cmtxt
  11. **
  12. ** This module contains the default break table and handlers for
  13. ** parsing a line of text.  Parsing succeeds if the current input
  14. ** consists of characters allowed by the break table and terminated
  15. ** by a newline character.  Completion always beeps, and standard
  16. ** help is always the same.  If parsing succeeds, the line of text,
  17. ** up to but not including the newline character, is copied into
  18. ** the atom buffer.
  19. **
  20. ** The break table determines which characters are allowed in the
  21. ** text.  The _br1st array specifies characters allowed in the first
  22. ** position, and _brrst specifies characters allowed in subsequent
  23. ** positions.  The default break table allows all printing characters
  24. ** in the interior of the text, and all but question mark at the front
  25. ** (so help works at the beginning, but not after the field has begun).
  26. ** Also, space and tab are break characters in the first position, so
  27. ** they will be skipped by the input loop.
  28. **/
  29.  
  30. #define TXTERR            /* declare cmtxt parse errors here */
  31.  
  32. #include "ccmdlib.h"        /* get ccmd package symbols */
  33. #include "cmfncs.h"        /* and internal symbols */
  34.  
  35. /* Forward declarations for handlers */
  36.  
  37. int txtprs(), txthlp(), txtcplt();
  38.  
  39. /* standard break table */
  40.  
  41. static brktab txtbrk = {
  42.   {                    /* print chars except ?, space, tab */
  43.     0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x01,
  44.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  45.   },
  46.   {                    /* all print characters */
  47.     0xff, 0xbf, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  48.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
  49.   }
  50. };
  51.  
  52. ftspec ft_txt = { txtprs, txthlp, txtcplt, 0, &txtbrk }; /* handler structure */
  53.  
  54.  
  55.  
  56. /* txtprs
  57. **
  58. ** Purpose:
  59. **   Attempt to parse a line of text.  Succeeds if the current input contains
  60. **   a newline character, and if the text up to that newline obeys the break
  61. **   table in effect.  A successful parse turns off the CM_CFM flag as a
  62. **   side effect.
  63. **/
  64.  
  65. PASSEDSTATIC int
  66. txtprs(text,textlen,fdbp,parselen,value)
  67. char *text;
  68. int textlen;
  69. fdb *fdbp;
  70. int *parselen;
  71. pval *value;
  72. {
  73.   int nlpos;                /* position of newline char */
  74.   int i;                /* for scanning text */
  75.   brktab *btab;                /* break table to use */
  76.   
  77.   if (textlen == 0)
  78.     return(CMxINC);            /* incomplete parse */
  79.   for (nlpos = 0; nlpos < textlen; nlpos++) /* search text for a newline */
  80.     if (text[nlpos] == NEWLINE)        /* fails if quoted */
  81.       break;                /* found it */
  82.   if (nlpos >= textlen)
  83.     return(CMxINC);            /* no newline in text */
  84.   if ((btab = fdbp->_cmbrk) == NULL)     /* get user specified break table */
  85.     btab = &txtbrk;            /* or used standard */
  86.   for (i = 0; i < nlpos; i++)        /* check included text */
  87.     if ((text[i] & CC_QUO) == 0)    /* accept all quoted chars */
  88.       if (BREAK(btab,text[i],i))
  89.         return(TXTxNP);            /* bad characters in text */
  90.   for (i = 0; i < nlpos; i++)        /* copy to atom buffer */
  91.     if (i >= cmcsb._cmabc-1)        /* leave room for null at end */
  92.       return(CMxAOVF);            /* no room */
  93.     else
  94.       cmcsb._cmabp[i] = text[i] & CC_CHR; /* else copy the text */
  95.   cmcsb._cmabp[nlpos] = NULCHAR;    /* tie off with a null */
  96.   cmcsb._cmflg |= CM_NAC;        /* core routines don't copy to atom */
  97.   cmcsb._cmflg &= ~CM_CFM;        /* no longer confirmed */
  98.   *parselen = nlpos;            /* number of chars consumed */
  99.   value->_pvstr = cmcsb._cmabp;        /* set parse value */
  100.   return(CMxOK);            /* good parse */
  101. }
  102.  
  103.  
  104.  
  105. /* txthlp
  106. **
  107. ** Always the same thing... 
  108. **/
  109.  
  110. PASSEDSTATIC int
  111. txthlp(text,textlen,fdbp,cust)
  112. char *text;
  113. int textlen,cust;
  114. fdb *fdbp;
  115. {
  116.   cmxputs("line of text");
  117.   return(CMxOK);
  118. }
  119.  
  120.  
  121.  
  122. /* txtcplt - Always beep
  123. **/
  124.  
  125. PASSEDSTATIC int
  126. txtcplt(text,textlen,fdbp,full,cplt,cpltlen)
  127. char *text,**cplt;
  128. int textlen,full,*cpltlen;
  129. fdb *fdbp;
  130. {
  131.   *cplt = NULL;
  132.   return(CMP_BEL);        /* beep at them */
  133. }
  134.