home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tools / make / tcmak / mak_cfg.c < prev    next >
C/C++ Source or Header  |  1988-06-21  |  2KB  |  88 lines

  1. /*
  2.     mak_cfg.c --     get configuration information
  3.                         for the makemak program
  4. */
  5.  
  6. /*    Last revised : Sun February 21, 1988 at 1:14:57 pm*/
  7. /* Loran W. Richardson */
  8.  
  9. #include    <stdio.h>
  10. #include    <stdlib.h>
  11. #include    <string.h>
  12. #include    "makemak.h"
  13.  
  14. char defaults[LIBS + 1][SLEN];
  15. char mak_defs[LIBS + 1][FNAMELEN];
  16. #define _MAX_PATH 255
  17.  
  18. int mak_cfg(char *pname)
  19. {
  20.     char line[SLEN];
  21.     char temp[SLEN];
  22.     char path[_MAX_PATH];
  23.     char *p;
  24.     char *s;
  25.     FILE *fp;
  26.     FLAGS i;
  27.  
  28. /* set up header strings */
  29.     strcpy(mak_defs[TARGET], "TARGET");
  30.     strcpy(mak_defs[CC], "CC");
  31.     strcpy(mak_defs[C_OPTS], "C_OPTS");
  32.     strcpy(mak_defs[CDEFS] ,"CDEFS");
  33.     strcpy(mak_defs[MC], "MC");
  34.     strcpy(mak_defs[M_OPTS], "M_OPTS");
  35.     strcpy(mak_defs[MDEFS], "MDEFS");
  36.     strcpy(mak_defs[LINK], "LINK");
  37.     strcpy(mak_defs[L_OPTS], "L_OPTS");
  38.     strcpy(mak_defs[LMAP], "LMAP");
  39.     strcpy(mak_defs[LIBS], "LIBS");
  40.  
  41. /* set up the defaults */
  42.  
  43.     strcpy(defaults[CC],    "tcc");
  44.     strcpy(defaults[C_OPTS], "");
  45.     strcpy(defaults[CDEFS],    "");
  46.     strcpy(defaults[MC],    "masm");
  47.     strcpy(defaults[M_OPTS], "");
  48.     strcpy(defaults[MDEFS],    "");
  49.     strcpy(defaults[LINK], "tlink");
  50.     strcpy(defaults[L_OPTS], "");
  51.     strcpy(defaults[LMAP], "NUL");
  52.     strcpy(defaults[LIBS], "");
  53.  
  54.  
  55.  
  56.  
  57. /* get the environment settings */
  58.     if ((s = getenv("TCC")) != NULL)
  59.         strcpy(defaults[C_OPTS], s);
  60.  
  61.     if ((s = getenv("MASM")) != NULL)
  62.         strcpy(defaults[M_OPTS], s);
  63.  
  64.     if ((s = getenv("TLINK")) != NULL)
  65.         strcpy(defaults[L_OPTS], s);
  66.  
  67. /* get the configuration file values */
  68. /*    _searchenv("makemak.cfg", "CONFIG", path);    /* find the configuration file */
  69.     p = searchpath("makemak.cfg");
  70.     strcpy(path, p);
  71.  
  72.     if (path[0] != '\0')
  73.         if ((fp = fopen(path, "r")) != NULL)
  74.             while ((s = fgets(line, SLEN, fp)) != NULL) /* read in a line */
  75.                 {
  76.                 strcpy(temp, strtok(line, " \t\n="));    /* get the first word */
  77.                 for (i = CC; i <= LIBS; ++i)    /* loop through the options */
  78.                     if (strcmpi(temp, mak_defs[i]) == 0) /* word matches option ? */
  79.                         {
  80.                         strcpy(defaults[i], strtok(NULL, "\n")); /* copy the rest of the line */
  81.                         if (defaults[i][0] == '=')                      /* into the defaults */
  82.                             strcpy(defaults[i], (defaults[i]) + 1);
  83.                         break;
  84.                         }
  85.                 }
  86.     return(0);
  87. }
  88.