home *** CD-ROM | disk | FTP | other *** search
/ Games 1995 to 2000 / Games.iso / SexTetris / PARSER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-16  |  9.3 KB  |  267 lines

  1. #include "microlib.h"
  2.  
  3. extern char iepdrive[3];
  4. extern char ieppath[50];
  5.  
  6. /***************************************************************************\
  7. |* Function: char *files(int filenum)                                      *|
  8. |* Description: Converts Alias Name to Pathname.                           *|
  9. |* Parameters: filenum  --> Which file ?                                   *|
  10. |* Returns: File's pathname.                                               *|
  11. |* Uses: Nothing.                                                          *|
  12. \***************************************************************************/
  13. char *files(filenum)
  14. int filenum;
  15. {
  16.     tmp_pathname[0] = '\0';
  17.  
  18.     strcpy(tmp_pathname, ieppath);
  19.     strcat(tmp_pathname, dbfpath);
  20.     strcat(tmp_pathname, dbf[filenum]);
  21.     return(tmp_pathname);
  22.     }
  23.  
  24. /***************************************************************************\
  25. |* Function: char *screens(int filenum)                                    *|
  26. |* Description: Adds Path to screen file name.                             *|
  27. |* Parameters: filenum  --> Which file ?                                   *|
  28. |* Returns: File's pathname.                                               *|
  29. |* Uses: Nothing.                                                          *|
  30. \***************************************************************************/
  31. char *screens(filenum)
  32. int filenum;
  33. {
  34.     tmp_pathname[0] = '\0';
  35.  
  36.     strcpy(tmp_pathname, ieppath);
  37.     strcat(tmp_pathname, scrpath);
  38.     strcat(tmp_pathname, sc[filenum]);
  39.     return(tmp_pathname);
  40.     }
  41.  
  42. /***************************************************************************\
  43. |* Function: int read_default_values()                                     *|
  44. |* Description: Reads the default values from the file IEP.INI .           *|
  45. |* Parameters: None.                                                       *|
  46. |* Returns: Nothing.                                                       *|
  47. |* Uses: Nothing.                                                          *|
  48. \***************************************************************************/
  49. read_default_values()
  50. {
  51.     FILE    *ini;
  52.     int    count;
  53.     long  section_ptr;
  54.     char  line[80];
  55.  
  56.     if ((ini = fopen("IEP.INI", "r")) == NULL) {
  57.         printf("%sIEP.INI\n", mes[ME+0]);
  58.         exit(1);
  59.         }
  60.  
  61.     line[0]='\0';
  62.     fseek(ini, 0L, SEEK_SET);
  63.     while (!strstr(line, "[colors]")) {
  64.         if ( !fgets(line, 79, ini )) {
  65.             printf(mes[ME+20]);
  66.             exit(1);
  67.             }
  68.         }
  69.     section_ptr = ftell(ini);
  70.  
  71.     custom[MENU_N]    = read_integer(ini, "menu_normal", section_ptr);
  72.     custom[MENU_S]    = read_integer(ini, "menu_selection", section_ptr);
  73.     custom[MENU_F]    = read_integer(ini, "menu_first", section_ptr);
  74.     custom[PULL_N]    = read_integer(ini, "pulldown_normal", section_ptr);
  75.     custom[PULL_S]    = read_integer(ini, "pulldown_selection", section_ptr);
  76.     custom[PULL_F]    = read_integer(ini, "pulldown_first", section_ptr);
  77.     custom[PULL_B]    = read_integer(ini, "pulldown_border", section_ptr);
  78.     custom[PULL_D]    = read_integer(ini, "pulldown_disabled", section_ptr);
  79.     custom[STAT_N]    = read_integer(ini, "status_normal", section_ptr);
  80.     custom[STAT_F]    = read_integer(ini, "status_first", section_ptr);
  81.     custom[MESS_N]    = read_integer(ini, "help_normal", section_ptr);
  82.     custom[ERR_N]    = read_integer(ini, "error_normal", section_ptr);
  83.     custom[ERR_B]    = read_integer(ini, "error_border", section_ptr);
  84.     custom[MAIN_N] = read_integer(ini, "main_normal", section_ptr);
  85.     custom[MAIN_I] = read_integer(ini, "main_input", section_ptr);
  86.     custom[MAIN_S] = read_integer(ini, "main_selection", section_ptr);
  87.     custom[WARN_N] = read_integer(ini, "warn_normal", section_ptr);
  88.     custom[HELPSCR_N] = read_integer(ini, "helpscr_normal", section_ptr);
  89.     custom[HELPSCR_T] = read_integer(ini, "helpscr_title", section_ptr);
  90.     custom[HELPSCR_S] = read_integer(ini, "helpscr_nextsym", section_ptr);
  91.     custom[BROWSER_N] = read_integer(ini, "browser_normal", section_ptr);
  92.     custom[BROWSER_S] = read_integer(ini, "browser_selection", section_ptr);
  93.     custom[BROWSER_B] = read_integer(ini, "browser_border", section_ptr);
  94.     custom[WAIT_N] = read_integer(ini, "wait_normal", section_ptr);
  95.     custom[WAIT_B] = read_integer(ini, "wait_border", section_ptr);
  96.  
  97.     line[0]='\0';
  98.     fseek(ini, 0L, SEEK_SET);
  99.     while (!strstr(line, "[editors]")) {
  100.         if( !fgets(line, 79, ini ) ) {
  101.             printf(mes[ME+19]);
  102.             exit(1);
  103.             }
  104.         }
  105.     section_ptr = ftell(ini);
  106.  
  107.     doccreate = read_integer(ini, "create_document", section_ptr);
  108.     read_string(ini, "wordprocessor", wordprocessor, section_ptr);
  109.     read_string(ini, "viewer", viewer, section_ptr);
  110.     read_string(ini, "docpath", docpath, section_ptr);
  111.     if(docpath[strlen(docpath) - 1] != '\\') {
  112.         docpath[strlen(docpath)] = '\\';
  113.         docpath[strlen(docpath) + 1] = '\0';
  114.         }
  115.  
  116.     if(docpath[1] == ':') {
  117.         memcpy(docdrive, docpath, 2);
  118.         docdrive[0] = gtoupper(docdrive[0]);
  119.         docdrive[2] = '\0';
  120.         }
  121.     else
  122.         memcpy(docdrive, space(3), 3);
  123.     read_string(ini, "pattern", pattern, section_ptr);
  124.  
  125.     line[0]='\0';
  126.     fseek(ini, 0L, SEEK_SET);
  127.     while (!strstr(line, "[misc]")) {
  128.         if( !fgets(line, 79, ini ) ) {
  129.             printf(mes[ME+27]);
  130.             exit(1);
  131.             }
  132.         }
  133.     section_ptr = ftell(ini);
  134.     read_string(ini, "ieppath", ieppath, section_ptr);
  135.     if(ieppath[0] != '\0') {
  136.         if(ieppath[strlen(ieppath) - 1] != '\\') {
  137.             ieppath[strlen(ieppath)] = '\\';
  138.             ieppath[strlen(ieppath) + 1] = '\0';
  139.             }
  140.         if(ieppath[1] == ':') {
  141.             memcpy(iepdrive, ieppath, 2);
  142.             iepdrive[0] = gtoupper(iepdrive[0]);
  143.             iepdrive[2] = '\0';
  144.             }
  145.         else
  146.             memcpy(iepdrive, space(3), 3);
  147.         }
  148.  
  149.     read_string(ini, "comm_program", comm_program, section_ptr);
  150.     read_string(ini, "comm_path", comm_path, section_ptr);
  151.     if(comm_path[0] != '\0') {
  152.         if(comm_path[strlen(comm_path) - 1] != '\\') {
  153.             comm_path[strlen(comm_path)] = '\\';
  154.             comm_path[strlen(comm_path) + 1] = '\0';
  155.             }
  156.         if(comm_path[1] == ':') {
  157.             memcpy(comm_drive, comm_path, 2);
  158.             comm_drive[0] = gtoupper(comm_drive[0]);
  159.             comm_drive[2] = '\0';
  160.             }
  161.         else
  162.             memcpy(comm_drive, space(3), 3);
  163.         }
  164.  
  165.     fclose(ini);
  166.     }
  167.  
  168. /***************************************************************************\
  169. |* Function: int read_string(FILE *fp, char *key, char *ret_str,           *|
  170. |*                                                    long section_ptr)    *|
  171. |* Description: Finds the string "key" in the file "fp" and returns its    *|
  172. |*              value. The file must be in the following format:           *|
  173. |*                    something   =  value                                 *|
  174. |*                    something   =  value                                 *|
  175. |* Parameters: FILE *fp        -> File to search.                              *|
  176. |*             char *key    -> string to search.                            *|
  177. |* Returns: The value after equal sign.                                    *|
  178. |* Uses: Nothing.                                                          *|
  179. \***************************************************************************/
  180. static int read_string(fp, key, ret_str, section_ptr)
  181. FILE    *fp;
  182. char    *key;
  183. char  *ret_str;
  184. long  section_ptr;
  185. {
  186.     char line[80];
  187.     char *line_p;
  188.  
  189.     line[0] = '\0';
  190.  
  191.     fseek(fp, section_ptr, SEEK_SET);
  192.     while (!strstr(line, key)) {
  193.         if( ! fgets(line, 79, fp )) {
  194.             printf("%s %s", mes[ME+54], key);
  195.             fclose(fp);
  196.             exit(-1);
  197.             }
  198.         }
  199.     line_p = strchr(line, '=') + (1 * sizeof(char));
  200.     trim_n(line_p, strlen(line_p));
  201.     strcpy(ret_str, line_p);
  202.     }
  203.  
  204.  
  205. /***************************************************************************\
  206. |* Function: int read_integer(FILE *fp, char *key, long section_ptr)       *|
  207. |* Description: Finds the string "key" in the file "fp" and returns its    *|
  208. |*              value. The file must be in the following format:           *|
  209. |*                    something   =  value                                 *|
  210. |*                    something   =  value                                 *|
  211. |* Parameters: FILE *fp        -> File to search.                              *|
  212. |*             char *key    -> string to search.                            *|
  213. |* Returns: The value after equal sign.                                    *|
  214. |* Uses: Nothing.                                                          *|
  215. \***************************************************************************/
  216. static int read_integer(fp, key, section_ptr)
  217. FILE    *fp;
  218. char    *key;
  219. long  section_ptr;
  220. {
  221.     char line[80];
  222.     line[0] = '\0';
  223.  
  224.     fseek(fp, section_ptr, SEEK_SET);
  225.     while (!strstr(line, key)) {
  226.         if( ! fgets(line, 79, fp ) ) {
  227.             printf("%s %s", mes[ME+54], key);
  228.             fclose(fp);
  229.             exit(-1);
  230.             }
  231.         }
  232.     return(atoi(strchr(line, '=') +1)) ;
  233.     }
  234.  
  235. int trim_n(str, n_ch)
  236. char *str;
  237. int n_ch;
  238. {
  239.     char *old_str;
  240.     int count;
  241.     int pos_d;
  242.  
  243.     /* Allocate memory for the old sting.  */
  244.     if( (old_str = (char *) calloc(n_ch, sizeof(char))) == NULL ) {
  245.         w4display(mes[MT], mes[ME+1], (char *) 0);
  246.         w4exit(1);
  247.         }
  248.     strcpy(old_str, str);
  249.  
  250.     pos_d = 0;
  251.     for(count = 0; count < n_ch; count ++) {
  252.         if( old_str[count] == '\n') {
  253.             continue;
  254.             }
  255.         if(old_str[count]==' ' || old_str[count]=='\t') {
  256.             if(old_str[count + 1] == ' ' || old_str[count + 1] == '\n' ||\
  257.                         pos_d == 0) {
  258.                 continue;
  259.                 }
  260.             }
  261.         str[pos_d] = old_str[count];
  262.         pos_d ++;
  263.         }
  264.     str[pos_d] = '\0';
  265.     free(old_str);
  266.     }
  267.