VirtualBox

Changeset 2015 in kBuild


Ignore:
Timestamp:
Nov 1, 2008 10:16:55 PM (16 years ago)
Author:
bird
Message:

kmk_append: added a new option '-N' for suppressing the trailing new line. Fixes #53.

File:
1 edited

Legend:

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

    r1695 r2015  
    11/* $Id$ */
    22/** @file
    3  *
    43 * kMk Builtin command - append text to file.
    5  *
    6  * Copyright (c) 2005-2007 knut st. osmundsen <[email protected]>
    7  *
     4 */
     5
     6/*
     7 * Copyright (c) 2005-2008 knut st. osmundsen <[email protected]>
    88 *
    99 * This file is part of kBuild.
     
    4242{
    4343    fprintf(pf,
    44             "usage: %s [-dcntv] file [string ...]\n"
     44            "usage: %s [-dcnNtv] file [string ...]\n"
    4545            "   or: %s --version\n"
    4646            "   or: %s --help\n"
     
    5151            "  -c  Output the command for specified target(s). [builtin only]\n"
    5252            "  -n  Insert a new line between the strings.\n"
     53            "  -N  Suppress the trailing new line.\n"
    5354            "  -t  Truncate the file instead of appending\n"
    5455            "  -v  Output the value(s) for specified variable(s). [builtin only]\n"
     
    6970    FILE *pFile;
    7071    int fNewLine = 0;
     72    int fNoTrailingNewLine = 0;
    7173    int fTruncate = 0;
    7274    int fDefine = 0;
     
    8385       &&  argv[i][0] == '-'
    8486       &&  argv[i][1] != '\0' /* '-' is a file */
    85        &&  strchr("-cdntv", argv[i][1]) /* valid option char */
     87       &&  strchr("-cdnNtv", argv[i][1]) /* valid option char */
    8688       )
    8789    {
     
    116118                    case 'n':
    117119                        fNewLine = 1;
     120                        break;
     121                    case 'N':
     122                        fNoTrailingNewLine = 1;
    118123                        break;
    119124                    case 't':
     
    222227    }
    223228
    224     /*
    225      * Add the newline, closing the define if needed, and close the file.
    226      */
    227     if (    (  fDefine
    228              ? fwrite(fFirst ?        "endef\n"      :        "\nendef\n",
    229                       1,
    230                       fFirst ? sizeof("endef\n") - 1 : sizeof("\nendef\n") - 1,
    231                       pFile) < sizeof("endef\n")
    232              : fputc('\n', pFile) == EOF)
     229    /*
     230     * End the define?
     231     */
     232    if (fDefine)
     233    {
     234        if (fFirst)
     235            fwrite("\nendef", 1, sizeof("\nendef") - 1, pFile);
     236        else
     237            fwrite("endef", 1, sizeof("endef") - 1, pFile);
     238    }
     239
     240    /*
     241     * Add the final newline (unless supressed) and close the file.
     242     */
     243    if (    (   !fNoTrailingNewLine
     244             && fputc('\n', pFile) == EOF)
    233245        ||  ferror(pFile))
    234246    {
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