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

  1.  
  2. /*
  3.  *  This file was generated by the SOM Compiler.
  4.  *  Generated using:
  5.  *     SOM incremental update: 10.9
  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. #include "msgid.h"
  20. #include "nlsutil.h"
  21.  
  22. #define fileMgr_Class_Source
  23. #if defined(_WIN32)
  24. #include "statcls.h"
  25. #endif
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include "fm.ih"
  30.  
  31. /* ************************************************************ */
  32. /*
  33.  *  Initialize and open a new file.
  34.  */
  35.  
  36. SOM_Scope void  SOMLINK fmInit(fileMgr *somSelf,
  37.         string newFile)
  38. {
  39.     fileMgrData *somThis = fileMgrGetData(somSelf);
  40.     fileMgrMethodDebug("fileMgr", "fileMgrInit");
  41.     if (!(_funit = fopen(newFile, "r"))) {
  42.     printf(NlsMsgGet(FileOpenErrorId), newFile);
  43.     exit(3);
  44.     }
  45. }
  46.  
  47. /* ************************************************************ */
  48. /*
  49.  *  Get the next character in the file.
  50.  */
  51.  
  52. SOM_Scope long  SOMLINK fmGetChar(fileMgr *somSelf)
  53. {
  54.     fileMgrData *somThis = fileMgrGetData(somSelf);
  55.     int newChar;
  56.     fileMgrMethodDebug("fileMgr", "fmGetChar");
  57.  
  58.     if (_fmSize(somSelf)) {
  59.     newChar = _buffer[_getSide];
  60.     _getSide = _fmIncr(somSelf, _getSide);
  61.     }
  62.     else {
  63.     newChar = getc(_funit);
  64.     }
  65.     return newChar;
  66. }
  67.  
  68. /* ************************************************************ */
  69. /*
  70.  *  Peek ahead in the file.
  71.  */
  72.  
  73. SOM_Scope long  SOMLINK fmPeekChar(fileMgr *somSelf,
  74.         long offset)
  75. {
  76.     fileMgrData *somThis = fileMgrGetData(somSelf);
  77.     int newChar;
  78.     char cChar;
  79.     int n;
  80.     fileMgrMethodDebug("fileMgr", "fmPeekChar");
  81.  
  82.     for (;;) {
  83.     n = _fmSize(somSelf);
  84.     if (n > offset)
  85.         break;
  86.     newChar = getc(_funit);
  87.     cChar = (char) newChar;
  88.     _buffer[_putSide] = newChar;
  89.     _putSide = _fmIncr(somSelf, _putSide);
  90.     }
  91.     offset = _fmAdd(somSelf, _getSide, offset);
  92.     newChar = _buffer[offset];
  93.     return newChar;
  94. }
  95.  
  96. /* ************************************************************ */
  97. SOM_Scope void SOMLINK somInit(fileMgr * somSelf)
  98. {
  99.     fileMgrData *somThis = fileMgrGetData(somSelf);
  100.     fileMgrMethodDebug("fileMgr", "somInit");
  101.     parent_somInit(somSelf);
  102.  
  103.     _funit = 0;
  104.     _putSide = 0;
  105.     _getSide = 0;
  106. }
  107.  
  108. /* ************************************************************ */
  109. SOM_Scope void SOMLINK somUninit(fileMgr * somSelf)
  110. {
  111.     fileMgrData *somThis = fileMgrGetData(somSelf);
  112.     fileMgrMethodDebug("fileMgr", "somUninit");
  113.  
  114.     if (_funit)
  115.     fclose(_funit);
  116.  
  117.     parent_somUninit(somSelf);
  118. }
  119.  
  120. /* ************************************************************ */
  121.  
  122. /*
  123.  * SOM_Scope void SOMLINK somDumpSelfInt(fileMgr * somSelf,
  124.  *                        int level)
  125.  */
  126.  
  127. /*
  128.  * The prototype for somDumpSelfInt was replaced by the following prototype:
  129.  */
  130. SOM_Scope void  SOMLINK somDumpSelfInt(fileMgr *somSelf,
  131.         long level)
  132. {
  133.     fileMgrData *somThis = fileMgrGetData(somSelf);
  134.     fileMgrMethodDebug("fileMgr", "somDumpSelfInt");
  135.     parent_somDumpSelfInt(somSelf, level);
  136. }
  137.  
  138. /* ************************************************************ */
  139. SOM_Scope long SOMLINK fmSize(fileMgr * somSelf)
  140. {
  141.     fileMgrData *somThis = fileMgrGetData(somSelf);
  142.     int result;
  143.     fileMgrMethodDebug("fileMgr", "size");
  144.  
  145.     if (_getSide == _putSide)
  146.     result = 0;
  147.     else if (_getSide < _putSide)
  148.     result = _putSide - _getSide;
  149.     else
  150.     result = (BUFF_SIZE - _getSide - 1) + (_putSide + 1);
  151.     return result;
  152. }
  153.  
  154. /* ************************************************************ */
  155. SOM_Scope long SOMLINK fmIncr(fileMgr * somSelf,
  156.                   long oldNum)
  157. {
  158.     fileMgrData *somThis = fileMgrGetData(somSelf);
  159.     fileMgrMethodDebug("fileMgr", "incr");
  160.  
  161.     if (oldNum == (BUFF_SIZE - 1))
  162.     return 0;
  163.     else
  164.     return (oldNum + 1);
  165. }
  166.  
  167. /* ************************************************************ */
  168. SOM_Scope long SOMLINK fmAdd(fileMgr * somSelf,
  169.                  long oldNum,
  170.                  long addNum)
  171. {
  172.     fileMgrData *somThis = fileMgrGetData(somSelf);
  173.     fileMgrMethodDebug("fileMgr", "add");
  174.     return ((oldNum + addNum) % BUFF_SIZE);
  175. }
  176.