logological / gpp

GPP, a generic preprocessor
https://logological.org/gpp
GNU Lesser General Public License v3.0
192 stars 33 forks source link

Add files via upload #32

Closed duncanmac99 closed 2 years ago

duncanmac99 commented 5 years ago

Proposed fixes for Issue #5 (checking results of '*alloc' fcns) as well as a number of other fixes. Also included: a list of proposed changes affecting command line args [attached to 'usage()'].

logological commented 5 years ago

@duncanmac99, the diff is showing changes to every line of gpp.c. Could this be because you changed the line-ending characters in the file? Could you submit a patch such that I can see only the parts you've changed?

duncanmac99 commented 5 years ago

This Diff shows what I understood to have changed. I hope this clarifies the situation.

/media/duncan/PRODR_DAM_B/General/Music/Temp/gpp_c.diff

duncanmac99 commented 5 years ago

22d21 < / To compile under MS VC++, one must define WIN_NT / 26a26

/ To compile under MS VC++, one must define WIN_NT / 34c34,38 < #else / UNIX settings /

ifndef DFT_SYS_INCL_DIR

define DFT_SYS_INCL_DIR "C:\usr\include" / a pro-tem definition /

endif

else / UNIX & Linux settings /

36a41,44

ifndef DFT_SYS_INCL_DIR

define DFT_SYS_INCL_DIR "/usr/include"

endif

42a51

48,50c57,66 < #define STACKDEPTH 50 < #define MAXARGS 100 < #define MAXINCL 128 / max # of include dirs /

/ recursion depth for macros /

define STACKDEPTH 50

define MAXARGS 100

define INIT_EXP_NUM_MACROS 31

define INIT_LINESIZE 80

/ max # of include dirs /

ifndef MAX_INCL_DIRS

define MAX_INCL_DIRS 128

endif

52,53c68,69 < #define MAX_GPP_NUM_SIZE 15 < #define MAX_GPP_DATE_SIZE 1024

define MAX_GPP_NUM_SIZE 15

define MAX_GPP_DATE_SIZE 1024

