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

  1. /*
  2.  *  This file was generated by the SOM Compiler.
  3.  *  Generated using:
  4.  *     SOM incremental update: 10.9
  5.     Last change:  KAS  18 Oct 94    4:06 pm
  6.  */
  7.  
  8.  
  9. #ifndef lint
  10. static char *sccsid = "%Z% %I% %W% %G% %U% [%H% %T%] (c)IBM Corp. 1992";
  11. #endif
  12.  
  13. /*
  14.  * This class is adapted from the book
  15.  *   Class Construction in C and C++, Object Oriented Fundamentals
  16.  *   by Roger Sessions, Copyright (c) 1992 Prentice Hall.
  17.  * Reprinted with permission.
  18.  */
  19.  
  20. #define word_Class_Source
  21. #if defined(_WIN32)
  22. #include "statcls.h"
  23. #endif
  24. #include "word.ih"
  25. #include <stdlib.h>
  26. #include <string.h>
  27.  
  28. static int nNews = 0;
  29. static int nDeletes = 0;
  30. #define PARRAY_SIZE        1000
  31. static char *parray[PARRAY_SIZE];
  32.  
  33.  
  34. /* ************************************************************ */
  35. /*
  36.  *  Initialize a word with a character string.
  37.  */
  38.  
  39. SOM_Scope word*  SOMLINK wordInit1(word *somSelf,
  40.         string newWord)
  41. {
  42.     wordData *somThis = wordGetData(somSelf);
  43.     wordMethodDebug("word", "wordInit1");
  44.  
  45.     if (_storage)
  46.       #ifdef _WIN32
  47.       SOMFree(_storage);
  48.       #else
  49.     free(_storage);
  50.     #endif /*WIN32*/
  51.     _storage = (string) SOMMalloc(strlen(newWord) + 1);
  52.     strcpy(_storage, newWord);
  53.     _length = strlen(newWord);
  54.     parray[nNews] = _storage;
  55.     nNews++;
  56.     return somSelf;
  57. }
  58.  
  59. /* ************************************************************ */
  60. /*
  61.  *  Initialize a word with a character and
  62.  *  count.  The new word will contain a null
  63.  *  terminated buffer containing count number of
  64.  *  newChars.
  65.  */
  66.  
  67. SOM_Scope word*  SOMLINK wordInit2(word *somSelf,
  68.         char newChar,
  69.         long count)
  70. {
  71.     wordData *somThis = wordGetData(somSelf);
  72.     int n;
  73.  
  74.     wordMethodDebug("word", "wordInit2");
  75.  
  76.     if (_storage)
  77.       #ifdef _WIN32
  78.       SOMFree(_storage);
  79.       #else
  80.     free(_storage);
  81.     #endif /*WIN32*/
  82.     _storage = (string) SOMMalloc(count + 1);
  83.     for (n = 0; n < count; n++) {
  84.     _storage[n] = newChar;
  85.     }
  86.     _storage[n] = '\0';
  87.     _length = strlen(_storage);
  88.     parray[nNews] = _storage;
  89.     nNews++;
  90.     return somSelf;
  91. }
  92.  
  93. /* ************************************************************ */
  94. /*
  95.  *  Translate a word to an integer, such as "123" to 123.
  96.  */
  97.  
  98. SOM_Scope long  SOMLINK wordToInt(word *somSelf)
  99. {
  100.     wordData *somThis = wordGetData(somSelf);
  101.     wordMethodDebug("word", "wordToInt");
  102.     return atoi(_storage);
  103. }
  104.  
  105. /* ************************************************************ */
  106.  
  107. /*
  108.  * SOM_Scope boolean SOMLINK match(word * somSelf,
  109.  *                  void *target)
  110.  */
  111.  
  112. SOM_Scope boolean  SOMLINK match(word *somSelf,
  113.                                  string target)
  114. {
  115.     wordData *somThis = wordGetData(somSelf);
  116.     int targetLength = strlen(target);
  117.     wordMethodDebug("word", "match");
  118.     return (!strncmp(_storage, target, targetLength));
  119. }
  120.  
  121. /* ************************************************************ */
  122. SOM_Scope void SOMLINK print(word * somSelf,
  123.                   FILE * outputFile)
  124. {
  125.     wordData *somThis = wordGetData(somSelf);
  126.     wordMethodDebug("word", "print");
  127.  
  128.     fprintf(outputFile, "%s", _storage);
  129.     fflush(outputFile);
  130. }
  131.  
  132. /* ************************************************************ */
  133. SOM_Scope void SOMLINK somInit(word * somSelf)
  134. {
  135.     wordData *somThis = wordGetData(somSelf);
  136.     wordMethodDebug("word", "somInit");
  137.     parent_somInit(somSelf);
  138.     _storage = 0;
  139. }
  140.  
  141. /* ************************************************************ */
  142. SOM_Scope void SOMLINK somUninit(word * somSelf)
  143. {
  144.     wordData *somThis = wordGetData(somSelf);
  145.     wordMethodDebug("word", "somUninit");
  146.     if (_storage)
  147.       #ifdef _WIN32
  148.       SOMFree(_storage);
  149.       #else
  150.     free(_storage);
  151.     #endif /*WIN32*/
  152.     parent_somUninit(somSelf);
  153. }
  154.  
  155. /* ************************************************************ */
  156.  
  157. /*
  158.  * SOM_Scope void SOMLINK somDumpSelfInt(word * somSelf,
  159.  *                        int level)
  160.  */
  161.  
  162. /*
  163.  * The prototype for somDumpSelfInt was replaced by the following prototype:
  164.  */
  165. SOM_Scope void  SOMLINK somDumpSelfInt(word *somSelf,
  166.         long level)
  167. {
  168.     wordData *somThis = wordGetData(somSelf);
  169.     wordMethodDebug("word", "somDumpSelfInt");
  170.     parent_somDumpSelfInt(somSelf, level);
  171. }
  172.  
  173. void showWordStats()
  174. {
  175.     int n;
  176.     printf("\n");
  177.     printf("   nNews: %d\n", nNews);
  178.     printf("nDeletes: %d\n", nDeletes);
  179.     for (n = 0; n < PARRAY_SIZE; n++) {
  180.     if (parray[n]) {
  181.         printf("n: %d storage: %s\n", n, parray[n]);
  182.     }
  183.     }
  184. }
  185.  
  186.  
  187. /* ************************************************************ */
  188. /*
  189.  *  Replace the contents of a word by another word.
  190.  */
  191.  
  192. SOM_Scope void  SOMLINK wrdReplace(word *somSelf,
  193.         string newWord)
  194. {
  195.     wordData *somThis = wordGetData(somSelf);
  196.     wordMethodDebug("word", "wrdReplace");
  197.  
  198.     _length = strlen(newWord);
  199.     if (_storage)
  200.       #ifdef _WIN32
  201.       SOMFree(_storage);
  202.       #else
  203.     free(_storage);
  204.     #endif /*WIN32*/
  205.     _storage = (string) SOMMalloc(_length + 1);
  206.     strcpy(_storage, newWord);
  207. }
  208.