File: pact.c

package info (click to toggle)
pact 980714-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 13,096 kB
  • ctags: 26,034
  • sloc: ansic: 109,076; lisp: 9,645; csh: 7,147; fortran: 1,050; makefile: 136; lex: 95; sh: 32
file content (168 lines) | stat: -rw-r--r-- 3,638 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * PACT.C - do makes properly
 *
 * Source Version: 2.0
 * Software Release #92-0043
 *
 * include "cpyright.h"
 *
 */

#include <stdio.h>
#include <string.h>

#define MAXLINE 255

static char
 cwd[MAXLINE],
 makefile[MAXLINE];

#ifdef STUPID_MAKE
static int
 was_there = 0;
#endif

int system();
char *getcwd();
void (*signal())();

static int cleanup();
static void handler();

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

main(c, v)
   int c;
   char **v;
   {int i, status, keep;
    FILE *mk, *in;
    char cmnd[MAXLINE], devdir[MAXLINE], *pmname;
    static char *default_pmname = "pre-Make";

    signal(2, handler);

    pmname = default_pmname;
    keep   = 0;

    for (i = 1; i < c; i++)
        {if (v[i][0] == '-')
            {switch (v[i][1])
                {case 'f' :
		      pmname = v[++i];
		      break;
	         case 'n' :
		      keep = 1;
		      break;};}
	 else
	    break;};

    in = fopen(pmname, "r");
    if (in == NULL)
       return(0);

#ifdef PUB
    sprintf(devdir, "%s", PUB);
#else
    sprintf(devdir, "%s/dev/%s", ROOT, SYSTEM);
#endif

/* find the current directory */
    if (getcwd(cwd, MAXLINE) == NULL)
       {fprintf(stderr, "ERROR: CAN'T GET CURRENT DIRECTORY\n");
        return(1);};

/* make the temporary file name */
    tmpnam(makefile);
    mk = fopen(makefile, "w");

/* write the temporary Makefile */
    i = strlen(cwd) - 7;
    if (strcmp(cwd+i, "manager") == 0)
       {fprintf(mk, "System = %s\n", SYSTEM);
	while (fgets(cmnd, MAXLINE, in) != NULL)
	   fprintf(mk, "%s", cmnd);}

    else
       {fprintf(mk, "include %s/include/make-def\n", devdir);
	while (fgets(cmnd, MAXLINE, in) != NULL)
	   fprintf(mk, "%s", cmnd);    
	fprintf(mk, "include %s/include/make-macros\n", devdir);};

    fclose(in);
    fclose(mk);

#ifdef STUPID_MAKE
    was_there = ((in = fopen("pact", "r")) != NULL);
    if (was_there)
       fclose(in);
    else
       {sprintf(cmnd, "cp %s/bin/pact .", devdir);
	system(cmnd);
	system("chmod a+x pact");};
#endif
    
/* make the command to invoke make */

#ifdef USE_GNU_MAKE
    sprintf(cmnd, "make --no-print-directory -f %s", makefile);
#else
    sprintf(cmnd, "make -f %s", makefile);
#endif
    for (i = 1; i < c; i++)
        {if (strcmp(v[i], "-f") == 0)
            {i++;
	     continue;};
	 strcat(cmnd, " ");
	 strcat(cmnd, v[i]);};

/* do the make */
    status = system(cmnd);   

    cleanup(keep);

    return((status == 0) ? 0 : 1);}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* CLEANUP - remove temporary files of all sorts */

static int cleanup(keep)
   int keep;
   {char cmnd[MAXLINE];

#ifdef STUPID_MAKE
    if (!was_there)
       unlink("pact");
#endif

    if (!keep)
       remove(makefile);
    else
       {sprintf(cmnd, "mv %s make.tmp", makefile);
	system(cmnd);};

    return(1);}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/

/* HANDLER - handle signals gracefully */

static void handler(sig)
   int sig;
   {
    fprintf(stderr, "PACT exiting on signal %d\n", sig);
    fprintf(stdout, "PACT exiting with signal %d\n", sig);

#ifdef STUPID_MAKE
    was_there = 0;
#endif

    cleanup(0);

    exit(sig);}

/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/