summaryrefslogtreecommitdiffstats
path: root/win/nmakehlp.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2005-11-04 00:06:49 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2005-11-04 00:06:49 (GMT)
commit1917d75e5fe50a58035bc8a2a47fdca8338ec9d7 (patch)
tree86211e81a05bc3c61493644f91017b9b65f71771 /win/nmakehlp.c
parent169a78358af41a6e77a814a0a73f663542c51a6f (diff)
downloadtcl-1917d75e5fe50a58035bc8a2a47fdca8338ec9d7.zip
tcl-1917d75e5fe50a58035bc8a2a47fdca8338ec9d7.tar.gz
tcl-1917d75e5fe50a58035bc8a2a47fdca8338ec9d7.tar.bz2
ANSIfy
Diffstat (limited to 'win/nmakehlp.c')
-rw-r--r--win/nmakehlp.c266
1 files changed, 187 insertions, 79 deletions
diff --git a/win/nmakehlp.c b/win/nmakehlp.c
index d1fb6b4..5b7a3b4 100644
--- a/win/nmakehlp.c
+++ b/win/nmakehlp.c
@@ -1,4 +1,5 @@
-/* ----------------------------------------------------------------------------
+/*
+ * ----------------------------------------------------------------------------
* nmakehlp.c --
*
* This is used to fix limitations within nmake and the environment.
@@ -9,9 +10,10 @@
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* ----------------------------------------------------------------------------
- * RCS: @(#) $Id: nmakehlp.c,v 1.8 2005/11/03 00:17:31 patthoyts Exp $
+ * RCS: @(#) $Id: nmakehlp.c,v 1.9 2005/11/04 00:06:49 dkf Exp $
* ----------------------------------------------------------------------------
*/
+
#include <windows.h>
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "kernel32.lib")
@@ -19,13 +21,15 @@
#include <math.h>
/* protos */
-int CheckForCompilerFeature (const char *option);
-int CheckForLinkerFeature (const char *option);
-int IsIn (const char *string, const char *substring);
-int GrepForDefine (const char *file, const char *string);
-DWORD WINAPI ReadFromPipe (LPVOID args);
+
+int CheckForCompilerFeature(const char *option);
+int CheckForLinkerFeature(const char *option);
+int IsIn(const char *string, const char *substring);
+int GrepForDefine(const char *file, const char *string);
+DWORD WINAPI ReadFromPipe(LPVOID args);
/* globals */
+
#define CHUNK 25
#define STATICBUFFERSIZE 1000
typedef struct {
@@ -35,21 +39,30 @@ typedef struct {
pipeinfo Out = {INVALID_HANDLE_VALUE, '\0'};
pipeinfo Err = {INVALID_HANDLE_VALUE, '\0'};
+
+/*
+ * exitcodes: 0 == no, 1 == yes, 2 == error
+ */
-
-
-/* exitcodes: 0 == no, 1 == yes, 2 == error */
int
-main (int argc, char *argv[])
+main(
+ int argc,
+ char *argv[])
{
char msg[300];
DWORD dwWritten;
int chars;
- /* make sure children (cl.exe and link.exe) are kept quiet. */
+ /*
+ * Make sure children (cl.exe and link.exe) are kept quiet.
+ */
+
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
- /* Make sure the compiler and linker aren't effected by the outside world. */
+ /*
+ * Make sure the compiler and linker aren't effected by the outside world.
+ */
+
SetEnvironmentVariable("CL", "");
SetEnvironmentVariable("LINK", "");
@@ -60,7 +73,8 @@ main (int argc, char *argv[])
chars = wsprintf(msg, "usage: %s -c <compiler option>\n"
"Tests for whether cl.exe supports an option\n"
"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 2;
}
return CheckForCompilerFeature(argv[2]);
@@ -69,19 +83,24 @@ main (int argc, char *argv[])
chars = wsprintf(msg, "usage: %s -l <linker option>\n"
"Tests for whether link.exe supports an option\n"
"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 2;
}
return CheckForLinkerFeature(argv[2]);
case 'f':
if (argc == 2) {
chars = wsprintf(msg, "usage: %s -f <string> <substring>\n"
- "Find a substring within another\n"
- "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ "Find a substring within another\n"
+ "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 2;
} else if (argc == 3) {
- /* if the string is blank, there is no match */
+ /*
+ * If the string is blank, there is no match.
+ */
+
return 0;
} else {
return IsIn(argv[2], argv[3]);
@@ -89,9 +108,11 @@ main (int argc, char *argv[])
case 'g':
if (argc == 2) {
chars = wsprintf(msg, "usage: %s -g <file> <string>\n"
- "grep for a #define\n"
- "exitcodes: integer of the found string (no decimals)\n", argv[0]);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
+ "grep for a #define\n"
+ "exitcodes: integer of the found string (no decimals)\n",
+ argv[0]);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
return 2;
}
return GrepForDefine(argv[2], argv[3]);
@@ -104,9 +125,10 @@ main (int argc, char *argv[])
WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
return 2;
}
-
+
int
-CheckForCompilerFeature (const char *option)
+CheckForCompilerFeature(
+ const char *option)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
@@ -130,23 +152,43 @@ CheckForCompilerFeature (const char *option)
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = FALSE;
- /* create a non-inheritible pipe. */
+ /*
+ * Create a non-inheritible pipe.
+ */
+
CreatePipe(&Out.pipe, &h, &sa, 0);
- /* dupe the write side, make it inheritible, and close the original. */
- DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ /*
+ * Dupe the write side, make it inheritible, and close the original.
+ */
+
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+ /*
+ * Same as above, but for the error side.
+ */
- /* Same as above, but for the error side. */
CreatePipe(&Err.pipe, &h, &sa, 0);
- DuplicateHandle(hProcess, h, hProcess, &si.hStdError,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+ /*
+ * Base command line.
+ */
- /* base command line */
strcpy(cmdline, "cl.exe -nologo -c -TC -Zs -X ");
- /* append our option for testing */
+
+ /*
+ * Append our option for testing
+ */
+
strcat(cmdline, option);
- /* filename to compile, which exists, but is nothing and empty. */
+
+ /*
+ * Filename to compile, which exists, but is nothing and empty.
+ */
+
strcat(cmdline, " .\\nul");
ok = CreateProcess(
@@ -163,46 +205,62 @@ CheckForCompilerFeature (const char *option)
if (!ok) {
DWORD err = GetLastError();
- int chars = wsprintf(msg, "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+ int chars = wsprintf(msg,
+ "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID) &msg[chars],
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
+ FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
(300-chars), 0);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, strlen(msg), &err, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, strlen(msg), &err,NULL);
return 2;
}
- /* close our references to the write handles that have now been inherited. */
+ /*
+ * Close our references to the write handles that have now been inherited.
+ */
+
CloseHandle(si.hStdOutput);
CloseHandle(si.hStdError);
WaitForInputIdle(pi.hProcess, 5000);
CloseHandle(pi.hThread);
- /* start the pipe reader threads. */
+ /*
+ * Start the pipe reader threads.
+ */
+
pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
- /* block waiting for the process to end. */
+ /*
+ * Block waiting for the process to end.
+ */
+
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
- /* wait for our pipe to get done reading, should it be a little slow. */
+ /*
+ * Wait for our pipe to get done reading, should it be a little slow.
+ */
+
WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
CloseHandle(pipeThreads[0]);
CloseHandle(pipeThreads[1]);
- /* look for the commandline warning code in both streams.
+ /*
+ * Look for the commandline warning code in both streams.
* - in MSVC 6 & 7 we get D4002, in MSVC 8 we get D9002.
*/
- return !(strstr(Out.buffer, "D4002") != NULL
+
+ return !(strstr(Out.buffer, "D4002") != NULL
|| strstr(Err.buffer, "D4002") != NULL
|| strstr(Out.buffer, "D9002") != NULL
|| strstr(Err.buffer, "D9002") != NULL);
}
-
+
int
-CheckForLinkerFeature (const char *option)
+CheckForLinkerFeature(
+ const char *option)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
@@ -226,21 +284,37 @@ CheckForLinkerFeature (const char *option)
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
- /* create a non-inheritible pipe. */
+ /*
+ * Create a non-inheritible pipe.
+ */
+
CreatePipe(&Out.pipe, &h, &sa, 0);
- /* dupe the write side, make it inheritible, and close the original. */
- DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ /*
+ * Dupe the write side, make it inheritible, and close the original.
+ */
+
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+ /*
+ * Same as above, but for the error side.
+ */
- /* Same as above, but for the error side. */
CreatePipe(&Err.pipe, &h, &sa, 0);
- DuplicateHandle(hProcess, h, hProcess, &si.hStdError,
- 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+ DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
+ DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
+
+ /*
+ * Base command line.
+ */
- /* base command line */
strcpy(cmdline, "link.exe -nologo ");
- /* append our option for testing */
+
+ /*
+ * Append our option for testing.
+ */
+
strcat(cmdline, option);
ok = CreateProcess(
@@ -257,48 +331,66 @@ CheckForLinkerFeature (const char *option)
if (!ok) {
DWORD err = GetLastError();
- int chars = wsprintf(msg, "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
+ int chars = wsprintf(msg,
+ "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS |
- FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID) &msg[chars],
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
+ FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
(300-chars), 0);
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, strlen(msg), &err, NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, strlen(msg), &err,NULL);
return 2;
}
- /* close our references to the write handles that have now been inherited. */
+ /*
+ * Close our references to the write handles that have now been inherited.
+ */
+
CloseHandle(si.hStdOutput);
CloseHandle(si.hStdError);
WaitForInputIdle(pi.hProcess, 5000);
CloseHandle(pi.hThread);
- /* start the pipe reader threads. */
+ /*
+ * Start the pipe reader threads.
+ */
+
pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
- /* block waiting for the process to end. */
+ /*
+ * Block waiting for the process to end.
+ */
+
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
- /* wait for our pipe to get done reading, should it be a little slow. */
+ /*
+ * Wait for our pipe to get done reading, should it be a little slow.
+ */
+
WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
CloseHandle(pipeThreads[0]);
CloseHandle(pipeThreads[1]);
- /* look for the commandline warning code in the stderr stream. */
- return !(strstr(Out.buffer, "LNK1117") != NULL || strstr(Err.buffer, "LNK1117") != NULL);
-}
+ /*
+ * Look for the commandline warning code in the stderr stream.
+ */
+ return !(strstr(Out.buffer, "LNK1117") != NULL ||
+ strstr(Err.buffer, "LNK1117") != NULL);
+}
+
DWORD WINAPI
-ReadFromPipe (LPVOID args)
+ReadFromPipe(
+ LPVOID args)
{
pipeinfo *pi = (pipeinfo *) args;
char *lastBuf = pi->buffer;
DWORD dwRead;
BOOL ok;
-again:
+ again:
if (lastBuf - pi->buffer + CHUNK > STATICBUFFERSIZE) {
CloseHandle(pi->pipe);
return -1;
@@ -313,22 +405,25 @@ again:
return 0; /* makes the compiler happy */
}
-
+
int
-IsIn (const char *string, const char *substring)
+IsIn(
+ const char *string,
+ const char *substring)
{
return (strstr(string, substring) != NULL);
}
-
+
/*
- * Find a specified #define by name.
+ * Find a specified #define by name.
*
- * If the line is '#define TCL_VERSION "8.5"', it returns
- * 85 as the result.
+ * If the line is '#define TCL_VERSION "8.5"', it returns 85 as the result.
*/
int
-GrepForDefine (const char *file, const char *string)
+GrepForDefine(
+ const char *file,
+ const char *string)
{
FILE *f;
char s1[51], s2[51], s3[51];
@@ -343,13 +438,26 @@ GrepForDefine (const char *file, const char *string)
do {
r = fscanf(f, "%50s", s1);
if (r == 1 && !strcmp(s1, "#define")) {
- /* get next two words */
+ /*
+ * Get next two words.
+ */
+
r = fscanf(f, "%50s %50s", s2, s3);
- if (r != 2) continue;
- /* is the first word what we're looking for? */
+ if (r != 2) {
+ continue;
+ }
+
+ /*
+ * Is the first word what we're looking for?
+ */
+
if (!strcmp(s2, string)) {
fclose(f);
- /* add 1 past first double quote char. "8.5" */
+
+ /*
+ * Add 1 past first double quote char. "8.5"
+ */
+
d1 = atof(s3 + 1); /* 8.5 */
while (floor(d1) != d1) {
d1 *= 10.0;