Initial import.

This commit is contained in:
rsc 2003-09-30 17:47:42 +00:00
parent b2cfc4e2e7
commit ed7c8e8d02
41 changed files with 3226 additions and 0 deletions

27
src/cmd/mk/NOTICE Normal file
View file

@ -0,0 +1,27 @@
Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
Portions Copyright © 1995-1997 C H Forsyth (forsyth@caldo.demon.co.uk). All rights reserved.
Portions Copyright © 1997-1999 Vita Nuova Limited. All rights reserved.
Portions Copyright © 2000-2002 Vita Nuova Holdings Limited (www.vitanuova.com). All rights reserved.
Under a licence agreement with Lucent Technologies Inc. effective 1st March 2000,
Vita Nuova Holdings Limited has the right to determine (within a specified scope)
the form and content of sublicences for this software.
Vita Nuova Holdings Limited now makes this software available as Free
Software under the terms of the `GNU General Public LIcense, Version 2'
(see the file LICENCE or http://www.fsf.org/copyleft/gpl.html for
the full terms and conditions). One of the conditions of that licence
is that you must keep intact all notices that refer to that licence and to the absence of
of any warranty: for this software, note that includes this NOTICE file in particular.
This suite of programs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
`GNU General Public License' for more details.
This copyright NOTICE applies to all files in this directory and
subdirectories, unless another copyright notice appears in a given
file or subdirectory. If you take code from this software to use in
other programs, you must somehow include with it an appropriate
copyright notice that includes the copyright notice and the other
notices above.

7
src/cmd/mk/README Normal file
View file

@ -0,0 +1,7 @@
This is a Unix port of mk,
originally done for the Inferno operating system.
Russ Cox repackaged this to build as a standalone
Unix program. Send comments about packaging to
Russ Cox <rsc@post.harvard.edu>

88
src/cmd/mk/bufblock.c Normal file
View file

@ -0,0 +1,88 @@
#include "mk.h"
static Bufblock *freelist;
#define QUANTA 4096
Bufblock *
newbuf(void)
{
Bufblock *p;
if (freelist) {
p = freelist;
freelist = freelist->next;
} else {
p = (Bufblock *) Malloc(sizeof(Bufblock));
p->start = Malloc(QUANTA*sizeof(*p->start));
p->end = p->start+QUANTA;
}
p->current = p->start;
*p->start = 0;
p->next = 0;
return p;
}
void
freebuf(Bufblock *p)
{
p->next = freelist;
freelist = p;
}
void
growbuf(Bufblock *p)
{
int n;
Bufblock *f;
char *cp;
n = p->end-p->start+QUANTA;
/* search the free list for a big buffer */
for (f = freelist; f; f = f->next) {
if (f->end-f->start >= n) {
memcpy(f->start, p->start, p->end-p->start);
cp = f->start;
f->start = p->start;
p->start = cp;
cp = f->end;
f->end = p->end;
p->end = cp;
f->current = f->start;
break;
}
}
if (!f) { /* not found - grow it */
p->start = Realloc(p->start, n);
p->end = p->start+n;
}
p->current = p->start+n-QUANTA;
}
void
bufcpy(Bufblock *buf, char *cp, int n)
{
while (n--)
insert(buf, *cp++);
}
void
insert(Bufblock *buf, int c)
{
if (buf->current >= buf->end)
growbuf(buf);
*buf->current++ = c;
}
void
rinsert(Bufblock *buf, Rune r)
{
int n;
n = runelen(r);
if (buf->current+n > buf->end)
growbuf(buf);
runetochar(buf->current, &r);
buf->current += n;
}

33
src/cmd/mk/job.c Normal file
View file

@ -0,0 +1,33 @@
#include "mk.h"
Job *
newjob(Rule *r, Node *nlist, char *stem, char **match, Word *pre, Word *npre, Word *tar, Word *atar)
{
register Job *j;
j = (Job *)Malloc(sizeof(Job));
j->r = r;
j->n = nlist;
j->stem = stem;
j->match = match;
j->p = pre;
j->np = npre;
j->t = tar;
j->at = atar;
j->nproc = -1;
j->next = 0;
return(j);
}
void
dumpj(char *s, Job *j, int all)
{
Bprint(&bout, "%s\n", s);
while(j){
Bprint(&bout, "job@%ld: r=%ld n=%ld stem='%s' nproc=%d\n",
j, j->r, j->n, j->stem, j->nproc);
Bprint(&bout, "\ttarget='%s' alltarget='%s' prereq='%s' nprereq='%s'\n",
wtos(j->t, ' '), wtos(j->at, ' '), wtos(j->p, ' '), wtos(j->np, ' '));
j = all? j->next : 0;
}
}

BIN
src/cmd/mk/mk.pdf Normal file

Binary file not shown.