home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / bcpp1611.zip / BCPP / CONFIG.H < prev    next >
C/C++ Source or Header  |  1996-12-18  |  8KB  |  200 lines

  1. #ifndef _CONFIG_HEADER
  2. #define _CONFIG_HEADER
  3.  
  4. // Program C(++) beautifier Written By Steven De Toni ACBC 11 10/94
  5. //
  6. // This file contains prototypes, constants, enum declarations for the
  7. // source file config?.cpp. Prototypes declared can read data from a
  8. // text file a line at a time, and able to read parameters from a
  9. // configuration file.
  10.  
  11. #include <stdio.h>            // FILE Structure
  12.  
  13. static const char  pConfigWord[][29] =
  14. {
  15.                               // 0
  16.     ";"                         ,
  17.  
  18.                               // 1
  19.     "FUNCTION_SPACING"          ,
  20.  
  21.                               // 2
  22.     "USE_TABS"                  ,
  23.                               // 3
  24.     "INDENT_SPACING"            ,
  25.                               // 4
  26.     "NONASCII_QUOTES_TO_OCTAL"  ,
  27.  
  28.                               // 5
  29.     "COMMENTS_WITH_CODE"        ,
  30.                               // 6
  31.     "COMMENTS_WITH_NOCODE"      ,
  32.     //JZAS Start
  33.                               // 7
  34.     "LEAVE_COMMENTS_NOCODE"     ,
  35.     // JZAS End
  36.  
  37.                               // 8
  38.     "LEAVE_GRAPHIC_CHARS"       ,
  39.                               // 9
  40.     "ASCII_CHARS_ONLY"          ,
  41.                               // 10
  42.     "PLACE_BRACE_ON_NEW_LINE"   ,
  43.                               // 11
  44.     "PROGRAM_OUTPUT"            ,
  45.                               // 12
  46.     "QUEUE_BUFFER"              ,
  47.                               // 13
  48.     "BACKUP_FILE"               ,
  49.                               // 14
  50.     "FORMAT_STYLE"               ,
  51.                               // 15
  52.     "FUNCTION_INDENT"            ,
  53.                               // 16
  54.     "DOS_FORMAT"                 ,
  55.                               // 17
  56.     "="                         ,
  57.                               // 18
  58.     "YES"                       ,
  59.                               // 19
  60.     "ON"                        ,
  61.                               // 20
  62.     "NO"                        ,
  63.     "OFF"                     // 21
  64. };
  65.  
  66.  
  67. enum Boolean     {False = 0, True = -1};
  68.  
  69. enum ConfigWords
  70. {
  71.     ANYT = 0, FSPC, UTAB, ISPC, NAQTOOCT, COMWC, COMNC, LCNC,
  72.     LGRAPHC, ASCIIO, PBNLINE, PROGO, QBUF, BUF, FMTSTY, IFUNC,
  73.     DOSF, EQUAL, YES, ON, NO, OFF
  74. };
  75.  
  76.  
  77. enum ConfigChars {NULLC = '\0', TAB = 9, LF = 10, CR = 13, SPACE = ' ', SEMICOLON = ';'};
  78.  
  79. // This structure is used to store the users settings that are read from a
  80. // configuration file.
  81. struct Config
  82. {
  83.     int     numOfLineFunc  ;  // number of lines between functions
  84.     int     tabSpaceSize   ;  // number of spaces a tab takes up {4}
  85.     Boolean useTabs        ;  // True = use tabs in indentingm, False = use spaces
  86.     int     posOfCommentsWC;  // position of comments on line with code
  87.     int     posOfCommentsNC;  // position of comments on line
  88.     // JZAS Start
  89.     Boolean leaveCommentsNC;  // True = don't change the indentation of comments with code.
  90.     // JZAS End
  91.     Boolean quoteChars     ;  // change non-ascii chars in quotes to octal notation
  92.     int     deleteHighChars;  // 0  = no check         , 1 = delete high chars,
  93.     // 2  = dont delete graphics chars
  94.     Boolean braceLoc       ;  // True = place on new line, False = at end of code
  95.     Boolean output         ;  // Set this True for normal program output
  96.     int     queueBuffer    ;  // Set the number if lines to store in memory at a time !
  97.     Boolean backUp         ;  // backup the original file, have output file become input file name !
  98.     Boolean formatStyle    ;  // backup the original file, have output file become input file name !
  99.     Boolean functionIndent ;  // backup the original file, have output file become input file name !
  100.     Boolean dosLines       ;  // backup the original file, have output file become input file name !
  101. };
  102.  
  103.  
  104. // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  105. // Allocates memory for line in file, and places that the data in it.
  106. // pInFile = the file handle to use when reading the file !
  107. // EndOfFile variable is ued to test if the end of the file has been reached.
  108. //           When  this is true, the variable is changed to -1
  109. //
  110. // A string is returned with the contents the current line in the file,
  111. // memory is allocated via the ReadLine routine, and should be deleted
  112. // when not needed !
  113. char* ReadLine (FILE *pInFile, int& EndOfFile);
  114.  
  115.  
  116. // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\
  117. // Functions finds keywords within a line of data.
  118. //
  119. // Parameters:
  120. // Type :
  121. //        The parameter is used to define the type of keyword to find within
  122. //        a configuration line.
  123. //
  124. //        See ConfigWords enum for values, Use ANYT, or a value of 0 to search
  125. //        for any valid keywords within the line.
  126. //
  127. // pConfigLine :
  128. //        This parameter is a pointer to a string that contains the data that
  129. //        is going to be searched.
  130. //
  131. // Return Values:
  132. //
  133. // Type : Returns the keyword value expected, or keyword value found if
  134. //        searching for any.
  135. //
  136. // Char*: Returns a pointer in the string to the next starting location
  137. //        AFTER the keyword found. Or returns NULL if no keyword found!
  138. //
  139. char* FindConfigWords (char* pConfigLine, ConfigWords& type);
  140.  
  141.  
  142. // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  143. // This function is used to generate a generic error message.
  144. //
  145. // Parameters:
  146. // LineNo       : Line number where the error occured
  147. // errorCode    : Error type to output to the user
  148. // errorCount   : This variable is increment when this function is used
  149. // pMessage     : Use by programmer to add additional information about the error
  150. //
  151. //
  152. // Return Values:
  153. // errorCount   : This variable is used to show how many errors have occured!
  154. //
  155. void ErrorMessage (int lineNo, int errorCode, int& errorCount, const char* pMessage = NULL);
  156.  
  157.  
  158. // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  159. // ConfigAssignment function is used to assigned Boolean, or unsigned integer
  160. // values from 0 - 500 to variables that are passed to it.
  161. //
  162. // Parameters:
  163. // type       : This variable defines the keyword next to expect within config line.
  164. // assignType : The variable is used to define what type of assignment to use,
  165. //              (i.e 1 = Boolean, 2 = Integer)
  166. // errorCount : Variable used to define how many error have occured. If any errors
  167. //              encounted within the function, then this var will be incremented.
  168. // PosInLine  : Defines a pointer to the starting location to read in data for
  169. //              assignment from config data line (string).
  170. // variable   : This defines the variables that's going to be altered, be boolean, or
  171. //              integer.
  172. //
  173. // Return Values:
  174. // errorCount : If any error occur within variable assignment, the a error
  175. //              message is displayed, and this vaiable is incremented.
  176. // variable   : If no errors have occured, then this variable will contain the value
  177. //              that was set by the user !
  178. //
  179. void ConfigAssignment (ConfigWords type, int assignType, int& errorCount, int& configError, char* pPosInLine, int& variable);
  180.  
  181.  
  182. // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  183. // This function is used to load the users configuration from a file.
  184. //
  185. // Parameters:
  186. // pConfigFile  : Pointer to a FILE structure/handle that contains the
  187. //                configuration data.
  188. // userSettings : Config structure that will contain the user settings.
  189. //
  190. // Return Values:
  191. // int          : Returns the number of errors encounted when reading the
  192. //                configuration file.
  193. // userSettings : This variable is altered to the user settings read from the
  194. //                config file.
  195. //
  196. int SetConfig (FILE* pConfigFile, Config& userSettings);
  197.  
  198. #endif
  199.  
  200.