Ignore:
Timestamp:
Mar 26, 2018, 10:25:56 PM (7 years ago)
Author:
bird
Message:

kmkbuiltin: funnel output thru output.c (usually via err.c).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/append.c

    r3177 r3192  
    2424 */
    2525
    26 /*******************************************************************************
    27 *   Header Files                                                               *
    28 *******************************************************************************/
    29 #ifndef kmk_builtin_append
     26/*********************************************************************************************************************************
     27*   Header Files                                                                                                                 *
     28*********************************************************************************************************************************/
     29#ifndef KMK_BUILTIN_STANDALONE
    3030# include "makeint.h"
    3131# include "filedef.h"
     
    4646# include <alloca.h>
    4747#endif
    48 #if !defined(kmk_builtin_append) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
     48#if !defined(KMK_BUILTIN_STANDALONE) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
    4949# include "../w32/winchildren.h"
    5050#endif
     
    173173 * Appends text to a textfile, creating the textfile if necessary.
    174174 */
    175 #ifndef kmk_builtin_append
    176 int kmk_builtin_append(int argc, char **argv, char **envp, struct child *pChild, pid_t *pPidSpawned)
    177 #else
    178 int main(int argc, char **argv, char **envp)
    179 #endif
     175int kmk_builtin_append(int argc, char **argv, char **envp, PKMKBUILTINCTX pCtx, struct child *pChild, pid_t *pPidSpawned)
    180176{
    181177#if defined(KBUILD_OS_WINDOWS) || defined(KBUILD_OS_OS2)
     
    195191    int fVariables = 0;
    196192    int fCommands = 0;
    197 #ifndef kmk_builtin_append
     193#ifndef KMK_BUILTIN_STANDALONE
    198194    int fLookForInserts = 0;
    199 #endif
    200 
    201     g_progname = argv[0];
     195#else
     196    (void)pChild; (void)pPidSpawned;
     197#endif
    202198
    203199    /*
     
    221217                        if (fVariables)
    222218                        {
    223                             errx(1, "Option '-c' clashes with '-v'.");
     219                            errx(pCtx, 1, "Option '-c' clashes with '-v'.");
    224220                            return kmk_builtin_append_usage(argv[0], stderr);
    225221                        }
    226 #ifndef kmk_builtin_append
     222#ifndef KMK_BUILTIN_STANDALONE
    227223                        fCommands = 1;
    228224                        break;
    229225#else
    230                         errx(1, "Option '-c' isn't supported in external mode.");
     226                        errx(pCtx, 1, "Option '-c' isn't supported in external mode.");
    231227                        return kmk_builtin_append_usage(argv[0], stderr);
    232228#endif
     
    234230                        if (fVariables)
    235231                        {
    236                             errx(1, "Option '-d' must come before '-v'!");
     232                            errx(pCtx, 1, "Option '-d' must come before '-v'!");
    237233                            return kmk_builtin_append_usage(argv[0], stderr);
    238234                        }
     
    242238                        if (fVariables || fCommands)
    243239                        {
    244                             errx(1, fVariables ? "Option '-i' clashes with '-v'." : "Option '-i' clashes with '-c'.");
     240                            errx(pCtx, 1, fVariables ? "Option '-i' clashes with '-v'." : "Option '-i' clashes with '-c'.");
    245241                            return kmk_builtin_append_usage(argv[0], stderr);
    246242                        }
    247 #ifndef kmk_builtin_append
     243#ifndef KMK_BUILTIN_STANDALONE
    248244                        fLookForInserts = 1;
    249245                        break;
    250246#else
    251                         errx(1, "Option '-C' isn't supported in external mode.");
     247                        errx(pCtx, 1, "Option '-C' isn't supported in external mode.");
    252248                        return kmk_builtin_append_usage(argv[0], stderr);
    253249#endif
     
    264260                        if (fCommands)
    265261                        {
    266                             errx(1, "Option '-v' clashes with '-c'.");
     262                            errx(pCtx, 1, "Option '-v' clashes with '-c'.");
    267263                            return kmk_builtin_append_usage(argv[0], stderr);
    268264                        }
    269 #ifndef kmk_builtin_append
     265#ifndef KMK_BUILTIN_STANDALONE
    270266                        fVariables = 1;
    271267                        break;
    272268#else
    273                         errx(1, "Option '-v' isn't supported in external mode.");
     269                        errx(pCtx, 1, "Option '-v' isn't supported in external mode.");
    274270                        return kmk_builtin_append_usage(argv[0], stderr);
    275271#endif
    276272                    default:
    277                         errx(1, "Invalid option '%c'! (%s)", *psz, argv[i]);
     273                        errx(pCtx, 1, "Invalid option '%c'! (%s)", *psz, argv[i]);
    278274                        return kmk_builtin_append_usage(argv[0], stderr);
    279275                }
     
    300296    {
    301297        if (i <= argc)
    302             errx(1, "missing filename!");
     298            errx(pCtx, 1, "missing filename!");
    303299        else
    304             errx(1, "missing define name!");
     300            errx(pCtx, 1, "missing define name!");
    305301        return kmk_builtin_append_usage(argv[0], stderr);
    306302    }
     
    334330                write_to_buf(&OutBuf, STR_TUPLE(" "));
    335331        }
    336 #ifndef kmk_builtin_append
     332#ifndef KMK_BUILTIN_STANDALONE
    337333        if (fCommands)
    338334        {
     
    417413     * Write the buffer (unless we ran out of heap already).
    418414     */
    419 #if !defined(kmk_builtin_append) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
     415#if !defined(KMK_BUILTIN_STANDALONE) && defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
    420416    if (!OutBuf.fOutOfMemory)
    421417    {
    422418        rc = MkWinChildCreateAppend(pszFilename, &OutBuf.pszBuf, OutBuf.offBuf, fTruncate, pChild, pPidSpawned);
    423419        if (rc != 0)
    424             rc = errx(rc, "MkWinChildCreateAppend failed: %u", rc);
     420            rc = errx(pCtx, rc, "MkWinChildCreateAppend failed: %u", rc);
    425421        if (OutBuf.pszBuf)
    426422            free(OutBuf.pszBuf);
     
    440436                rc = 0;
    441437            else
    442                 rc = err(1, "error writing %lu bytes to '%s'", (unsigned long)OutBuf.offBuf, pszFilename);
     438                rc = err(pCtx, 1, "error writing %lu bytes to '%s'", (unsigned long)OutBuf.offBuf, pszFilename);
    443439            if (close(fd) < 0)
    444                 rc = err(1, "error closing '%s'", pszFilename);
     440                rc = err(pCtx, 1, "error closing '%s'", pszFilename);
    445441        }
    446442        else
    447             rc = err(1, "failed to open '%s'", pszFilename);
     443            rc = err(pCtx, 1, "failed to open '%s'", pszFilename);
    448444        free(OutBuf.pszBuf);
    449445    }
    450446    else
    451         rc = errx(1, "out of memory for output buffer! (%u needed)", OutBuf.offBuf + 1);
     447        rc = errx(pCtx, 1, "out of memory for output buffer! (%u needed)", OutBuf.offBuf + 1);
    452448    return rc;
    453449}
    454450
     451#ifdef KMK_BUILTIN_STANDALONE
     452int main(int argc, char **argv, char **envp)
     453{
     454    KMKBUILTINCTX Ctx = { "kmk_append", NULL };
     455    return kmk_builtin_append(argc, argv, envp, &Ctx, NULL, NULL);
     456}
     457#endif
     458
Note: See TracChangeset for help on using the changeset viewer.