Changeset 2869 for trunk/tools


Ignore:
Timestamp:
Feb 23, 2000, 10:26:58 AM (26 years ago)
Author:
bird
Message:

Append option added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/fastdep/fastdep.c

    r2714 r2869  
    1 /* $Id: fastdep.c,v 1.1 2000-02-09 23:48:49 bird Exp $
     1/* $Id: fastdep.c,v 1.2 2000-02-23 09:26:58 bird Exp $
    22 *
    33 * Fast dependents. (Fast = Quick and Dirty!)
     
    3838    BOOL            fNoObjectPath;
    3939    BOOL            fSrcWhenObj;
     40    BOOL            fAppend;            /* append to the output file, not overwrite it. */
    4041} OPTIONS, *POPTIONS;
    4142
     
    8081int main(int argc, char **argv)
    8182{
    82     FILE       *phDep;
     83    FILE       *phDep = NULL;
    8384    int         rc   = 0;
    8485    int         argi = 1;
     
    99100        TRUE,            /* fObjRule */
    100101        FALSE,           /* fNoObjectPath */
    101         TRUE             /* fSrcWhenObj */
     102        TRUE,            /* fSrcWhenObj */
     103        FALSE            /* fAppend */
    102104    };
    103105
     
    108110    }
    109111
    110     /* look for depend filename option "-d <filename>" */
    111     if (argc >= 3 && strcmp(argv[1], "-d") == 0)
    112     {
    113         pszDepFile = argv[2];
    114         argi = 3;
    115     }
    116 
    117     phDep = fopen(pszDepFile, "w");
    118     if (phDep != NULL)
    119     {
    120         while (argi < argc)
     112    while (argi < argc)
     113    {
     114        if (argv[argi][0] == '-' || argv[argi][0] == '/')
    121115        {
    122             if (argv[argi][0] == '-' || argv[argi][0] == '/')
    123             {
    124                 /* parameters */
    125                 switch (argv[argi][1])
    126                 {
    127                     case 'E': /* list of paths. If a file is found in one of these directories the */
    128                     case 'e': /* filename will be used without the directory path. */
    129                         /* Eall<[+]|-> ? */
    130                         if (strlen(&argv[argi][1]) <= 5 && strnicmp(&argv[argi][1], "Eall", 4) == 0)
    131                         {
    132                             options.fExcludeAll = argv[argi][5] != '-';
    133                             break;
    134                         }
    135                         /* path or path list */
    136                         if (strlen(argv[argi]) > 2)
    137                             strcat(szExclude, &argv[argi][2]);
     116            /* parameters */
     117            switch (argv[argi][1])
     118            {
     119                case 'A':
     120                case 'a': /* Append to the output file */
     121                    options.fAppend = argv[argi][2] != '-';
     122                    break;
     123
     124                case 'D':
     125                case 'd': /* "-d <filename>" */
     126                    if (argv[argi][2] != '\0')
     127                        pszDepFile = &argv[argi][2];
     128                    else
     129                    {
     130                        if (argi + 1 < argc)
     131                            pszDepFile = argv[++argi];
    138132                        else
    139133                        {
    140                             strcat(szExclude, argv[argi+1]);
     134                            fprintf(stderr, "invalid parameter -d, filename missing!\n");
     135                            return -1;
     136                        }
     137                    }
     138                    if (phDep != NULL)
     139                    {
     140                        fclose(phDep);
     141                        phDep = NULL;
     142                    }
     143                    break;
     144
     145                case 'E': /* list of paths. If a file is found in one of these directories the */
     146                case 'e': /* filename will be used without the directory path. */
     147                    /* Eall<[+]|-> ? */
     148                    if (strlen(&argv[argi][1]) <= 5 && strnicmp(&argv[argi][1], "Eall", 4) == 0)
     149                    {
     150                        options.fExcludeAll = argv[argi][5] != '-';
     151                        break;
     152                    }
     153                    /* path or path list */
     154                    if (strlen(argv[argi]) > 2)
     155                        strcat(szExclude, &argv[argi][2]);
     156                    else
     157                    {
     158                        strcat(szExclude, argv[argi+1]);
     159                        argi++;
     160                    }
     161                    if (szExclude[strlen(szExclude)-1] != ';')
     162                        strcat(szExclude, ";");
     163                    break;
     164
     165                case 'I': /* optional include path. This has precedence over the INCLUDE environment variable. */
     166                case 'i':
     167                    if (strlen(argv[argi]) > 2)
     168                        strcat(szInclude, &argv[argi][2]);
     169                    else
     170                    {
     171                        strcat(szInclude, argv[argi+1]);
     172                        argi++;
     173                    }
     174                    if (szInclude[strlen(szInclude)-1] != ';')
     175                        strcat(szInclude, ";");
     176                    break;
     177
     178                case 'n': /* no object path , -N<[+]|-> */
     179                case 'N':
     180                    if (strlen(argv[argi]) <= 1+1+1)
     181                        options.fNoObjectPath = argv[argi][2] != '-';
     182                    else
     183                    {
     184                        fprintf(stderr, "error: invalid parameter!, '%s'\n", argv[argi]);
     185                        return -1;
     186                    }
     187                    break;
     188
     189                case 'o': /* object base directory, Obj or Obr<[+]|-> */
     190                case 'O':
     191                    if (strlen(&argv[argi][1]) <= 4 && strnicmp(&argv[argi][1], "Obr", 3) == 0)
     192                    {
     193                        options.fObjRule = argv[argi][4] != '-';
     194                        break;
     195                    }
     196
     197                    if (strlen(&argv[argi][1]) >= 4 && strnicmp(&argv[argi][1], "Obj", 3) == 0)
     198                    {
     199                        if (strlen(argv[argi]) > 4)
     200                            strcpy(szObjectExt, argv[argi]+4);
     201                        else
     202                        {
     203                            strcpy(szObjectExt, argv[argi+1]);
    141204                            argi++;
    142205                        }
    143                         if (szExclude[strlen(szExclude)-1] != ';')
    144                             strcat(szExclude, ";");
    145206                        break;
    146 
    147                     case 'I': /* optional include path. This has precedence over the INCLUDE environment variable. */
    148                     case 'i':
    149                         if (strlen(argv[argi]) > 2)
    150                             strcat(szInclude, &argv[argi][2]);
    151                         else
    152                         {
    153                             strcat(szInclude, argv[argi+1]);
    154                             argi++;
    155                         }
    156                         if (szInclude[strlen(szInclude)-1] != ';')
    157                             strcat(szInclude, ";");
    158                         break;
    159 
    160                     case 'n': /* no object path , -N<[+]|-> */
    161                     case 'N':
    162                         if (strlen(argv[argi]) <= 1+1+1)
    163                             options.fNoObjectPath = argv[argi][2] != '-';
    164                         else
    165                         {
    166                             fprintf(stderr, "error: invalid parameter!, '%s'\n", argv[argi]);
    167                             return -1;
    168                         }
    169                         break;
    170 
    171                     case 'o': /* object base directory, Obj or Obr<[+]|-> */
    172                     case 'O':
    173                         if (strlen(&argv[argi][1]) <= 4 && strnicmp(&argv[argi][1], "Obr", 3) == 0)
    174                         {
    175                             options.fObjRule = argv[argi][4] != '-';
    176                             break;
    177                         }
    178 
    179                         if (strlen(&argv[argi][1]) >= 4 && strnicmp(&argv[argi][1], "Obj", 3) == 0)
    180                         {
    181                             if (strlen(argv[argi]) > 4)
    182                                 strcpy(szObjectExt, argv[argi]+4);
    183                             else
    184                             {
    185                                 strcpy(szObjectExt, argv[argi+1]);
    186                                 argi++;
    187                             }
    188                             break;
    189                         }
    190 
    191                         /* path */
    192                         if (strlen(argv[argi]) > 2)
    193                             strcpy(szObjectDir, argv[argi]+2);
    194                         else
    195                         {
    196                             strcpy(szObjectDir, argv[argi+1]);
    197                             argi++;
    198                         }
    199                         if (szObjectDir[strlen(szObjectDir)-1] != '\\'
    200                             && szObjectDir[strlen(szObjectDir)-1] != '/'
    201                             )
    202                             strcat(szObjectDir, "\\");
    203                         break;
    204 
    205                     case 'h':
    206                     case 'H':
    207                     case '?':
    208                         syntax();
    209                         return 1;
    210 
    211                     default:
    212                         fprintf(stderr, "error: invalid parameter! '%s'\n", argv[argi]);
    213                         return -1;
     207                    }
     208
     209                    /* path */
     210                    if (strlen(argv[argi]) > 2)
     211                        strcpy(szObjectDir, argv[argi]+2);
     212                    else
     213                    {
     214                        strcpy(szObjectDir, argv[argi+1]);
     215                        argi++;
     216                    }
     217                    if (szObjectDir[strlen(szObjectDir)-1] != '\\'
     218                        && szObjectDir[strlen(szObjectDir)-1] != '/'
     219                        )
     220                        strcat(szObjectDir, "\\");
     221                    break;
     222
     223                case 'h':
     224                case 'H':
     225                case '?':
     226                    syntax();
     227                    return 1;
     228
     229                default:
     230                    fprintf(stderr, "error: invalid parameter! '%s'\n", argv[argi]);
     231                    return -1;
     232            }
     233
     234        }
     235        else
     236        {   /* not a parameter! */
     237            ULONG        ulRc;
     238            FILEFINDBUF3 filebuf = {0};
     239            HDIR         hDir = HDIR_CREATE;
     240            ULONG        ulFound = 1;
     241
     242            /*
     243             * Open output file.
     244             */
     245            if (phDep == NULL)
     246            {
     247                phDep = fopen(pszDepFile, options.fAppend ? "a" : "w");
     248                if (phDep == NULL)
     249                {
     250                    fprintf(stderr, "error opening outputfile '%s'.\n", pszDepFile);
     251                    return 1;
    214252                }
    215 
    216             }
    217             else
    218             {   /* not a parameter! */
    219                 ULONG        ulRc;
    220                 FILEFINDBUF3 filebuf = {0};
    221                 HDIR         hDir = HDIR_CREATE;
    222                 ULONG        ulFound = 1;
    223 
    224                 ulRc = DosFindFirst(argv[argi], &hDir,
    225                                     FILE_READONLY |  FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED,
    226                                     &filebuf, sizeof(FILEFINDBUF3), &ulFound, FIL_STANDARD);
    227                 while (ulRc == NO_ERROR)
     253            }
     254
     255            /*
     256             * Search for the files specified.
     257             */
     258            ulRc = DosFindFirst(argv[argi], &hDir,
     259                                FILE_READONLY |  FILE_HIDDEN | FILE_SYSTEM | FILE_ARCHIVED,
     260                                &filebuf, sizeof(FILEFINDBUF3), &ulFound, FIL_STANDARD);
     261            while (ulRc == NO_ERROR)
     262            {
     263                char *psz;
     264                char  szSource[CCHMAXPATH];
     265
     266                /*
     267                 * Make full path.
     268                 */
     269                if ((psz = strrchr(argv[argi], '\\')) || (psz = strrchr(argv[argi], '/')))
    228270                {
    229                     char *psz;
    230                     char  szSource[CCHMAXPATH];
    231 
    232                     if ((psz = strrchr(argv[argi], '\\')) || (psz = strrchr(argv[argi], '/')))
    233                     {
    234                         strncpy(szSource, argv[argi], psz - argv[argi] + 1);
    235                         szSource[psz - argv[argi] + 1]  = '\0';
    236                     }
    237                     else
    238                         szSource[0]  = '\0';
    239 
    240                     strcat(szSource, filebuf.achName);
    241                     rc -= makeDependent(phDep, &szSource[0], &options);
    242                     ulRc = DosFindNext(hDir, &filebuf, sizeof(filebuf), &ulFound);
     271                    strncpy(szSource, argv[argi], psz - argv[argi] + 1);
     272                    szSource[psz - argv[argi] + 1]  = '\0';
    243273                }
    244                 DosFindClose(hDir);
    245             }
    246             /* next */
    247             argi++;
     274                else
     275                    szSource[0]  = '\0';
     276                strcat(szSource, filebuf.achName);
     277
     278                /*
     279                 * Analyse the file.
     280                 */
     281                rc -= makeDependent(phDep, &szSource[0], &options);
     282
     283                /* next file */
     284                ulRc = DosFindNext(hDir, &filebuf, sizeof(filebuf), &ulFound);
     285            }
     286            DosFindClose(hDir);
    248287        }
    249     } else
    250     {
    251         fprintf(stderr, "error opening outputfile '%s'.\n", pszDepFile);
    252         rc = 1;
     288        /* next */
     289        argi++;
    253290    }
    254291
     
    268305        "Quick and dirty dependant scanner. Creates a makefile readable depend file.\n"
    269306        "\n"
    270         "Syntax: FastDep [-d <outputfn>] [-e <excludepath>] [-eall<[+]|->]\n"
    271         "                [-i <include>] [-n<[+]|->] [-o <objdir>] [-obr<[+]|->]\n"
     307        "Syntax: FastDep [-a<[+]|->] [-d <outputfn>] [-e <excludepath>] [-eall<[+]|->]\n"
     308        "                [-i <include>] [-n<[+]|->] [-o <objdir>] [-obr<[+]|->] <files>\n"
    272309        "\n"
     310        "   -a<[+]|->       Append to the output file. Default: Overwrite.\n"
    273311        "   -d <outputfn>   Output filename. Default: %s\n"
    274312        "   -e excludepath  Exclude paths. If a filename is found in any\n"
     
    285323        "   -obr<[+]|->     -obr+: Object rule.\n"
    286324        "                   -obr-: No object rule, rule for source filename is generated.\n"
     325        "   <files>         Files to scan. Wildchars are allowed.\n"
    287326        "\n",
    288327        pszDefaultDepFile
Note: See TracChangeset for help on using the changeset viewer.