Category : Miscellaneous Language Source Code
Archive   : MAKE15.ZIP
Filename : BUILD.C

 
Output of file : BUILD.C contained in archive : MAKE15.ZIP
/*
* build.c An imitation of the Unix MAKE facility
*
* 88-10-01 v1.0 created by greg yachuk, placed in the public domain
* 88-10-06 v1.1 changed prerequisite list handling
* 88-11-11 v1.2 fixed some bugs and added environment variables
* 89-07-12 v1.3 stop appending shell commands, and flush output
* 89-08-01 v1.4 AB lots of new options and code
* 89-10-30 v1.5 greggy -f -S -q options, took some changes from v1.4
*
*/

#include
#include
#ifdef MSDOS
#include
#include
#else
#include
#endif

#include "make.h"
#include "tstring.h"
#include "decl.h"

char *shell_cmds[] = {
#ifdef MSDOS
"dir", "type", "rem", "pause", "date", "time", "ren", "rename",
"ver", "vol", "break", "verify", "mkdir", "md", "exit", "ctty",
"echo", "if", "cls", "chdir", "cd", "rmdir", "rd", "copy", "del",
"erase",
#endif
NULL,
};

/*
* build - process the shell commands
*/
build(shellp)
REGISTER shellptr *shellp;
{
REGISTER char **argv; /* argified version of scmd */
int runst; /* exec return status */
char *scmd; /* command with symbols broken out */
char *tcmd; /* copy of scmd for `tokenize' */
char *errnum; /* error number in ascii */
char *errmsg; /* error message */
#ifdef MSDOS
char **shcp; /* pointer to shell command list */
#endif

if (shellp == NULL || opts.query)
return (0);

for (; *shellp != NULL;
tfree(scmd), tfree(tcmd), tfree(argv), ++shellp)
{
/* breakout runtime symbols (e.g. $* $@ $<) */
scmd = breakout((*shellp)->scmd);

if (!opts.silent && (opts.noexec || !(*shellp)->s_silent))
{
puts(scmd);
fflush(stdout);
}

/* make a copy because tokenize litters '\0's */
tcmd = tstrcpy(scmd);
argv = tokenize(tcmd);

/* look for $(MAKE) */
if (equal(argv[0], opts.make))
{
/* call ourselves recursively */
new_make(argv);
continue;
}

if (opts.noexec)
continue;

/* any SHELL meta-characters MUST be handled by the shell */
if (!(*shellp)->s_shell && strpbrk(scmd, SHELL_METAS))
(*shellp)->s_shell = 1;
#ifdef MSDOS
/* likewise, check for COMMAND.COM builtin commands */
shcp = shell_cmds;
for (; !(*shellp)->s_shell && *shcp; ++shcp)
(*shellp)->s_shell = equal(*shcp, argv[0]);
#endif
/* run without COMMAND.COM if possible, 'cause it uses RAM */
if ((*shellp)->s_shell)
runst = system(scmd);
else
runst = spawnvp(P_WAIT, argv[0], argv);

if (runst == 0)
continue;

/* uh-oh, an error */
if (runst == -1)
perror("make");

errnum = talloc(18);
#ifdef MSDOS
errnum = itoa(runst, errnum, 10);
#else
sprintf(errnum, "%d", runst);
#endif
errmsg = (opts.keepon) ? "\007*** Ignoring Error code "
: "\007*** Error code ";
errmsg = tstrcat(errmsg, errnum);
terror(0, errmsg);
tfree(errmsg);
tfree(errnum);

if (opts.keepon)
return (1);

if (!opts.ignore && !(*shellp)->s_ignore)
exit(1);
}

return (0);
}


/*
* new_make - save current environment
* - call make() recursively (actually main())
* - clean up new environment
* - restore environment
*/
new_make(argv)
char **argv;
{
targptr thead, tnext, tsuffix;
fileptr fhead, fnext;
symptr shead, snext;
shellptr shhead, shnext;
char **ttlist;
long tnow;
optnode topts;
int i;

/* save all the globals */
tsuffix = suffix_targ;
thead = target_list;
fhead = file_list;
shead = symbol_list;
shhead = shell_list;
ttlist = tlist;
tnow = now;
topts = opts;

/* count the arguments */
for (i = 0; argv[i]; ++i)
tunquote(argv[i]);

/* call ourselves recursively; this inherits flags */
++make_level;
main(i, argv);
--make_level;

/* we're back, so gotta clean up and dispose of a few things */
while (target_list)
{
tnext = target_list->tnext;
if (target_list->tpreq)
tfree(target_list->tpreq);
if (target_list->tshell)
tfree(target_list->tshell);
tfree(target_list);
target_list = tnext;
}

while (file_list)
{
fnext = file_list->fnext;
tfree(file_list->fname);
tfree(file_list);
file_list = fnext;
}

/* don't drop all symbols, just the new ones */

while (symbol_list != shead)
{
snext = symbol_list->snext;
tfree(symbol_list->sname);
tfree(symbol_list->svalue);
tfree(symbol_list);
symbol_list = snext;
}

while (shell_list)
{
shnext = shell_list->slink;
tfree(shell_list->scmd);
tfree(shell_list);
shell_list = shnext;
}

/* restore our original globals */
suffix_targ = tsuffix;
target_list = thead;
file_list = fhead;
symbol_list = shead;
shell_list = shhead;
tlist = ttlist;
now = tnow;
opts = topts;
}


#ifndef MSDOS
int
spawnvp(mode, path, args)
int mode;
char *path;
char **args;
{
int pid = 0;
union wait waitword;

if (mode != P_OVERLAY)
pid = fork();

if (pid == 0)
execvp(path, args);

wait(&waitword);
return (waitword.w_retcode);
}
#endif


  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : MAKE15.ZIP
Filename : BUILD.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/