55c71 < typedef struct MODE {

typedef struct MODE_ { 80,87c96,103 < / st end args sep arge ref quot stk unstk/ < struct MODE CUser = {"", "", "(", ",", ")", "#", '\', "(", ")" }; < struct MODE CMeta = {"#", "\n", "\001","\001","\n","#", '\', "(", ")" }; < struct MODE KUser = {"", "", "(", ",", ")", "#", 0, "(", ")" }; < struct MODE KMeta = {"\n#\002","\n", "\001","\001","\n","#", 0, "", "" }; < struct MODE Tex = {"\", "", "{", "}{", "}", "#", '@', "{", "}" }; < struct MODE Html = {"<#", ">", "\003","|", ">", "#", '\', "<", ">" }; < struct MODE XHtml = {"<#", "/>", "\003","|", "/>","#", '\', "<", ">" };

/ st end args sep arge ref quot stk unstk/ MODE CUser = {"", "", "(", ",", ")", "#", '\', "(", ")" }; MODE CMeta = {"#", "\n", "\001","\001","\n","#", '\', "(", ")" }; MODE KUser = {"", "", "(", ",", ")", "#", 0, "(", ")" }; MODE KMeta = {"\n#\002","\n", "\001","\001","\n","#", 0, "", "" }; MODE Tex = {"\", "", "{", "}{", "}", "#", '@', "{", "}" }; MODE Html = {"<#", ">", "\003","|", ">", "#", '\', "<", ">" }; MODE XHtml = {"<#", "/>", "\003","|", "/>","#", '\', "<", ">" }; 101c117 < typedef struct COMMENT {

typedef struct COMMENT_ { 107c123 < struct COMMENT *next;

struct COMMENT_ *next;

149,152c165,168 < typedef struct SPECS { < struct MODE User, Meta; < struct COMMENT comments; < struct SPECS stack_next;

typedef struct SPECS { MODE User, Meta; COMMENT *comments; struct SPECS stack_next; 157c173 < struct SPECS S;

SPECS *S; 159c175 < typedef struct MACRO {

typedef struct MACRODESC { 162c178 < struct SPECS *define_specs;

SPECS *define_specs;

166c182 < struct MACRO *macros;

MACRO macros; 168c184 < char includedir[MAXINCL];

char *includedir[MAX_INCL_DIRS]; 172a189

182a200 / if the file is delimited with "<>", the current directory ^should^ be last / 189c207 < typedef struct OUTPUTCONTEXT {

typedef struct OUTPUTCONTEXT_ { 195c213 < typedef struct INPUTCONTEXT {

typedef struct INPUTCONTEXT_ { 205c223 < struct OUTPUTCONTEXT *out;

OUTPUTCONTEXT *out;

212c230 < struct INPUTCONTEXT *C;

INPUTCONTEXT *C; 244c262,264 < ** versions in case the compiler does not support them

versions in case the compiler does not support them. No checking is done on the malloc call here, as this code won't be used ** if the local library has a copy. 247a268

251c272 < return newstr ? (char *) memcpy(newstr, s, len) : NULL ;

return (newstr!=NULL) ? (char *) memcpy(newstr, s, len) : NULL ;

256a278

273a296,297 / this only works if the global 'C' (an INPUTCONTEXT object) is defined / / it should be defined by the time text processing starts, fortunately / 283,285c307,309 < struct SPECS CloneSpecs(const struct SPECS Q) { < struct SPECS P; < struct COMMENT x, *y;

SPECS CloneSpecs(const SPECS Q) { SPECS P; COMMENT x, *y; 289,290c313,315 < bug("Out of memory."); < memcpy(P, Q, sizeof(struct SPECS));

    bug("Out of memory for copying specs");

memcpy(P, Q, sizeof(SPECS));

292c317 < if (Q->comments != NULL )

if (Q->comments != NULL ) {

293a319,322 if (P->comments == NULL) bug("Out of memory for copying first attached comment-strings block"); }

296c325,326 < memcpy(y, x, sizeof(struct COMMENT));

    memcpy(y, x, sizeof(COMMENT));

299c329,332 < if (x->next != NULL )

    if ((y->start==NULL) || (y->end==NULL))
        bug("Out of memory for copying attached individual comment-string");

    if (x->next != NULL ) {

300a334,336 if (y->next == NULL) bug("Out of memory for copying next attached comment-strings block"); } 305,306c341,342 < void FreeComments(struct SPECS Q) { < struct COMMENT p;

void FreeComments(SPECS Q) { COMMENT p; 317,318c353,354 < void PushSpecs(const struct SPECS X) { < struct SPECS P;

void PushSpecs(const SPECS X) { SPECS P; 326c362 < struct SPECS *P;

SPECS *P;

344a381,397 / future proposed changes to command-line args: / / change '-x' to '+xx' (to enable "#exec") / / add '-xm' (to turn off "#mode", which would remain ON by default) / / [because "#mode" can enable major changes in syntax, it is desirable to add the ability to turn it off] / / add '-xxs' and '-xms' (to turn off "#exec" and "#mode" only in standard/system #include-d files) / / add '-aiCHARS (for input format; to hint at what text format the files in following directory/ies contain) / / [where CHARS is one of: 'U8' [UTF-8], 'U16' [UTF-16], 'U16L', 'U16B', or 'CPnnnn' (a Windows "code page")] / / (we can't use "iconv(1)" on #include-d files; what happens if an UTF-16 file #include-s a 'CP1252' one?) / / (use of "iconv(3)" also won't work, if we don't use 'glibc'; separately licenced one under incompatible licence) / / add '-aoCHARS' (for output format; list of allowable CHARS here should be Much Shorter) / / add '--allowlonesurr' (to allow cases where surrogate values appear alone, which breaks Unicode rules) / / add '--sysincdir' (to specify a "system" directory for finding standard includes) / / add '--rootprefix' (to supply a prefix-ed PATH to add to '-I=' arguments [for #28]) / / add '+Ksym' and '-Ksym' (see #29 for details; should also fix #27 first) / / add '--listheaders' (corr to "cpp" '-H' option, list all #include-d header files) / / add '--makegener' (generate list in Make format, see #24, corr to "cpp" '-M') / / add '--makeoutput' and '--maketarget' (corr to "cpp" '-MF' and '-MT') / 377c430 < if (c >= 128)

if (c >= 128) /* needs to be re-considered if UTF-8 (multi-byte) chars involved */

405c458 < bug("Out of memory");

        bug("Out of memory for new macro(s)");

407c460,461 < macros[nmacros].username = malloc(len + 1);

if ( (macros[nmacros].username = malloc(len + 1)) == NULL)
    bug("Out of memory for new macro(s)");

409c463 < macros[nmacros].username[len] = 0;

macros[nmacros].username[len] = '\0';

442c496,498 < t = malloc(strlen(s) + 1);

if ( (t = malloc(strlen(s) + 1)) == NULL)
    bug("Out of memory");

443a500

461,462c518 < t = malloc(strlen(s) + 1); < u = t;

464a521,524 if ( (t = malloc(strlen(s) + 1)) == NULL) bug("Out of memory"); u = t;

483c543 < bug("\w and \W cannot be negated");

                bug("\\w and \\W cannot be negated"); /* should this be a "warning"? */

491c551 < bug("\w and \W cannot be negated");

                bug("\\w and \\W cannot be negated"); /* should this be a "warning"? */

555c615 < bug("\w and \W cannot be negated");

                bug("\\w and \\W cannot be negated"); /* should this be a "warning"? */

563c623 < bug("\w and \W cannot be negated");

                bug("\\w and \\W cannot be negated"); /* should this be a "warning"? */

601c661 < bug("unterminated string in #mode command");

        bug("non-terminated string in #mode command");

633a694,696 / since the INPUTCONTEXT may be undefined when parsing the command line, avoid 'bug()' / / instead, use this /

define OPT_BUG(s) { fprintf(stderr, "gpp: Error during Command-line parse: %s\n", (s)); exit(EXIT_FAILURE); }

636a700

651a716

653c718 < bug("invalid syntax in -D declaration");

            OPT_BUG("invalid syntax in -D declaration");

657a723,725 if (macros[nmacros].argnames == NULL) OPT_BUG("out of memory for args of current macro");

659c727,728 < macros[nmacros].argnames[argc - 1] = malloc(i - l + 1);

            if ( (macros[nmacros].argnames[argc - 1] = malloc(i - l + 1)) == NULL)
                OPT_BUG("out of memory for arg(s) of current macro");

674c743,744 < bug("invalid syntax in -D declaration");

    OPT_BUG("invalid syntax in -D declaration");

676c746,749 < macros[nmacros++].macrotext = my_strdup(s + l);

macros[nmacros].macrotext = my_strdup(s + l);
if (macros[nmacros].macrotext == NULL)
    OPT_BUG("out of memory for text of current macro");
nmacros++;

679c752 < int readModeDescription(char *args, struct MODE mode, int ismeta) {

int readModeDescription(char *args, MODE mode, int ismeta) { 730,731c803 < bug("Invalid comment/string modifier"); < return 0;

    bug("invalid comment or string modifier"); /* should this be a warning? */

735c807 < void add_comment(struct SPECS S, const char specif, char start, char end,

void add_comment(SPECS S, const char specif, char start, char end, 737c809 < struct COMMENT *p;

COMMENT *p;

738a811,812 if ( (start==NULL) || (end==NULL) || (specif==NULL) ) bug("No string passed for start, end or specifier string (perhaps a copy failed)"); 740,741c814,817 < bug("Comment/string start delimiter must be non-empty"); < for (p = S->comments; p != NULL ; p = p->next)

    bug("Comment or string start delimiter must be non-empty");
if (strlen(specif) != 3)
    bug("Invalid comment or string modifier");
for (p = S->comments; p != NULL ; p = p->next) {

744c820,821 < bug("Conflicting comment/string delimiter specifications");

            bug("Conflicting (comment or string) delimiter specifications");
        /* found a match */

748a826 } 750,751c828,831 < if (p == NULL ) { < p = malloc(sizeof *p);

/* No match for this comment or string?  Create a new one */
if (p == NULL) {
    if ( (p=malloc(sizeof *p)) == NULL)
        bug("Out of memory for new comment or string");

759,760d838 < if (strlen(specif) != 3) < bug("Invalid comment/string modifier"); 766,767c844,845 < void delete_comment(struct SPECS S, char start) { < struct COMMENT p, q;

void delete_comment(SPECS S, char start) { COMMENT p, q; 768a847,848 if (start == NULL) bug("Out of memory for start string"); 769a850

772c853 < if (q == NULL )

        if (q == NULL)

789,792c870,872 < if (C->out->len + 1 == C->out->bufsize) { < C->out->bufsize = C->out->bufsize * 2; < C->out->buf = realloc(C->out->buf, C->out->bufsize); < if (C->out->buf == NULL )

    if (C->out->len + 1 >= C->out->bufsize) {
        C->out->bufsize = (C->out->bufsize * 2) + 1;
        if ( (C->out->buf = realloc(C->out->buf, C->out->bufsize)) == NULL)

829a910

832a914,916 if (p == NULL) bug("Out of memory extending main buffer");

836,837d919 < if (C->buf == NULL ) < bug("Out of memory"); 1073c1155,1156 < x = malloc(CHARSET_SUBSET_LEN * sizeof(unsigned long));

if ( (x = malloc(CHARSET_SUBSET_LEN * sizeof(unsigned long))) == NULL)
    bug("Out of memory for char-set check");

1079,1080c1162,1163 < bug( < "negated special sequences not allowed in charset specifications");

            bug("negated special sequences not allowed in charset specifications");

1193c1276 < nalloced = 31;

nalloced = INIT_EXP_NUM_MACROS;

1194a1278,1279 if (macros == NULL) OPT_BUG("Out of memory for first macros"); 1196a1282,1284 if (S == NULL) OPT_BUG("Out of memory for first macro-specs");

1206a1295,1297 if (C == NULL) OPT_BUG("Out of memory for input context");

1210,1211c1301,1305 < C->filename = my_strdup("stdin"); < C->out = malloc(sizeof *(C->out));

if ( (C->filename = my_strdup("stdin")) == NULL)
    OPT_BUG("Out of memory for input filename ref");

if ( (C->out = malloc(sizeof *(C->out))) == NULL)
    OPT_BUG("Out of memory for output context");

1214c1308 < C->lineno = 1;

C->lineno = 1; /* should really be zero, at the beginning */

1217c1311 < C->bufsize = 80;

C->bufsize = INIT_LINESIZE;

1218a1313

1219a1315,1317 if (C->buf == NULL) OPT_BUG("Out of memory for main input text buffer");

1230a1329,1330

define OPT_SYNTAX_ERR { fprintf(stderr, "gpp: Command-line syntax error\n\n"); usage(); exit(EXIT_FAILURE); }

define DEPRECATED_WARNING fprintf(stderr, "gpp: warning: deprecated option %s'; use-%s' instead\n", arg, arg)

1240d1339 < #define DEPRECATED_WARNING fprintf(stderr, "gpp: warning: deprecated option %s'; use-%s' instead\n", arg, arg) 1259,1262c1358,1360 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

        if (!(*(++arg)))
            OPT_SYNTAX_ERR;

1267,1270c1365,1366 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

        if (!(*(++arg)))
            OPT_SYNTAX_ERR;

1276,1279c1372,1373 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

        if (!(*(++arg)))
            OPT_SYNTAX_ERR;

1297,1300c1391,1392 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

        if (!(*(++arg)))
            OPT_SYNTAX_ERR;

1305,1308c1397,1398 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

        if (!(*(++arg)))
            OPT_SYNTAX_ERR;

1319,1326c1409,1412 < if (!((++arg))) { < usage(); < exit(EXIT_FAILURE); < } < if (!((++arg))) { < usage(); < exit(EXIT_FAILURE); < }

            if (!(*(++arg)))
                OPT_SYNTAX_ERR;
            if (!(*(++arg)))
                OPT_SYNTAX_ERR;

1333,1344c1419,1424 < if (!((++arg))) { < usage(); < exit(EXIT_FAILURE); < } < if (!((++arg))) { < usage(); < exit(EXIT_FAILURE); < } < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

            if (!(*(++arg)))
                OPT_SYNTAX_ERR;
            if (!(*(++arg)))
                OPT_SYNTAX_ERR;
            if (!(*(++arg)))
                OPT_SYNTAX_ERR;

1359a1440

1360a1442,1445 if (C->in == NULL) { fprintf(stderr, "Command line error: cannot open input file %s\n", arg); exit(EXIT_FAILURE); } 1362,1365c1447,1449 < C->filename = my_strdup(arg); < if (C->in == NULL ) < bug("Cannot open input file"); < } else

        if ( (C->filename = my_strdup(*arg)) == NULL)
            OPT_BUG("Out of memory to copy input file name");
    } else /* arg does start with '-' => process option(s) */

1368,1369c1452,1453 < if (nincludedirs == MAXINCL) < bug("too many include directories");

            if (nincludedirs >= MAX_INCL_DIRS)
                OPT_BUG("Too many directories to search");

1371,1375c1455,1457 < if (!((++arg))) { < usage(); < exit(EXIT_FAILURE); < } < includedir[nincludedirs++] = my_strdup(arg);

                if (!(*(++arg)))
                    OPT_SYNTAX_ERR;
                includedir[nincludedirs] = my_strdup(*arg);

1377c1459,1463 < includedir[nincludedirs++] = my_strdup((*arg) + 2);

                includedir[nincludedirs] = my_strdup((*arg) + 2);

            if (includedir[nincludedirs] == NULL)
                OPT_BUG("Out of memory to copy directory to search");
            nincludedirs++;

1427,1430c1513,1514 < if (!readModeDescription(arg, &(S->User), 0)) { < usage(); < exit(EXIT_FAILURE); < }

            if (!readModeDescription(arg, &(S->User), 0))
                OPT_SYNTAX_ERR;

1438,1441c1522,1523 < if (!readModeDescription(arg, &(S->Meta), 1)) { < usage(); < exit(EXIT_FAILURE); < }

            if (!readModeDescription(arg, &(S->Meta), 1))
                OPT_SYNTAX_ERR;

1447,1450c1529,1530 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

            if (!(*(++arg)))
                OPT_SYNTAX_ERR;

1455c1535 < bug("Cannot create output file");

                OPT_BUG("Cannot create output file");

1459,1462c1539,1540 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

                if (!(*(++arg)))
                    OPT_SYNTAX_ERR;

1480,1483c1558,1559 < if (!(*(++arg))) { < usage(); < exit(EXIT_FAILURE); < }

            if (!(*(++arg)))
                OPT_SYNTAX_ERR;

1492,1495c1568,1569 < if (hasmeta && !usrmode) { < usage(); < exit(EXIT_FAILURE); < }

    if (hasmeta && !usrmode)
        OPT_SYNTAX_ERR;

1502a1577 / to be fixed later, see #27; the directory should be present no matter what / 1504c1579,1581 < includedir[0] = my_strdup("/usr/include");

    includedir[0] = my_strdup(DFT_SYS_INCL_DIR);
    if (includedir[0] == NULL)
        OPT_BUG("Out of memory for standard search dir ref");

1544c1621 < struct COMMENT *c;

COMMENT *c;

1724c1801 < struct INPUTCONTEXT *T;

INPUTCONTEXT *T;

1727c1804,1805 < s = malloc(1);

    if ( (s = malloc(1)) == NULL)
        bug("Out of memory");

1731c1809,1810 < s = malloc(l + 2);

if ( (s = malloc(l + 2)) == NULL)
    bug("Out of memory");

1734c1813,1814 < s[l + 1] = 0;

s[l + 1] = '\0';

1736,1737c1816,1819 < C = malloc(sizeof C); < C->out = malloc(sizeof (C->out));

if ( (C = malloc(sizeof *C)) == NULL)
    bug("Out of memory for input context copy");
if ( (C->out = malloc(sizeof *(C->out))) == NULL)
    bug("Out of memory for output context copy");

1742c1824,1825 < C->out->buf = malloc(80);

if ( (C->out->buf = malloc(INIT_LINESIZE)) == NULL)
    bug("Out of memory for output context buffer copy");

1744c1827 < C->out->bufsize = 80;

C->out->bufsize = INIT_LINESIZE;

1877c1960 < bug("globbing support has not been compiled in");

    bug("support for 'glob' match has not been compiled in");

1888c1971,1974 < str1 = strdup(buf + pos1);

        str1 = my_strdup(buf + pos1);
        str2 = my_strdup(buf + spl2);
        if ((str1==NULL) || (str2==NULL))
            bug("Out of memory to copy 'fnmatch' operands");

1890d1975 < str2 = strdup(buf + spl2); 2076c2161 < memcpy(macros + i, macros + nmacros, sizeof(struct MACRO));

memcpy(macros + i, macros + nmacros, sizeof(MACRO));

2090c2175,2176 < macros[nmacros].macrotext = malloc(1);

    if ( (macros[nmacros].macrotext = malloc(1)) == NULL)
        bug("Out of memory");

2096a2183

2108,2109c2195,2197 < t = malloc(MAX_GPP_NUM_SIZE); < sprintf(t, "%d", i);

if ( (t = malloc(MAX_GPP_NUM_SIZE + 1)) == NULL)
    bug("Out of memory for number value");
sprintf(t, "%d", i); /* check to see if it can be restricted to MAX_GPP_NUM_SIZE */

2131c2219,2221 < t = s = malloc(end - start + 1);

if ( (t = s = malloc(end - start + 1)) == NULL)
    bug("Out of memory for comment or string");

2146c2236 < void SetStandardMode(struct SPECS P, const char opt) {

void SetStandardMode(SPECS P, const char opt) { 2189a2280,2281 / in these cases, consideration should be given to making some of these warnings, / / rather than (fatal) bugs / 2191c2283 < struct SPECS *P;

SPECS *P;

2202a2295,2296 if (s == NULL) bug("Out of memory for second arg"); 2282,2291c2376,2392 < if ((opt != NULL )||(nargs!=9))bug("#mode user requires 9 arguments"); < S->stack_next->User.mStart=my_strdup(args[0]); < S->stack_next->User.mEnd=my_strdup(args[1]); < S->stack_next->User.mArgS=my_strdup(args[2]); < S->stack_next->User.mArgSep=my_strdup(args[3]); < S->stack_next->User.mArgE=my_strdup(args[4]); < S->stack_next->User.stackchar=my_strdup(args[5]); < S->stack_next->User.unstackchar=my_strdup(args[6]); < S->stack_next->User.mArgRef=my_strdup(args[7]); < S->stack_next->User.quotechar=args[8][0];

    MODE *mCurr = &(S->stack_next->User);

    if ((opt != NULL ) || (nargs!=9))
        bug("#mode user requires 9 arguments");
    mCurr->mStart=my_strdup(args[0]);
    mCurr->mEnd=my_strdup(args[1]);
    mCurr->mArgS=my_strdup(args[2]);
    mCurr->mArgSep=my_strdup(args[3]);
    mCurr->mArgE=my_strdup(args[4]);
    mCurr->stackchar=my_strdup(args[5]);
    mCurr->unstackchar=my_strdup(args[6]);
    mCurr->mArgRef=my_strdup(args[7]);
    mCurr->quotechar=args[8][0];
    if ((mCurr->mStart==NULL) || (mCurr->mEnd==NULL) || (mCurr->mArgS==NULL) || (mCurr->mArgSep==NULL)
      || (mCurr->mArgE==NULL) || (mCurr->mArgRef==NULL) || (mCurr->stackchar==NULL)
      || (mCurr->unstackchar==NULL))
        bug("Out of memory to copy #mode user args");

2295c2396 < S->stack_next->Meta=S->stack_next->User;

        S->stack_next->Meta = S->stack_next->User;

2297,2304c2398,2411 < if ((opt!=NULL)||(nargs!=7)) bug("#mode meta requires 7 arguments"); < S->stack_next->Meta.mStart=my_strdup(args[0]); < S->stack_next->Meta.mEnd=my_strdup(args[1]); < S->stack_next->Meta.mArgS=my_strdup(args[2]); < S->stack_next->Meta.mArgSep=my_strdup(args[3]); < S->stack_next->Meta.mArgE=my_strdup(args[4]); < S->stack_next->Meta.stackchar=my_strdup(args[5]); < S->stack_next->Meta.unstackchar=my_strdup(args[6]);

        MODE *mCurr = &(S->stack_next->Meta);

        if ((opt!=NULL) || (nargs!=7))
            bug("#mode meta requires 7 arguments");
        mCurr->mStart=my_strdup(args[0]);
        mCurr->mEnd=my_strdup(args[1]);
        mCurr->mArgS=my_strdup(args[2]);
        mCurr->mArgSep=my_strdup(args[3]);
        mCurr->mArgE=my_strdup(args[4]);
        mCurr->stackchar=my_strdup(args[5]);
        mCurr->unstackchar=my_strdup(args[6]);
        if ((mCurr->mStart==NULL) || (mCurr->mEnd==NULL) || (mCurr->mArgS==NULL) || (mCurr->mArgSep==NULL)
          || (mCurr->mArgE==NULL) || (mCurr->stackchar==NULL) || (mCurr->unstackchar==NULL))
            bug("Out of memory to copy #mode meta args");

2323c2430 < S->stack_next->op_set=MakeCharsetSubset((unsigned char *)args[0]);

        S->stack_next->op_set=MakeCharsetSubset((unsigned char *)args[0]);

2325c2432 < S->stack_next->ext_op_set=MakeCharsetSubset((unsigned char *)args[0]);

        S->stack_next->ext_op_set=MakeCharsetSubset((unsigned char *)args[0]);

2327c2434 < S->stack_next->id_set=MakeCharsetSubset((unsigned char *)args[0]);

        S->stack_next->id_set=MakeCharsetSubset((unsigned char *)args[0]);

2336c2443 < struct INPUTCONTEXT *N;

INPUTCONTEXT *N;

2340c2447 < int len = strlen(file_name);

int len1 = strlen(file_name);

2354,2362c2461,2474 < for (j = 0; (f == NULL )&&(j<nincludedirs);j++){ < incfile_name = < realloc(incfile_name,len+strlen(includedir[j])+2); < strcpy(incfile_name,includedir[j]); < incfile_name[strlen(includedir[j])]=SLASH; < / extract the orig include filename / < strcpy(incfile_name+strlen(includedir[j])+1, file_name); < f=fopen(incfile_name,"r"); < }

for (j = 0; (f == NULL) && (j<nincludedirs);j++) {
    int len2 = strlen(includedir[j]);

    /* 'realloc()' used, as generated name's length changes each time thru */
    if ( (incfile_name = realloc(incfile_name,len1+len2+2)) == NULL)
        bug("Out of memory for new file's name");
    strncpy(incfile_name, includedir[j], len2);
    incfile_name[len2] = SLASH;

    /* extract the orig include filename, and append */
    strncpy(incfile_name+len2+1, file_name, len1);
    incfile_name[len2+1+len1] = '\0';
    f=fopen(incfile_name,"r");
}

2375c2487,2488 < C = malloc(sizeof *C);

if ( (C = malloc(sizeof *C)) == NULL)
    bug("Out of memory for input context copy");

2384c2497,2498 < C->buf = C->malloced_buf = malloc(C->bufsize);

if ( (C->buf = C->malloced_buf = malloc(C->bufsize)) == NULL)
    bug("Out of memory for input buffer");

2390a2505

2399a2515

2539a2656,2657 if (macros[nmacros].argnames == NULL) bug("Out of memory"); 2545,2546c2663 < bug( < "#define with named args needs identifiers as arg names");

                bug("#define with named args needs identifiers as arg names");

2547a2665,2666 if (macros[nmacros].argnames[j] == NULL) bug("Out of memory"); 2633c2752 < / user may put "" or <> /

        /* user may put "" or <> (or other framing chars) */

2641c2760,2762 < incfile_name = malloc(p1end - p1start + 1);

        if ( (incfile_name = malloc(p1end - p1start + 1)) == NULL)
            bug("Out of memory for file name to #include");

2655,2656c2776 < warning( < "Not allowed to #exec. Command output will be left blank");

            warning("Not allowed to #exec. Command output will be left blank");

2660a2781

2665,2666c2786,2788 < i = strlen(s); < s = realloc(s, i + strlen(t) + 2);

                i = strlen(s);    j = strlen(t);
                if ( (s = realloc(s, i + j + 2)) == NULL)
                    bug("Out of memory");

2668c2790,2791 < strcpy(s + i + 1, t);

                strncpy(s + i + 1, t, j);
                s[i+1+j] = '\0';

2709c2832,2833 < macros[nmacros].argnames = malloc((argc + 1) sizeof(char ));

            if ( (macros[nmacros].argnames = malloc((argc + 1) * sizeof(char *))) == NULL)
                bug("Out of memory for macro arg");

2717c2841,2842 < macros[nmacros].argnames[j] = malloc(arge[j] - argb[j] + 1);

            if ( (macros[nmacros].argnames[j] = malloc(arge[j] - argb[j] + 1)) == NULL)
                bug("Out of memory for macro arg");

2875c3000 < int argc, id, i, l;

int argc, id, i, j, l;

2878c3003 < struct INPUTCONTEXT *T;

INPUTCONTEXT *T;

2933c3058,3059 < C = malloc(sizeof *C);

if ( (C = malloc(sizeof *C)) == NULL)
    bug("Out of memory for input context");

2950c3076,3077 < C->buf = C->malloced_buf = malloc(l);

    if ( (C->buf = C->malloced_buf = malloc(l)) == NULL)
        bug("Out of memory");

2953,2954c3080,3081 < strcpy(C->buf + 1, macros[id].macrotext); < while ((l > 1) && isWhite(C->buf[l - 1]))

    strncpy(C->buf + 1, macros[id].macrotext, l);
    while ((l > 1) && isWhite(C->buf[l - 1])) /* strip trailing whitespace */

2956c3083,3085 < strcpy(C->buf + l, macros[id].define_specs->User.mArgS);

    j = strlen(macros[id].define_specs->User.mArgS);
    strncpy(C->buf + 1 + l, macros[id].define_specs->User.mArgS, j);
    C->buf[1 + l + j] = '\0';

2965c3094,3095 < C->buf = C->malloced_buf = malloc(strlen(macros[id].macrotext) + 2);

    if ( (C->buf = C->malloced_buf = malloc(strlen(macros[id].macrotext) + 2)) == NULL)
        bug("Out of memory for input buffer");

2990c3120 < struct COMMENT *p;

COMMENT *p;

3080a3211 char absfile = calloc(strlen(C->filename) + strlen(incfile) + 1, 1); 3082d3212 < char absfile; 3084,3088c3214,3215 < if (IncludeFile) { < return fopen(incfile, "r"); < } < < absfile = calloc(strlen(C->filename) + strlen(incfile) + 1, 1);

if (absfile == NULL)
    bug("Out of memory for local file name");

3100,3102c3227,3231 < while (start <= end) { < if (*start == '\n') { < if (skip) skip--; else fprintf(C->out->f,"\n");

    while (start <= end) {
        if (*start == '\n') {
            if (skip) skip--; else fprintf(C->out->f,"\n");
        }
        start++;

3104d3232 < start++; 3107d3234 < } 3115,3116c3242,3243 < fprintf(f,"\n"); < }

    fprintf(f,"\n");
}

3144c3271,3272 < outstr = malloc(2 strlen(instr));

if ( (*outstr = malloc(2 * strlen(instr))) == NULL)
    bug("Out of memory for file-rebuilding");

3170c3298,3299 < *include_directive_marker = malloc(len + 18);

if ( (*include_directive_marker = malloc(len + 18)) == NULL)
    bug("Out of memory for directive marker");

3194c3323 < bug("only 3 substitutions allowed in -includemarker");

                bug("only 3 substitutions allowed in --includemarker");

3216d3344 < IncludeFile = NULL;