VirtualBox

Changeset 63498 in vbox


Ignore:
Timestamp:
Aug 15, 2016 8:41:37 PM (8 years ago)
Author:
vboxsync
Message:

Better way of dealing with unused sizes in bin2c output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/bin2c.c

    r62537 r63498  
    5353    fprintf(stderr,
    5454            "Syntax: %s [options] <arrayname> <binaryfile> <outname>\n"
    55             "  -min <n>     check if <binaryfile> is not smaller than <n>KB\n"
    56             "  -max <n>     check if <binaryfile> is not bigger than <n>KB\n"
    57             "  -mask <n>    check if size of binaryfile is <n>-aligned\n"
    58             "  -width <n>   number of bytes per line (default: 16)\n"
    59             "  -break <n>   break every <n> lines    (default: -1)\n"
    60             "  -ascii       show ASCII representation of binary as comment\n"
    61             "  -export      emit DECLEXPORT\n"
     55            "  --min <n>    check if <binaryfile> is not smaller than <n>KB\n"
     56            "  --max <n>    check if <binaryfile> is not bigger than <n>KB\n"
     57            "  --mask <n>   check if size of binaryfile is <n>-aligned\n"
     58            "  --width <n>  number of bytes per line (default: 16)\n"
     59            "  --break <n>  break every <n> lines    (default: -1)\n"
     60            "  --ascii      show ASCII representation of binary as comment\n"
     61            "  --export     emit DECLEXPORT\n"
    6262            "  --append     append to the output file (default: truncate)\n"
     63            "  --no-size    Skip the size.\n"
     64            "  --static     Static data scope.\n"
    6365            , argv0);
    6466
     
    7779    int           fAppend = 0;
    7880    int           fExport = 0;
     81    int           fNoSize = 0;
     82    int           fStatic = 0;
    7983    long          iBreakEvery = -1;
    8084    unsigned char abLine[32];
     
    9094    for (iArg = 1; iArg < argc; iArg++)
    9195    {
    92         if (!strcmp(argv[iArg], "-min"))
     96        if (!strcmp(argv[iArg], "--min") || !strcmp(argv[iArg], "-min"))
    9397        {
    9498            if (++iArg >= argc)
     
    96100            cbMin = 1024 * strtoul(argv[iArg], NULL, 0);
    97101        }
    98         else if (!strcmp(argv[iArg], "-max"))
     102        else if (!strcmp(argv[iArg], "--max") || !strcmp(argv[iArg], "-max"))
    99103        {
    100104            if (++iArg >= argc)
     
    102106            cbMax = 1024 * strtoul(argv[iArg], NULL, 0);
    103107        }
    104         else if (!strcmp(argv[iArg], "-mask"))
     108        else if (!strcmp(argv[iArg], "--mask") || !strcmp(argv[iArg], "-mask"))
    105109        {
    106110            if (++iArg >= argc)
     
    108112            uMask = strtoul(argv[iArg], NULL, 0);
    109113        }
    110         else if (!strcmp(argv[iArg], "-ascii"))
     114        else if (!strcmp(argv[iArg], "--ascii") || !strcmp(argv[iArg], "-ascii"))
    111115            fAscii = 1;
    112116        else if (!strcmp(argv[iArg], "--append"))
    113117            fAppend = 1;
    114         else if (!strcmp(argv[iArg], "-export"))
     118        else if (!strcmp(argv[iArg], "--export") || !strcmp(argv[iArg], "-export"))
    115119            fExport = 1;
    116         else if (!strcmp(argv[iArg], "-width"))
     120        else if (!strcmp(argv[iArg], "--no-size"))
     121            fNoSize = 1;
     122        else if (!strcmp(argv[iArg], "--static"))
     123            fStatic = 1;
     124        else if (!strcmp(argv[iArg], "--width") || !strcmp(argv[iArg], "-width"))
    117125        {
    118126            if (++iArg >= argc)
     
    126134            }
    127135        }
    128         else if (!strcmp(argv[iArg], "-break"))
     136        else if (!strcmp(argv[iArg], "--break") || !strcmp(argv[iArg], "-break"))
    129137        {
    130138            if (++iArg >= argc)
     
    176184           "%sconst unsigned char%s g_ab%s[] =\n"
    177185           "{\n",
    178            argv[iArg+1], argv[0], fExport ? "DECLEXPORT(" : "", fExport ? ")" : "", argv[iArg]);
     186           argv[iArg+1], argv[0], fStatic ? "static " : fExport ? "DECLEXPORT(" : "", !fStatic && fExport ? ")" : "", argv[iArg]);
    179187
    180188    /* check size restrictions */
     
    227235            /* no errors, finish the structure. */
    228236            fprintf(pFileOut,
    229                     "};\n"
    230                     "\n"
    231                     "%sconst unsigned%s g_cb%s = sizeof(g_ab%s);\n"
    232                     "/* end of file */\n",
    233                     fExport ? "DECLEXPORT(" : "", fExport ? ")" : "", argv[iArg], argv[iArg]);
     237                    "};\n");
     238
     239            if (!fNoSize)
     240                fprintf(pFileOut,
     241                        "\n"
     242                        "%sconst unsigned%s g_cb%s = sizeof(g_ab%s);\n",
     243                        fExport ? "DECLEXPORT(" : "", fExport ? ")" : "", argv[iArg], argv[iArg]);
     244
     245            fprintf(pFileOut, "/* end of file */\n");
    234246
    235247            /* flush output and check for error. */
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