home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / toolkt21 / c / samples / tp / tpword.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-12  |  2.4 KB  |  101 lines

  1. #ifndef lint
  2. static char *sccsid = "@(#)tpword.c 1.3 1/22/92 16:11:32 [1/26/92] (c)IBM Corp. 1992";
  3. #endif
  4.  
  5. /*
  6.  * This class is adapted from the book
  7.  *   Class Construction in C and C++, Object Oriented Fundamentals
  8.  *   by Roger Sessions, Copyright (c) 1992 Prentice Hall.
  9.  * Reprinted with permission.
  10.  */
  11.  
  12. #define TPWord_Class_Source
  13. #include <string.h>
  14. #include "tpword.ih"
  15.  
  16. /* ************************************************************ */
  17. SOM_Scope int SOMLINK tpwType(TPWord * somSelf)
  18. {
  19. /* TPWordData *somThis = TPWordGetData(somSelf); */
  20.      TPWordMethodDebug("TPWord", "tpwType");
  21.  
  22.     if (_match(somSelf, "[[EOF]]"))
  23.     return TP_EOF;
  24.     else if (_match(somSelf, "[["))
  25.     return TP_TOKEN;
  26.     else if (_match(somSelf, "\n\n"))
  27.     return TP_PARAGRAPH_BREAK;
  28.     else if (_match(somSelf, "\n"))
  29.     return TP_LINE_BREAK;
  30.     else if (_match(somSelf, " "))
  31.     return TP_BLANK_SPACE;
  32.     else
  33.     return TP_WORD;
  34. }
  35.  
  36. TPWord *readToken(fileMgr * myFile)
  37. {
  38.     char buffer[100];
  39.     int nxtChr;
  40.     int n = 0;
  41.     int brackets;
  42.     TPWord *newWord;
  43.     nxtChr = _fmPeekChar(myFile, 0);
  44.  
  45. /* Check for string of blanks.
  46.    --------------------------- */
  47.     if (nxtChr == ' ') {
  48.     while (_fmPeekChar(myFile, 0) == ' ') {
  49.         buffer[n++] = (char) _fmGetChar(myFile);
  50.     }
  51.     }
  52. /* Check for string of newlines.
  53.    ----------------------------- */
  54.     else if (nxtChr == '\n') {
  55.     while (_fmPeekChar(myFile, 0) == '\n') {
  56.         buffer[n++] = (char) _fmGetChar(myFile);
  57.     }
  58.     }
  59. /* Check for EOF.
  60.    -------------- */
  61.     else if (nxtChr == EOF) {
  62.     strcpy(buffer, "[[EOF]]");
  63.     n = strlen(buffer);
  64.     }
  65. /* Check for special token.
  66.    ------------------------ */
  67.     else if ((nxtChr == '[') && (_fmPeekChar(myFile, 1) == '[')) {
  68.     brackets = 0;
  69.     while (brackets < 2) {
  70.         nxtChr = _fmGetChar(myFile);
  71.         buffer[n++] = (char) nxtChr;
  72.         if (nxtChr == ']')
  73.         brackets++;
  74.         else
  75.         brackets = 0;
  76.     }
  77.     }
  78. /* Otherwise, handle as word.
  79.    -------------------------- */
  80.     else {
  81.     for (;;) {
  82.         nxtChr = _fmPeekChar(myFile, 0);
  83.         if (nxtChr == ' ')
  84.         break;
  85.         if (nxtChr == '\n')
  86.         break;
  87.         if (nxtChr == EOF)
  88.         break;
  89.         if (nxtChr == '[')
  90.         break;
  91.         buffer[n++] = (char) _fmGetChar(myFile);
  92.     }
  93.     }
  94. /* Return converted buffer.
  95.    ------------------------ */
  96.     buffer[n] = '\0';
  97.     newWord = TPWordNew();
  98.     _wordInit1(newWord, buffer);
  99.     return newWord;
  100. }
  101.