home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / som / somk / c / tp / tpword.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-24  |  2.6 KB  |  115 lines

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