📄 maker.c
字号:
/*
Copyright 1994-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
You may contact the author at:
mailto::camille@bluegrass.net
or by snail mail at:
David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222
*/
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <dos.h>
#include "utype.h"
#include "cmdline.h"
#include "interp.h"
#include "umem.h"
#include "register.h"
#include "maker.h"
#include "phash.h"
#include "input.h"
#include "imake.h"
#include "macros.h"
#include "module.h"
#define MK_FP(seg,ofs) ((void __seg *)(seg) + (void __near *)(ofs))
extern LIST *targetlist;
extern BOOL prm_buildall;
extern BOOL prm_displaystamp;
extern short xpath[];
extern HASHREC **hashtable;
static char *months[] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
"Dec"
};
static void nxtarget(short *target)
{
char buf[200];
CompressFile(buf, target);
fatal("Target %s - non-existant with no rules", buf);
}
//-------------------------------------------------------------------------
void CompressFile(char *out, short *in)
{
do
{
*out++ = *in++ &0xff;
}
while (*in);
*out = 0;
}
//-------------------------------------------------------------------------
void ExpandFile(short *out, char *in)
{
do
{
*out++ = *in++;
}
while (*in);
*out = 0;
}
//-------------------------------------------------------------------------
static unsigned long getfiletime(short *file)
{
char buf[200];
uint handle, date, time;
CompressFile(buf, file);
_dos_open(buf, 0, &handle);
if (handle == 0)
return (0);
_dos_getftime(handle, &date, &time);
_dos_close(handle);
return (((unsigned long)(date) << 16) + time);
}
//-------------------------------------------------------------------------
FILE *GetPath(short *name)
{
REGISTRY **r;
char buf[200];
char searchpath[200];
short *p = pstrrchr(name, '.');
short pathext[40];
FILE *s;
searchpath[0] = 0;
if (p && *(p - 1) != '.')
{
pstrcpy(pathext, xpath);
pstrcat(pathext, p);
r = LookupPhiHash(hashtable, pathext);
if (r && (*r)->type == R_PATH)
{
CompressFile(searchpath, (*r)->x.path);
}
}
CompressFile(buf, name);
s = SearchPath(buf, searchpath, "r");
ExpandFile(name, buf);
return s;
}
//-------------------------------------------------------------------------
FILEREC *FileData(short *string)
{
short pathext[40], *p;
short *buf;
short buf2[1000];
BOOL exists = FALSE, explicit = FALSE, implicit = FALSE;
short *depends = 0, *depends1 = 0, *target, *path = 0;
FILE *s;
REGISTRY **r = LookupPhiHash(hashtable, string);
buf = AllocateMemory(INTERNALBUFSIZE *sizeof(short));
if (r && (*r)->type == R_EXPLICIT)
{
explicit = TRUE;
pstrcpy(buf, (*r)->depends);
ExpandString(buf);
depends = AllocateMemory(pstrlen(buf) *2+2);
pstrcpy(depends, buf);
}
target = AllocateMemory(pstrlen(string) *2+2);
pstrcpy(target, string);
pstrcpy(buf, string);
s = GetPath(buf);
if (s)
{
fclose(s);
exists = TRUE;
path = AllocateMemory(pstrlen(buf) *2+2);
pstrcpy(path, buf);
}
else
{
path = AllocateMemory(pstrlen(string) *2+2);
pstrcpy(path, string);
}
pstrcpy(buf, string);
p = pstrrchr(buf, '.');
if (p && (!explicit || (*r)->x.commands == 0 || (*r)->x.commands[0] == 0))
{
if (*(p - 1) != '.')
{
pstrcpy(pathext, p);
r = LookupPhiHash(hashtable, pathext);
if (r && (*r)->type == R_DEST)
{
if (explicit || !(depends1 = GetAutoDepends(path)))
{
short *bp, *t, *d;
pstrcpy(buf, target);
bp = pstrrchr(buf, PERIOD);
s = 0;
if (*(bp - 1) != '.')
{
d = (*r)->x.path;
while (*d)
{
t = bp;
do
{
*t++ = *d++;
}
while (*d && *d != ';');
if (*d)
d++;
*t = 0;
pstrcpy(buf2, buf);
s = GetPath(buf2);
if (s)
{
fclose(s);
break;
}
}
}
DeallocateMemory(target);
p = pstrrchr(string, '.');
target = AllocateMemory((pstrlen(bp) + pstrlen(p)) *2+2);
pstrcpy(target, bp);
pstrcat(target, p);
/* Note that this implementation depends on the name being
given in the MB record of the obje file */
/* hacked to allow recursion on non-existing targets.
* Some ambiguity exists though in the presence of multiple
* source resulting in the same obj for example...
*/
/* if (s) { */
if (depends1)
{
pstrcat(buf2, L" ");
pstrcat(buf2, depends1);
}
if (depends)
{
pstrcat(buf2, L" ");
pstrcat(buf2, depends);
}
depends = AllocateMemory(pstrlen(buf2) *2+2);
pstrcpy(depends, buf2);
/* }
else {
depends = AllocateMemory(2);
depends[0] = 0;
}
*/
}
else
{
short *bp = buf, *t;
pstrcpy(buf, depends);
t = pstrchr(buf, ' ');
if (t)
*t = 0;
bp = pstrrchr(bp, '.');
if (!bp)
bp = buf;
DeallocateMemory(target);
target = AllocateMemory((pstrlen(bp) + pstrlen(p)) *2+2);
p = pstrrchr(string, '.');
pstrcpy(target, bp);
pstrcat(target, p);
}
implicit = TRUE;
}
}
}
if (exists || explicit || implicit)
{
FILEREC *rv = AllocateMemory(sizeof(FILEREC));
rv->link = 0;
rv->parent = 0;
rv->targetable = explicit || implicit;
rv->implicit = implicit != 0;
rv->exists = exists;
rv->depends = depends;
rv->target = target;
rv->path = path;
rv->timedout = FALSE;
if (exists)
rv->time = getfiletime(path);
else
rv->time = 0xffffffffL;
DeallocateMemory(buf);
return (rv);
}
else
{
DeallocateMemory(depends);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -