home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / mm / mm-ccmd-0.91-20031009.tar.gz / mm-ccmd-0.91-20031009.tar / work / ccmd / cmtxt.c < prev    next >
C/C++ Source or Header  |  2000-01-02  |  4KB  |  134 lines

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