VirtualBox

Changeset 41630 in vbox


Ignore:
Timestamp:
Jun 8, 2012 5:54:54 PM (13 years ago)
Author:
vboxsync
Message:

filesplitter: optionally produce a list of files for kmk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/filesplitter.cpp

    r41624 r41630  
    3030
    3131
     32/*******************************************************************************
     33*   Defined Constants And Macros                                               *
     34*******************************************************************************/
     35#ifndef S_ISDIR
     36# define S_ISDIR(a_fMode)       ( (S_IFMT & (a_fMode)) == S_IFDIR )
     37#endif
     38
     39
    3240/**
    3341 * Calculates the line number for a file position.
     
    7179
    7280    return RTEXITCODE_FAILURE;
     81}
     82
     83
     84/**
     85 * Opens the makefile list for writing.
     86 * 
     87 * @returns Exit code.
     88 * @param   pcszPath            The path to the file.
     89 * @param   pcszVariableName    The make variable name.
     90 * @param   ppFile              Where to return the file stream.
     91 */
     92static int openMakefileList(const char *pcszPath, const char *pcszVariableName, FILE **ppFile)
     93{
     94    *ppFile = NULL;
     95
     96    FILE *pFile= fopen(pcszPath, "w");
     97    if (!pFile)
     98        return printErr("Failed to open \"%s\" for writing the file list");
     99
     100    if (fprintf(pFile, "%s := \\\n", pcszVariableName) <= 0)
     101    {
     102        fclose(pFile);
     103        return printErr("Error writing to the makefile list.\n");
     104    }
     105
     106    *ppFile = pFile;
     107    return 0;
     108}
     109
     110
     111/**
     112 * Adds the given file to the makefile list.
     113 * 
     114 * @returns Exit code.
     115 * @param   pFile               The file stream of the makefile list.
     116 * @param   pszFilename         The file name to add.
     117 */
     118static int addFileToMakefileList(FILE *pFile, char *pszFilename)
     119{
     120    if (pFile)
     121    {
     122        char *pszSlash = pszFilename;
     123        while ((pszSlash = strchr(pszSlash, '\\')) != NULL)
     124            *pszSlash++ = '/';
     125
     126        if (fprintf(pFile, "\t%s \\\n", pszFilename) <= 0)
     127            return printErr("Error adding file to makefile list.\n");
     128    }
     129    return 0;
     130}
     131
     132
     133/**
     134 * Closes the makefile list.
     135 * 
     136 * @returns Exit code derived from @a rc.
     137 * @param   pFile               The file stream of the makefile list.
     138 * @param   rc                  The current exit code.
     139 */
     140static int closeMakefileList(FILE *pFile, int rc)
     141{
     142    fprintf(pFile, "\n\n");
     143    if (fclose(pFile))
     144        return printErr("Error closing the file list file: %s\n", strerror(errno));
     145    return rc;
    73146}
    74147
     
    189262 * @returns exit code.
    190263 * @param   pcszOutDir      Path to the output directory.
    191  * @param   pcszContent     The content to split up.
    192  */
    193 static int splitFile(const char *pcszOutDir, const char *pcszContent)
     264 * @param   pcszContent     The content to split up.
     265 * @param   pFileList       The file stream of the makefile list.  Can be NULL.
     266 */
     267static int splitFile(const char *pcszOutDir, const char *pcszContent, FILE *pFileList)
    194268{
    195269    static char const   s_szBeginMarker[] = "\n// ##### BEGINFILE \"";
     
    248322        }
    249323
     324        if (!rc)
     325            rc = addFileToMakefileList(pFileList, pszFilename);
     326
    250327        free(pszFilename);
    251328
     
    263340    int rc = 0;
    264341
    265     if (argc == 3)
     342    if (argc == 3 || argc == 5)
    266343    {
    267344        struct stat DirStat;
    268         if (stat(argv[2], &DirStat) == 0
     345        if (   stat(argv[2], &DirStat) == 0
    269346            && S_ISDIR(DirStat.st_mode))
    270347        {
     
    273350            if (!rc)
    274351            {
    275                 rc = splitFile(argv[2], pszContent);
     352                FILE *pFileList = NULL;
     353                if (argc == 5)
     354                    rc = openMakefileList(argv[3], argv[4], &pFileList);
     355
     356                if (argc < 4 || pFileList)
     357                    rc = splitFile(argv[2], pszContent, pFileList);
     358
     359                if (pFileList)
     360                    rc = closeMakefileList(pFileList, rc);
    276361                free(pszContent);
    277362            }
     
    281366    }
    282367    else
    283         rc = printErr("Must be started with exactly two arguments,\n"
    284                       "1) the input file and 2) the directory where to put the output files\n");
    285     return rc;
    286 }
     368        rc = printErr("Syntax error: usage: filesplitter <infile> <outdir> [<list.kmk> <kmkvar>]\n");
     369    return rc;
     370}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette