Changeset 40 for trunk/src/kmk


Ignore:
Timestamp:
Mar 27, 2003, 3:42:39 AM (22 years ago)
Author:
bird
Message:

Inline files and such.

Location:
trunk/src/kmk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.emx.mak

    r35 r40  
    33
    44CC = gcc
     5#CC = gcc -Zomf
    56CFLAGS = -g -I. -I./include -I../kLib/Generic/include \
    6 #         -DUSE_KLIB \
     7#                -DUSE_KLIB \
     8         -Dregister= \
    79         -DOS2 -D__i386__ -D__32BIT__ -DNMAKE -DMACHINE=\"ibmos2\" -DMACHINE_ARCH=\"x86\" -DMACHINE_CPU=\"386\" \
    810
  • trunk/src/kmk/Makefile.icc.mak

    r35 r40  
    33
    44CC = icc
    5 CFLAGS = /Q /Ti+ /Ss+ /Ge+ /I. /I./include /I../kLib/Generic/include \
     5CFLAGS = /Q /Ti+ /Ss+ /Ge+ /Ig:\ktaskmgr\tree\generic\include\klibcrt /I. /I./include /I../kLib/Generic/include \
    66         -DUSE_KLIB -DOS2 -D__i386__ -D__32BIT__ -DNMAKE=1 -DMACHINE=\"ibmos2\" -DMACHINE_ARCH=\"x86\" -DMACHINE_CPU=\"386\" \
    77
     
    4444$(OBJDIR)\for.obj\
    4545$(OBJDIR)\hash.obj\
    46 $(OBJDIR)\job.obj\
     46#$(OBJDIR)\job.obj\
    4747$(OBJDIR)\main.obj\
    4848$(OBJDIR)\make.obj\
  • trunk/src/kmk/main.c

    r39 r40  
    305305                                        debug |= DEBUG_MAKE;
    306306                                        break;
    307                                 case 's':
     307                                case 'p':     /*kso*/
     308                                        debug |= DEBUG_PARSE;
     309                                        break;
     310                                case 's':
    308311                                        debug |= DEBUG_SUFF;
    309312                                        break;
  • trunk/src/kmk/make.h

    r27 r40  
    370370#define DEBUG_FOR       0x0400
    371371#define DEBUG_LOUD      0x0800
     372#define DEBUG_PARSE     0x8000 /*kso*/
    372373
    373374/*#ifdef __STDC__*/
  • trunk/src/kmk/parse.c

    r36 r40  
    103103#include "pathnames.h"
    104104
     105#if defined(NMAKE) || defined(KMK)
     106#define SUPPORT_INLINEFILES     1
     107#endif
     108
    105109/*
    106110 * These values are returned by ParseEOF to tell Parse_File whether to
     
    111115#define DONE            0
    112116static Lst          targets;    /* targets we're working on */
    113 static Lst          targCmds;   /* command lines for targets */
     117/*static Lst                targCmds; */        /* command lines for targets */
    114118static Boolean      inLine;     /* true if currently in a dependency
    115119                                 * line or its commands */
     120#if defined(NMAKE) || defined(KMK)
     121static Boolean      inInlineFile; /* true if currently in a inline file.*/
     122#endif
    116123typedef struct {
    117124    char *str;
     
    249256static void ParseDoDependency __P((char *));
    250257static int ParseAddCmd __P((ClientData, ClientData));
     258#ifdef SUPPORT_INLINEFILES
     259static int ParseAppendInline __P((ClientData, ClientData));
     260static Boolean ParseCmdIsComponent __P((const char *, const char *));
     261#endif
    251262static int ParseReadc __P((void));
    252263static void ParseUnreadc __P((int));
     
    15101521}
    15111522
     1523
     1524
     1525#ifdef SUPPORT_INLINEFILES
     1526/*-
     1527 * ParseAppendInline  --
     1528 *      Lst_ForEach function to append the line to the last command
     1529 *
     1530 * Results:
     1531 *      Always 0
     1532 *
     1533 * Side Effects:
     1534 *      A new element is added to the last commands list of the node.
     1535 */
     1536static int
     1537ParseAppendInline(gnp, line)
     1538    ClientData gnp;     /* the node to which the command is to be added */
     1539    ClientData line;    /* the command to add */
     1540{
     1541    GNode *gn = (GNode *)gnp;
     1542    /* if target already supplied, ignore commands */
     1543    if (!(gn->type & OP_HAS_COMMANDS))
     1544    {
     1545        unsigned cch;
     1546        char *  cmd;
     1547        unsigned cchNew;
     1548        cmd = (char*)Lst_Datum(Lst_Last(gn->commands));
     1549        cch = strlen(cmd);
     1550        cchNew = strlen(line);
     1551        cmd = erealloc(cmd, cch + 1 + cchNew + 1);
     1552        cmd[cch] = '\n';
     1553        memcpy(&cmd[cch + 1], line, cchNew + 1);
     1554        Lst_Replace(Lst_Last(gn->commands), cmd);
     1555    }
     1556    return(0);
     1557}
     1558
     1559/*-
     1560 *-----------------------------------------------------------------------
     1561 * ParseCmdIsComponent --
     1562 *      Checks if the comp is a component in the cmdline.
     1563 *
     1564 * Results:
     1565 *      returns TRUE if it is, FALSE if not.
     1566 *
     1567 * Side Effects:
     1568 *      OP_HAS_COMMANDS may be set for the target.
     1569 *
     1570 *-----------------------------------------------------------------------
     1571 */
     1572static Boolean
     1573ParseCmdIsComponent(cmdline, comp)
     1574    const char *cmdline;
     1575    const char *comp;
     1576{
     1577#if 0 /* @todo FIX THIS */
     1578    const char *    psz;
     1579    char            chQuote;
     1580    int             cchComp;
     1581    register char   ch;
     1582
     1583    /** ASSUMES NOT ESCAPED (but then the shell doesn't support escaping anyway) */
     1584    if (!strstr(cmdline, comp))
     1585        return FALSE;
     1586
     1587    cchComp = strlen(comp);
     1588    for (chQuote = '\0', ch = *cmdline, psz = NULL; ch; ch = *++cmdline)
     1589    {
     1590        if (ch == '\'' || ch == '\"')
     1591        {
     1592            if (chQuote)
     1593            {   /* end of story */
     1594                if (cmdline - psz == cchComp && !strncmp(psz, comp, cchComp))
     1595                    return TRUE;
     1596                chQuote = '\0';
     1597                psz = NULL;
     1598            }
     1599            else
     1600            {
     1601                chQuote = ch;
     1602                if (!psz)
     1603                    psz = cmdline + 1;
     1604            }
     1605        } else if (!chQuote && !psz && !isspace(ch))
     1606            psz = cmdline;
     1607    }
     1608
     1609    return FALSE;
     1610
     1611#else
     1612    return strstr(cmdline, comp) != NULL;
     1613
     1614#endif
     1615}
     1616#endif
     1617
    15121618/*-
    15131619 *-----------------------------------------------------------------------
     
    21452251    semiNL = FALSE;
    21462252    ignDepOp = FALSE;
     2253    #ifdef SUPPORT_INLINEFILES
     2254    ignComment = inInlineFile;
     2255    #else
    21472256    ignComment = FALSE;
     2257    #endif
    21482258
    21492259    /*
     
    21562266    for (;;) {
    21572267        c = ParseReadc();
     2268        #ifdef SUPPORT_INLINEFILES
     2269        if (inInlineFile)
     2270            break;
     2271        #endif
    21582272
    21592273        if (c == '\t') {
     
    21772291        buf = Buf_Init(MAKE_BSIZE);
    21782292
     2293        /* @todo any inline changes here? */
    21792294        #ifdef NMAKE
    21802295        while (((c = ParseReadc ()) != '\n' || (lastc == '\\') || (lastc == '^')) && (c != EOF))
     
    21862301            switch(c) {
    21872302            case '\n':
    2188                 /*
     2303                #ifdef SUPPORT_INLINEFILES
     2304                /* No newline escaping in inline files, unless it's a directive. */
     2305                if (inInlineFile) {
     2306                    int cb;
     2307                    char *psz = Buf_GetAll(buf, &cb);
     2308                    #ifdef NMAKE
     2309                    if (cb > 0 && *psz != '.' && *psz != '!')
     2310                    #else
     2311                    if (cb > 0 && *psz != '.')
     2312                    #endif
     2313                        break;
     2314                }
     2315                #endif
     2316               
     2317                /*
    21892318                 * Escaped newline: read characters until a non-space or an
    21902319                 * unescaped newline and replace them all by a single space.
     
    22302359                break;
    22312360
     2361/* We don't need this, and don't want it! */
     2362#ifndef KMK
    22322363            case ';':
     2364                #ifdef SUPPORT_INLINEFILES
     2365                if (inInlineFile)
     2366                    break;
     2367                #endif
    22332368                /*
    22342369                 * Semi-colon: Need to see if it should be interpreted as a
     
    22492384                break;
    22502385            case '=':
    2251                 if (!semiNL) {
     2386                #ifdef SUPPORT_INLINEFILES
     2387                if (inInlineFile)
     2388                    break;
     2389                #endif
     2390                if (!semiNL) {
    22522391                    /*
    22532392                     * Haven't seen a dependency operator before this, so this
     
    22982437            case ':':
    22992438            case '!':
     2439                #ifdef SUPPORT_INLINEFILES
     2440                if (inInlineFile)
     2441                    break;
     2442                #endif
    23002443                if (!ignDepOp && (c == ':' || c == '!')) {
    23012444                    /*
     
    23072450                }
    23082451                break;
     2452#endif /* !KMK */
    23092453            }
    23102454            /*
     
    23662510                break;
    23672511            case COND_INVALID:
    2368                 if (For_Eval(line)) {
     2512                if (For_Eval(line)) {
    23692513                    int ok;
    23702514                    efree(line);
     
    24492593
    24502594    inLine = FALSE;
     2595    #if defined(NMAKE) || defined(KMK)
     2596    inInlineFile = FALSE;
     2597    #endif
    24512598    fname = name;
    24522599    curFILE = stream;
     
    24562603    do {
    24572604        while ((line = ParseReadLine ()) != NULL) {
    2458 //debugkso: fprintf(stderr, "%s(%d): inLine=%d line=%s\n", fname, lineno, inLine, line);
     2605            if (DEBUG(PARSE))
     2606                printf("%s(%d): inLine=%d inInlineFile=%d\n%s\n", fname, lineno, inLine, inInlineFile, line);
    24592607            #ifdef NMAKE
    24602608            if (*line == '.' || *line == '!') {
     
    24922640                }
    24932641            }
     2642
     2643            #ifdef SUPPORT_INLINEFILES
     2644            if (inInlineFile)
     2645            {
     2646                cp = line;
     2647                if (*cp == '<' && cp[1] == '<')
     2648                {
     2649                    inInlineFile = FALSE;
     2650                    for (cp = line + 2; isspace(*cp); cp++) {
     2651                        continue;
     2652                    }
     2653                    if (!*cp || *cp == '#') { /* no flag */
     2654                        line[2] = '\0';
     2655                        cp = line;
     2656                    } else if (!strncmp(cp, "KEEP", 4) &&
     2657                               (!cp[4] || isspace(cp[4]) || cp[4] == '#')) {
     2658                        cp[4] = '\0';
     2659                        *--cp = '<';
     2660                        *--cp = '<';
     2661                    } else if (!strncmp(cp, "NOKEEP", 6) &&
     2662                               (!cp[6] || isspace(cp[6]) || cp[6] == '#')) {
     2663                        cp[6] = '\0';
     2664                        *--cp = '<';
     2665                        *--cp = '<';
     2666                    }
     2667                    else
     2668                    {
     2669                        Parse_Error(PARSE_FATAL, "Invalid termination of inline file \"%s\"", cp);
     2670                        cp = NULL;
     2671                    }
     2672                }
     2673                /* Append to last command */
     2674                if (cp)
     2675                {
     2676                    Lst_ForEach(targets, ParseAppendInline, cp);
     2677                    /*Lst_AtEnd(targCmds, (ClientData) line); */
     2678                }
     2679                goto nextLine;
     2680            }
     2681            #endif
     2682
    24942683            if (*line == '#') {
    24952684                /* If we're this far, the line must be a comment. */
     
    25102699                if (*cp) {
    25112700                    if (inLine) {
     2701                        #ifdef SUPPORT_INLINEFILES
     2702                        if (ParseCmdIsComponent(cp, "<<"))
     2703                        {
     2704                            inInlineFile = TRUE;
     2705                            Lst_ForEach(targets, ParseAddCmd, estrdup(cp));
     2706                            /*Lst_AtEnd(targCmds, (ClientData) line);*/
     2707                            goto nextLine;
     2708                        }
     2709                        #endif
    25122710                        /*
    25132711                         * So long as it's not a blank line and we're actually
     
    25162714                         */
    25172715                        Lst_ForEach (targets, ParseAddCmd, cp);
    2518                         Lst_AtEnd(targCmds, (ClientData) line);
     2716                        /*Lst_AtEnd(targCmds, (ClientData) line);*/
    25192717                        continue;
    25202718                    } else {
     
    25482746                 * and add it to the current list of targets.
    25492747                 */
    2550 #if !defined(POSIX) || defined(NMAKE)
     2748#if !defined(POSIX) || defined(NMAKE) || defined(KMK)
    25512749                Boolean nonSpace = FALSE;
    25522750#endif
     
    25602758                        goto nextLine;
    25612759                    }
    2562 #if !defined(POSIX) || defined(NMAKE)
     2760#if !defined(POSIX) || defined(NMAKE) || defined(KMK)
    25632761                    while ((*cp != ':') && (*cp != '!') && (*cp != '\0')) {
    25642762                        nonSpace = TRUE;
     
    25682766                }
    25692767
    2570 #if !defined(POSIX) || defined(NMAKE)
     2768#if !defined(POSIX) || defined(NMAKE) || defined(KMK)
    25712769                if (*cp == '\0') {
    25722770                    if (inLine) {
    2573 #ifndef NMAKE
     2771#if !defined(NMAKE) && !defined(KMK)
    25742772                        Parse_Error (PARSE_WARNING,
    25752773                                     "Shell command needs a leading tab");
     
    25972795
    25982796                    ParseDoDependency (line);
    2599 #if !defined(POSIX) || defined(NMAKE)
     2797#if !defined(POSIX) || defined(NMAKE) || defined(KMK)
    26002798                }
    26012799#endif
     
    26392837    sysIncPath = Lst_Init (FALSE);
    26402838    includes = Lst_Init (FALSE);
    2641     targCmds = Lst_Init (FALSE);
     2839    /*targCmds = Lst_Init (FALSE);*/
    26422840}
    26432841
     
    26452843Parse_End()
    26462844{
    2647     Lst_Destroy(targCmds, (void (*) __P((ClientData))) efree);
     2845    /*Lst_Destroy(targCmds, (void (*) __P((ClientData))) efree);*/
    26482846    if (targets)
    26492847        Lst_Destroy(targets, NOFREE);
Note: See TracChangeset for help on using the changeset viewer.