📄 make.c
字号:
if (avail)
{
rv = ReadFile(handle, buf + pos, 512-pos, &read, 0);
}
}
pos += read;
buf[pos] = 0;
while (p = strchr(buf, '\n'))
{
char s = *++p;
*p = 0;
SendMessage(hwndError, WM_SETTEXT, window, (LPARAM)buf);
countErrors(buf);
*p = s;
memcpy(buf, p, 512-(p - buf));
pos -= p - buf;
buf[pos] = 0;
}
if (pos == 512 || !rv && pos)
{
buf[pos] = 0;
SendMessage(hwndError, WM_SETTEXT, window, (LPARAM)buf);
countErrors(buf);
pos = 0;
}
if (!read || !rv)
break;
}
return rv;
}
//-------------------------------------------------------------------------
int Execute(char *name, char *cmd, int window)
{
char filename[260];
char cmdbuf[1024];
int retcode;
HANDLE stdoutWr, stdinRd;
HANDLE stdoutRd, stdinWr;
static char buf[1000];
// HANDLE oldhand = GetStdHandle(STD_OUTPUT_HANDLE) ;
// HANDLE oldhande = GetStdHandle(STD_ERROR_HANDLE) ;
// HANDLE oldhandi = GetStdHandle(STD_INPUT_HANDLE) ;
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES security;
memset(&security, 0, sizeof(security));
security.nLength = sizeof(security);
security.bInheritHandle = TRUE;
CreatePipe(&stdoutRd, &stdoutWr, &security, 0);
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
// SetStdHandle(STD_OUTPUT_HANDLE,stdoutWr) ;
// SetStdHandle(STD_ERROR_HANDLE,stdoutWr) ;
CreatePipe(&stdinRd, &stdinWr, &security, 0);
DuplicateHandle(GetCurrentProcess(), stdinWr, GetCurrentProcess(), &stdinWr,
0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
// SetStdHandle(STD_INPUT_HANDLE,stdinRd) ;
si.hStdInput = INVALID_HANDLE_VALUE;
si.hStdOutput = stdoutWr;
si.hStdError = stdoutWr;
if (!name)
{
sprintf(cmdbuf, "\"%s\" /C %s", getenv("COMSPEC"), cmd);
retcode = CreateProcess(0, cmdbuf, 0, 0, 1, DETACHED_PROCESS |
CREATE_SUSPENDED, 0, 0, &si, &pi);
}
else
{
sprintf(filename, "%s\\bin\\%s", szInstallPath, name);
retcode = CreateProcess(filename, cmd, 0, 0, 1, DETACHED_PROCESS |
CREATE_SUSPENDED, 0, 0, &si, &pi);
}
// SetStdHandle(STD_OUTPUT_HANDLE,oldhand) ;
// SetStdHandle(STD_ERROR_HANDLE,oldhande) ;
// SetStdHandle(STD_INPUT_HANDLE,oldhandi) ;
CloseHandle(stdoutWr);
CloseHandle(stdinRd);
if (retcode)
{
SetPriorityClass(pi.hProcess, NORMAL_PRIORITY_CLASS);
SetThreadPriority(pi.hThread, THREAD_PRIORITY_ABOVE_NORMAL);
ResumeThread(pi.hThread);
// sprintf(buf,"%s\r\n",cmd) ;
// SendMessage(hwndError,WM_SETTEXT,window,(LPARAM) buf) ;
while (ParsePipeData(stdoutRd, window, pi.hProcess))
;
WaitForSingleObject(pi.hProcess, INFINITE);
while (ParsePipeData(stdoutRd, window, pi.hProcess))
;
}
else
{
sprintf(buf, "\r\nCan't spawn %s\r\n", filename);
SendMessage(hwndError, WM_SETTEXT, window, (LPARAM)buf);
}
CloseHandle(stdoutRd);
CloseHandle(stdinWr);
if (!retcode)
return 0x55555555;
else
{
GetExitCodeProcess(pi.hProcess, &retcode);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
return retcode;
}
//-------------------------------------------------------------------------
void CompileMessage(char *title, char *name)
{
char buf[256];
sprintf(buf, ";============ %s %s ============\r\n", title, name);
SendMessage(hwndError, WM_SETTEXT, ERR_BUILD_WINDOW, (LPARAM)buf);
}
//-------------------------------------------------------------------------
void repdefines(PROJLIST *x, char *buffer)
{
DEFINES *d = x->defines;
while (d)
{
strcat(buffer, " ");
buffer += strlen(buffer);
sprintf(buffer, "-D%s", d->name);
if (d->value[0])
{
buffer += strlen(buffer);
sprintf(buffer, "=%s", d->value);
}
d = d->next;
}
}
//-------------------------------------------------------------------------
int CompileFile(PROJLIST *x, FILELIST *list)
{
int rv;
FILE *fil;
char buffer[10000], *p;
char intermed[10000];
char working[300];
char *dbgFlag, *nasmFlag, *browseFlag, *nasmdebugFlag, *warningFlag,
*c99Flag, *ansiFlag, *importFlag;
char projectPath[260];
strcpy(projectPath, x->name);
p = strrchr(projectPath, '\\');
if (p)
*(p + 1) = 0;
strcpy(intermed, list->output);
p = strstr(intermed, ".obj");
if (p)
{
CompileMessage("Compiling", list->name);
nasmFlag = (x->buildFlags &BF_COMPILEVIAASM) ? "/C+N " : "/c";
dbgFlag = (x->buildFlags &BF_DEBUGINFO) ? "+v" : "";
nasmdebugFlag = (x->buildFlags &BF_DEBUGINFO) ? "-Fls -g" : "";
browseFlag = (browseInfo) ? "/C+?" : "";
warningFlag = (x->buildFlags &BF_SHOWWARNINGS) ? "" : "/w-all";
c99Flag = (x->buildFlags &BF_C99) ? "/9" : "";
ansiFlag = (x->buildFlags &BF_ANSI) ? "+A" : "";
importFlag = (x->libType == LT_LSCRTDLL) ? "/Wgl" : "";
if (x->buildFlags &BF_COMPILEVIAASM)
strcpy(p, ".asm");
if (x->includePath[0])
sprintf(buffer, "%s %s %s %s %s %s %s %s \"-I%s\\include;%s;%s\"", x
->compileopts, nasmFlag, dbgFlag, browseFlag, warningFlag,
c99Flag, ansiFlag, importFlag, szInstallPath, projectPath, x->includePath);
else
sprintf(buffer, "%s %s %s %s %s %s %s %s \"-I%s\\include;%s\"", x
->compileopts, nasmFlag, dbgFlag, browseFlag, warningFlag,
c99Flag, ansiFlag, importFlag, szInstallPath, projectPath);
repdefines(x, buffer);
p = buffer + strlen(buffer);
sprintf(p, " \"-o%s\" \"%s\"", intermed, list->name);
fil = fopen(tempfile, "w");
fprintf(fil, "%s", buffer);
fclose(fil);
sprintf(working, "cc386 /f%s", tempfile);
rv = Execute("cc386.exe", working, ERR_BUILD_WINDOW);
unlink(tempfile);
if (rv)
return rv;
if (x->buildFlags &BF_COMPILEVIAASM)
{
buffer[0] = 0;
repdefines(x, buffer);
sprintf(buffer + strlen(buffer), " -s -fobj %s", nasmdebugFlag);
fil = fopen(tempfile, "w");
fprintf(fil, "%s", buffer);
fclose(fil);
sprintf(working, "nasm @%s -o \"%s\" \"%s\"", tempfile, list
->output, intermed);
rv = Execute("nasm.exe", working, ERR_BUILD_WINDOW);
unlink(tempfile);
return rv;
}
else
return rv;
}
return 1;
}
//-------------------------------------------------------------------------
int AssembleFile(PROJLIST *x, FILELIST *list)
{
char buffer[10000];
char working[300];
FILE *fil;
int rv;
char *nasmdebugFlag = (x->buildFlags &BF_DEBUGINFO) ? "-Fls -g" : "";
CompileMessage("Assembling", list->name);
buffer[0] = 0;
repdefines(x, buffer);
sprintf(buffer + strlen(buffer), " -s -fobj %s", nasmdebugFlag);
fil = fopen(tempfile, "w");
fprintf(fil, "%s", buffer);
fclose(fil);
sprintf(working, "nasm @%s -o \"%s\" \"%s\"", tempfile, list->output, list
->name);
rv = Execute("nasm.exe", working, ERR_BUILD_WINDOW);
unlink(tempfile);
return rv;
}
//-------------------------------------------------------------------------
int RCFile(PROJLIST *x, FILELIST *list)
{
char buffer[10000];
char working[300];
char projectPath[260], *p;
FILE *fil;
int rv;
strcpy(projectPath, x->name);
p = strrchr(projectPath, '\\');
if (p)
*(p + 1) = 0;
CompileMessage("Compiling Resources", list->name);
buffer[0] = 0;
repdefines(x, buffer);
if (x->includePath[0])
sprintf(buffer + strlen(buffer), " -r \"-i%s\\include;%s;%s\"",
szInstallPath, projectPath, x->includePath);
else
sprintf(buffer + strlen(buffer), " -r \"-i%s\\include;%s\"",
szInstallPath, projectPath);
fil = fopen(tempfile, "w");
fprintf(fil, "%s", buffer);
fclose(fil);
sprintf(working, "xrc @%s \"-fo%s\" \"%s\"", tempfile, list->output, list
->name);
rv = Execute("xrc.exe", working, ERR_BUILD_WINDOW);
unlink(tempfile);
return rv;
}
//-------------------------------------------------------------------------
int scanfiles(PROJLIST *list, char *p, char *ext)
{
FILELIST *l = list->files;
int rv = 0;
while (l)
{
char *x = strrchr(l->output, '.');
if (x && !xstricmpz(x, ext))
{
sprintf(p + rv, "\"%s\" ", l->output);
rv += strlen(p + rv);
}
l = l->next;
}
return rv;
}
//-------------------------------------------------------------------------
int linkFile(PROJLIST *list)
{
char buf[100000], *p;
char drive[10], dir[256], file[256], ext[256];
FILE *tempfil;
int rv;
CompileMessage("Linking", "");
tempfil = fopen(tempfile, "w");
_splitpath(list->name, drive, dir, file, ext);
sprintf(buf, "valx -Nci -32 ");
p = buf + strlen(buf);
if (list->buildFlags &BF_MAPFILE)
{
strcpy(p, "-MP ");
p += strlen(p);
}
if (list->buildFlags &BF_DEBUGINFO)
{
strcpy(p, "-DEB ");
p += strlen(p);
}
switch (list->buildType)
{
case BT_CONSOLE:
sprintf(p, "-PE -CON @%s", tempfile);
if (list->libType != LT_NONE)
if (list->libType == LT_LSCRTDLL)
fprintf(tempfil, "\"%s\\lib\\c0xdll.obj\" ", szInstallPath);
else
fprintf(tempfil, "\"%s\\lib\\c0xwin.obj\" ", szInstallPath);
break;
case BT_WINDOWS:
sprintf(p, "-PE -WIN @%s", tempfile);
if (list->libType != LT_NONE)
if (list->libType == LT_LSCRTDLL)
fprintf(tempfil, "\"%s\\lib\\c0dll.obj\" ", szInstallPath);
else
fprintf(tempfil, "\"%s\\lib\\c0win.obj\" ", szInstallPath);
break;
case BT_DLL:
sprintf(p, "-PE -BDL @%s", tempfile);
if (list->libType != LT_NONE)
if (list->libType == LT_LSCRTDLL)
fprintf(tempfil, "\"%s\\lib\\c0ddll.obj\" ", szInstallPath);
else
fprintf(tempfil, "\"%s\\lib\\c0dwin.obj\" ", szInstallPath);
break;
case BT_DOS:
sprintf(p, "-LX @%s", tempfile);
if (list->libType != LT_NONE)
fprintf(tempfil, "\"%s\\lib\\c0dosw.obj\" ", szInstallPath);
break;
case BT_RAW:
sprintf(p, "-SY @%s", tempfile);
if (list->libType != LT_NONE)
fprintf(tempfil, "\"%s\\lib\\c0dosw.obj\" ", szInstallPath);
break;
}
p += strlen(p) + 1;
p[0] = 0;
scanfiles(list, p, ".obj");
fprintf(tempfil, "%s %s\n\"%s\"\n", list->linkopts, p, list->name);
if (list->buildFlags &BF_MAPFILE)
{
fprintf(tempfil, "\"%s\"\n", file);
}
else
fprintf(tempfil, "\n");
p[0] = 0;
scanfiles(list, p, ".lib");
fprintf(tempfil, "%s", p);
if (list->buildType == BT_DOS)
if (list->libType == LT_STANDARD)
fprintf(tempfil, "\"%s\\lib\\cldos.lib\"\n\n\n", szInstallPath);
else
fprintf(tempfil, "\n\n\n");
else
{
if (list->libType == LT_CRTDLL)
fprintf(tempfil,
"\"%s\\lib\\climp.lib\" \"%s\\lib\\crtdll.lib\"\n",
szInstallPath, szInstallPath);
else if (list->libType == LT_STANDARD)
fprintf(tempfil,
"\"%s\\lib\\clwin.lib\" \"%s\\lib\\climp.lib\"\n",
szInstallPath, szInstallPath);
else if (list->libType == LT_LSCRTDLL)
fprintf(tempfil,
"\"%s\\lib\\lscrtl.lib\" \"%s\\lib\\climp.lib\"\n",
szInstallPath, szInstallPath);
else
fprintf(tempfil, "\"%s\\lib\\climp.lib\"\n", szInstallPath);
p[0] = 0;
scanfiles(list, p, ".res");
if (*p)
fprintf(tempfil, "%s\n\n", p);
else
fputc('\n', tempfil);
}
fclose(tempfil);
rv = Execute("valx.exe", buf, ERR_BUILD_WINDOW);
unlink(tempfile);
return rv;
}
//-------------------------------------------------------------------------
int browseFile(PROJLIST *list)
{
FILE *tempfil;
int rv;
char buf[100000], *p = buf;
char filename[256], *q;
char cmd[256];
strcpy(filename, szProjectName);
q = strrchr(filename, '.');
if (q)
*q = 0;
else
{
SendMessage(hwndError, WM_SETTEXT, ERR_BUILD_WINDOW, (LPARAM)
"Internal Error...\r\n");
return 1;
}
CompileMessage("Creating Browse Information", "");
scanfiles(list, p, ".obj");
tempfil = fopen(tempfile, "w");
fputs(p, tempfil);
fclose(tempfil);
sprintf(cmd, "brc.exe \"%s\" @%s", filename, tempfile);
rv = Execute("brc.exe", cmd, ERR_BUILD_WINDOW);
fclose(tempfil);
unlink(tempfile);
SendMessage(hwndError, WM_SETTEXT, ERR_BUILD_WINDOW, (LPARAM)
"Build Complete\r\n");
return rv;
}
//-------------------------------------------------------------------------
int scanlibfiles(PROJLIST *list, char *p, char *ext)
{
FILELIST *l = list->files;
int rv = 0;
while (l)
{
char *x = strrchr(l->output, '.');
if (x && !xstricmpz(x, ext))
{
sprintf(p + rv, "+\"%s\" &\n", l->output);
rv += strlen(p + rv);
}
l = l->next;
}
return rv;
}
//-------------------------------------------------------------------------
int libFile(PROJLIST *list)
{
char buffer[100000], *p;
FILE *tempfil;
int rv;
unlink(list->name);
CompileMessage("Creating Library", "");
sprintf(buffer, "xlib \"%s\" %s @%s", list->name, list->libopts, tempfile);
p = buffer + strlen(buffer);
*p++ = 0;
scanlibfiles(list, p, ".obj");
tempfil = fopen(tempfile, "w");
fputs(p, tempfil);
fclose(tempfil);
rv = Execute("xlib.exe", buffer, ERR_BUILD_WINDOW);
unlink(tempfile);
return rv;
}
//-------------------------------------------------------------------------
int buildFile(PROJLIST *l, FILELIST *list)
{
char dirty[256], ext[100];
_splitpath(list->name, dirty, dirty, dirty, ext);
if (!xstricmpz(ext, ".c") || !xstricmpz(ext, ".cpp"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -