~ubuntu-branches/ubuntu/raring/pmake/raring-proposed

« back to all changes in this revision

Viewing changes to compat.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hocevar (Debian packages)
  • Date: 2005-07-07 10:20:56 UTC
  • mfrom: (0.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050707102056-3nh411zy3wbwuwyr
Tags: 1.111-1
* New upstream snapshot.
* This version properly parses arguments and does not crash when parameters
  are missing (Closes: #287336, #316394).
* debian/control:
  + Set policy to 3.6.2.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $NetBSD: compat.c,v 1.52 2003/09/10 18:04:22 jmmv Exp $ */
 
1
/*      $NetBSD: compat.c,v 1.58 2005/05/08 04:19:12 christos Exp $     */
2
2
 
3
3
/*
4
4
 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
69
69
 * SUCH DAMAGE.
70
70
 */
71
71
 
72
 
#ifdef MAKE_BOOTSTRAP
73
 
static char rcsid[] = "$NetBSD: compat.c,v 1.52 2003/09/10 18:04:22 jmmv Exp $";
 
72
#ifndef MAKE_NATIVE
 
73
static char rcsid[] = "$NetBSD: compat.c,v 1.58 2005/05/08 04:19:12 christos Exp $";
74
74
#else
75
75
#include <sys/cdefs.h>
76
76
#ifndef lint
77
77
#if 0
78
78
static char sccsid[] = "@(#)compat.c    8.2 (Berkeley) 3/19/94";
79
79
#else
80
 
__RCSID("$NetBSD: compat.c,v 1.52 2003/09/10 18:04:22 jmmv Exp $");
 
80
__RCSID("$NetBSD: compat.c,v 1.58 2005/05/08 04:19:12 christos Exp $");
81
81
#endif
82
82
#endif /* not lint */
83
83
#endif
122
122
static GNode        *curTarg = NILGNODE;
123
123
static GNode        *ENDNode;
124
124
static void CompatInterrupt(int);
125
 
static int CompatRunCommand(ClientData, ClientData);
126
 
static int CompatMake(ClientData, ClientData);
 
125
 
 
126
static void
 
127
Compat_Init(void)
 
128
{
 
129
    const char *cp;
 
130
 
 
131
    Shell_Init();               /* setup default shell */
 
132
    
 
133
    for (cp = "~#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
 
134
        meta[(unsigned char) *cp] = 1;
 
135
    }
 
136
    /*
 
137
     * The null character serves as a sentinel in the string.
 
138
     */
 
139
    meta[0] = 1;
 
140
}
127
141
 
128
142
/*-
129
143
 *-----------------------------------------------------------------------
147
161
 
148
162
    if ((curTarg != NILGNODE) && !Targ_Precious (curTarg)) {
149
163
        char      *p1;
150
 
        char      *file = Var_Value (TARGET, curTarg, &p1);
 
164
        char      *file = Var_Value(TARGET, curTarg, &p1);
151
165
 
152
166
        if (!noExecute && eunlink(file) != -1) {
153
167
            Error("*** %s removed", file);
161
175
        if (signo == SIGINT) {
162
176
            gn = Targ_FindNode(".INTERRUPT", TARG_NOCREATE);
163
177
            if (gn != NILGNODE) {
164
 
                Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
 
178
                Compat_Make(gn, gn);
165
179
            }
166
180
        }
167
181
 
187
201
 *
188
202
 *-----------------------------------------------------------------------
189
203
 */
190
 
static int
 
204
int
191
205
CompatRunCommand(ClientData cmdp, ClientData gnp)
192
206
{
193
207
    char          *cmdStart;    /* Start of expanded command */
194
208
    char          *cp, *bp;
195
209
    Boolean       silent,       /* Don't print command */
 
210
                  doIt,         /* Execute even if -n */
196
211
                  errCheck;     /* Check errors */
197
212
    int           reason;       /* Reason for child's death */
198
213
    int           status;       /* Description of child's death */
214
229
#if __GNUC__
215
230
    (void) &av;
216
231
    (void) &errCheck;
 
232
    (void) &cmd;
217
233
#endif
218
234
    silent = gn->type & OP_SILENT;
219
235
    errCheck = !(gn->type & OP_IGNORE);
220
 
 
221
 
    cmdNode = Lst_Member (gn->commands, (ClientData)cmd);
222
 
    cmdStart = Var_Subst (NULL, cmd, gn, FALSE);
 
236
    doIt = FALSE;
 
237
    
 
238
    cmdNode = Lst_Member(gn->commands, (ClientData)cmd);
 
239
    cmdStart = Var_Subst(NULL, cmd, gn, FALSE);
223
240
 
224
241
    /*
225
242
     * brk_string will return an argv with a NULL in av[0], thus causing
235
252
    } else {
236
253
        cmd = cmdStart;
237
254
    }
238
 
    Lst_Replace (cmdNode, (ClientData)cmdStart);
 
255
    Lst_Replace(cmdNode, (ClientData)cmdStart);
239
256
 
240
257
    if ((gn->type & OP_SAVE_CMDS) && (gn != ENDNode)) {
241
258
        (void)Lst_AtEnd(ENDNode->commands, (ClientData)cmdStart);
245
262
        return(0);
246
263
    }
247
264
 
248
 
    while ((*cmd == '@') || (*cmd == '-')) {
249
 
        if (*cmd == '@') {
 
265
    while ((*cmd == '@') || (*cmd == '-') || (*cmd == '+')) {
 
266
        switch (*cmd) {
 
267
        case '@':
250
268
            silent = TRUE;
251
 
        } else {
 
269
            break;
 
270
        case '-':
252
271
            errCheck = FALSE;
 
272
            break;
 
273
        case '+':
 
274
            doIt = TRUE;
 
275
            if (!meta[0])               /* we came here from jobs */
 
276
                Compat_Init();
 
277
            break;
253
278
        }
254
279
        cmd++;
255
280
    }
279
304
     * If we're not supposed to execute any commands, this is as far as
280
305
     * we go...
281
306
     */
282
 
    if (NoExecute(gn)) {
 
307
    if (!doIt && NoExecute(gn)) {
283
308
        return (0);
284
309
    }
285
310
 
286
311
    if (*cp != '\0') {
287
312
        /*
288
313
         * If *cp isn't the null character, we hit a "meta" character and
289
 
         * need to pass the command off to the shell. We give the shell the
290
 
         * -e flag as well as -c if it's supposed to exit when it hits an
291
 
         * error.
 
314
         * need to pass the command off to the shell. 
292
315
         */
293
316
        static const char *shargv[4];
294
317
 
297
320
         * The following work for any of the builtin shell specs.
298
321
         */
299
322
        if (DEBUG(SHELL))
300
 
                shargv[1] = (errCheck ? "-exc" : "-xc");
 
323
                shargv[1] = "-xc";
301
324
        else
302
 
                shargv[1] = (errCheck ? "-ec" : "-c");
 
325
                shargv[1] = "-c";
303
326
        shargv[2] = cmd;
304
327
        shargv[3] = (char *)NULL;
305
328
        av = shargv;
335
358
        free(av);
336
359
        free(bp);
337
360
    }
338
 
    Lst_Replace (cmdNode, (ClientData) NULL);
 
361
    Lst_Replace(cmdNode, (ClientData) NULL);
339
362
 
340
363
    /*
341
364
     * The child is off and running. Now all we can do is wait...
398
421
            }
399
422
            break;
400
423
        } else {
401
 
            Fatal ("error in wait: %d: %s", retstat, strerror(errno));
 
424
            Fatal("error in wait: %d: %s", retstat, strerror(errno));
402
425
            /*NOTREACHED*/
403
426
        }
404
427
    }
409
432
 
410
433
/*-
411
434
 *-----------------------------------------------------------------------
412
 
 * CompatMake --
 
435
 * Compat_Make --
413
436
 *      Make a target.
414
437
 *
415
438
 * Input:
424
447
 *
425
448
 *-----------------------------------------------------------------------
426
449
 */
427
 
static int
428
 
CompatMake(ClientData gnp, ClientData pgnp)
 
450
int
 
451
Compat_Make(ClientData gnp, ClientData pgnp)
429
452
{
430
453
    GNode *gn = (GNode *) gnp;
431
454
    GNode *pgn = (GNode *) pgnp;
432
455
 
 
456
    if (!meta[0])               /* we came here from jobs */
 
457
        Compat_Init();
433
458
    if (gn->made == UNMADE && (gn == pgn || (pgn->type & OP_MADE) == 0)) {
434
459
        /*
435
460
         * First mark ourselves to be made, then apply whatever transformations
442
467
        gn->flags |= REMAKE;
443
468
        gn->made = BEINGMADE;
444
469
        if ((gn->type & OP_MADE) == 0)
445
 
            Suff_FindDeps (gn);
446
 
        Lst_ForEach (gn->children, CompatMake, (ClientData)gn);
 
470
            Suff_FindDeps(gn);
 
471
        Lst_ForEach(gn->children, Compat_Make, (ClientData)gn);
447
472
        if ((gn->flags & REMAKE) == 0) {
448
473
            gn->made = ABORTED;
449
474
            pgn->flags &= ~REMAKE;
450
475
            goto cohorts;
451
476
        }
452
477
 
453
 
        if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
 
478
        if (Lst_Member(gn->iParents, pgn) != NILLNODE) {
454
479
            char *p1;
455
 
            Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
 
480
            Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
456
481
            if (p1)
457
482
                free(p1);
458
483
        }
495
520
         * Alter our type to tell if errors should be ignored or things
496
521
         * should not be printed so CompatRunCommand knows what to do.
497
522
         */
498
 
        if (Targ_Ignore (gn)) {
 
523
        if (Targ_Ignore(gn)) {
499
524
            gn->type |= OP_IGNORE;
500
525
        }
501
 
        if (Targ_Silent (gn)) {
 
526
        if (Targ_Silent(gn)) {
502
527
            gn->type |= OP_SILENT;
503
528
        }
504
529
 
505
 
        if (Job_CheckCommands (gn, Fatal)) {
 
530
        if (Job_CheckCommands(gn, Fatal)) {
506
531
            /*
507
532
             * Our commands are ok, but we still have to worry about the -t
508
533
             * flag...
509
534
             */
510
535
            if (!touchFlag || (gn->type & OP_MAKE)) {
511
536
                curTarg = gn;
512
 
                Lst_ForEach (gn->commands, CompatRunCommand, (ClientData)gn);
 
537
                Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
513
538
                curTarg = NILGNODE;
514
539
            } else {
515
 
                Job_Touch (gn, gn->type & OP_SILENT);
 
540
                Job_Touch(gn, gn->type & OP_SILENT);
516
541
            }
517
542
        } else {
518
543
            gn->made = ERROR;
544
569
         */
545
570
        pgn->flags &= ~REMAKE;
546
571
    } else {
547
 
        if (Lst_Member (gn->iParents, pgn) != NILLNODE) {
 
572
        if (Lst_Member(gn->iParents, pgn) != NILLNODE) {
548
573
            char *p1;
549
 
            Var_Set (IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
 
574
            Var_Set(IMPSRC, Var_Value(TARGET, gn, &p1), pgn, 0);
550
575
            if (p1)
551
576
                free(p1);
552
577
        }
573
598
    }
574
599
 
575
600
cohorts:
576
 
    Lst_ForEach (gn->cohorts, CompatMake, pgnp);
 
601
    Lst_ForEach(gn->cohorts, Compat_Make, pgnp);
577
602
    return (0);
578
603
}
579
604
 
596
621
void
597
622
Compat_Run(Lst targs)
598
623
{
599
 
    const char    *cp;      /* Pointer to string of shell meta-characters */
600
624
    GNode         *gn = NULL;/* Current root target */
601
625
    int           errors;   /* Number of targets not remade due to errors */
602
626
 
603
 
    Shell_Init();               /* setup default shell */
 
627
    Compat_Init();
604
628
 
605
629
    if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
606
630
        signal(SIGINT, CompatInterrupt);
615
639
        signal(SIGQUIT, CompatInterrupt);
616
640
    }
617
641
 
618
 
    for (cp = "~#=|^(){};&<>*?[]:$`\\\n"; *cp != '\0'; cp++) {
619
 
        meta[(unsigned char) *cp] = 1;
620
 
    }
621
 
    /*
622
 
     * The null character serves as a sentinel in the string.
623
 
     */
624
 
    meta[0] = 1;
625
 
 
626
642
    ENDNode = Targ_FindNode(".END", TARG_CREATE);
 
643
    ENDNode->type = OP_SPECIAL;
627
644
    /*
628
645
     * If the user has defined a .BEGIN target, execute the commands attached
629
646
     * to it.
631
648
    if (!queryFlag) {
632
649
        gn = Targ_FindNode(".BEGIN", TARG_NOCREATE);
633
650
        if (gn != NILGNODE) {
634
 
            Lst_ForEach(gn->commands, CompatRunCommand, (ClientData)gn);
 
651
            Compat_Make(gn, gn);
635
652
            if (gn->made == ERROR) {
636
653
                PrintOnError("\n\nStop.");
637
654
                exit(1);
646
663
    Lst_Destroy(Make_ExpandUse(targs), NOFREE);
647
664
 
648
665
    /*
649
 
     * For each entry in the list of targets to create, call CompatMake on
650
 
     * it to create the thing. CompatMake will leave the 'made' field of gn
 
666
     * For each entry in the list of targets to create, call Compat_Make on
 
667
     * it to create the thing. Compat_Make will leave the 'made' field of gn
651
668
     * in one of several states:
652
669
     *      UPTODATE        gn was already up-to-date
653
670
     *      MADE            gn was recreated successfully
657
674
     */
658
675
    errors = 0;
659
676
    while (!Lst_IsEmpty (targs)) {
660
 
        gn = (GNode *) Lst_DeQueue (targs);
661
 
        CompatMake (gn, gn);
 
677
        gn = (GNode *) Lst_DeQueue(targs);
 
678
        Compat_Make(gn, gn);
662
679
 
663
680
        if (gn->made == UPTODATE) {
664
681
            printf ("`%s' is up to date.\n", gn->name);
672
689
     * If the user has defined a .END target, run its commands.
673
690
     */
674
691
    if (errors == 0) {
675
 
        Lst_ForEach(ENDNode->commands, CompatRunCommand, (ClientData)gn);
 
692
        Compat_Make(ENDNode, ENDNode);
676
693
        if (gn->made == ERROR) {
677
694
            PrintOnError("\n\nStop.");
678
695
            exit(1);