summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-31 10:33:29 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-07-31 10:33:29 (GMT)
commit885ed8e2dc2f2eb66d422eb4b56df906fda85a8d (patch)
treefc074c19ccb462f5049fa910d8b64b0ac631ac6b /win
parenta8b104c3b5ef5cf3721b20a37d48360b90f77a10 (diff)
parent517621a49a33a09a8f3e0a4519624b3f0af770fd (diff)
downloadtcl-885ed8e2dc2f2eb66d422eb4b56df906fda85a8d.zip
tcl-885ed8e2dc2f2eb66d422eb4b56df906fda85a8d.tar.gz
tcl-885ed8e2dc2f2eb66d422eb4b56df906fda85a8d.tar.bz2
Backport nmakehlp.c from Tcl 8.6, but add -Q option from sampleextension
Diffstat (limited to 'win')
-rw-r--r--win/nmakehlp.c145
1 files changed, 58 insertions, 87 deletions
diff --git a/win/nmakehlp.c b/win/nmakehlp.c
index f1b5f34..2868857 100644
--- a/win/nmakehlp.c
+++ b/win/nmakehlp.c
@@ -14,16 +14,21 @@
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
+#define NO_SHLWAPI_GDI
+#define NO_SHLWAPI_STREAM
+#define NO_SHLWAPI_REG
+#include <shlwapi.h>
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "kernel32.lib")
+#pragma comment (lib, "shlwapi.lib")
#include <stdio.h>
#include <math.h>
/*
- * This library is required for x64 builds with _some_ versions
+ * This library is required for x64 builds with _some_ versions of MSVC
*/
#if defined(_M_IA64) || defined(_M_AMD64)
-#if _MSC_FULL_VER > 140000000 && _MSC_FULL_VER <= 140040310
+#if _MSC_VER >= 1400 && _MSC_VER < 1500
#pragma comment(lib, "bufferoverflowU")
#endif
#endif
@@ -37,13 +42,13 @@
/* 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);
-int SubstituteFile(const char *substs, const char *filename);
-const char * GetVersionFromFile(const char *filename, const char *match);
-DWORD WINAPI ReadFromPipe(LPVOID args);
+static int CheckForCompilerFeature(const char *option);
+static int CheckForLinkerFeature(const char *option);
+static int IsIn(const char *string, const char *substring);
+static int SubstituteFile(const char *substs, const char *filename);
+static int QualifyPath(const char *path);
+static const char *GetVersionFromFile(const char *filename, const char *match);
+static DWORD WINAPI ReadFromPipe(LPVOID args);
/* globals */
@@ -125,18 +130,6 @@ main(
} else {
return IsIn(argv[2], argv[3]);
}
- case 'g':
- if (argc == 2) {
- chars = snprintf(msg, sizeof(msg) - 1,
- "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);
- return 2;
- }
- return GrepForDefine(argv[2], argv[3]);
case 's':
if (argc == 2) {
chars = snprintf(msg, sizeof(msg) - 1,
@@ -162,10 +155,21 @@ main(
}
printf("%s\n", GetVersionFromFile(argv[2], argv[3]));
return 0;
+ case 'Q':
+ if (argc != 3) {
+ chars = snprintf(msg, sizeof(msg) - 1,
+ "usage: %s -Q path\n"
+ "Emit the fully qualified path\n"
+ "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+ &dwWritten, NULL);
+ return 2;
+ }
+ return QualifyPath(argv[2]);
}
}
chars = snprintf(msg, sizeof(msg) - 1,
- "usage: %s -c|-l|-f|-g|-V ...\n"
+ "usage: %s -c|-f|-l|-Q|-s|-V ...\n"
"This is a little helper app to equalize shell differences between WinNT and\n"
"Win9x and get nmake.exe to accomplish its job.\n",
argv[0]);
@@ -173,7 +177,7 @@ main(
return 2;
}
-int
+static int
CheckForCompilerFeature(
const char *option)
{
@@ -258,7 +262,7 @@ CheckForCompilerFeature(
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,lstrlen(msg), &err,NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
return 2;
}
@@ -307,7 +311,7 @@ CheckForCompilerFeature(
|| strstr(Err.buffer, "D2021") != NULL);
}
-int
+static int
CheckForLinkerFeature(
const char *option)
{
@@ -386,7 +390,7 @@ CheckForLinkerFeature(
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,lstrlen(msg), &err,NULL);
+ WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
return 2;
}
@@ -432,7 +436,7 @@ CheckForLinkerFeature(
strstr(Err.buffer, "LNK4044") != NULL);
}
-DWORD WINAPI
+static DWORD WINAPI
ReadFromPipe(
LPVOID args)
{
@@ -457,7 +461,7 @@ ReadFromPipe(
return 0; /* makes the compiler happy */
}
-int
+static int
IsIn(
const char *string,
const char *substring)
@@ -466,70 +470,13 @@ IsIn(
}
/*
- * Find a specified #define by name.
- *
- * If the line is '#define TCL_VERSION "8.5"', it returns 85 as the result.
- */
-
-int
-GrepForDefine(
- const char *file,
- const char *string)
-{
- char s1[51], s2[51], s3[51];
- FILE *f = fopen(file, "rt");
-
- if (f == NULL) {
- return 0;
- }
-
- do {
- int r = fscanf(f, "%50s", s1);
-
- if (r == 1 && !strcmp(s1, "#define")) {
- /*
- * 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 (!strcmp(s2, string)) {
- double d1;
-
- fclose(f);
-
- /*
- * Add 1 past first double quote char. "8.5"
- */
-
- d1 = atof(s3 + 1); /* 8.5 */
- while (floor(d1) != d1) {
- d1 *= 10.0;
- }
- return ((int) d1); /* 85 */
- }
- }
- } while (!feof(f));
-
- fclose(f);
- return 0;
-}
-
-/*
* GetVersionFromFile --
* Looks for a match string in a file and then returns the version
* following the match where a version is anything acceptable to
* package provide or package ifneeded.
*/
-const char *
+static const char *
GetVersionFromFile(
const char *filename,
const char *match)
@@ -635,7 +582,7 @@ list_free(list_item_t **listPtrPtr)
* <<
*/
-int
+static int
SubstituteFile(
const char *substitutions,
const char *filename)
@@ -711,6 +658,30 @@ SubstituteFile(
fclose(fp);
return 0;
}
+
+/*
+ * QualifyPath --
+ *
+ * This composes the current working directory with a provided path
+ * and returns the fully qualified and normalized path.
+ * Mostly needed to setup paths for testing.
+ */
+
+static int
+QualifyPath(
+ const char *szPath)
+{
+ char szCwd[MAX_PATH + 1];
+ char szTmp[MAX_PATH + 1];
+ char *p;
+ GetCurrentDirectory(MAX_PATH, szCwd);
+ while ((p = strchr(szPath, '/')) && *p)
+ *p = '\\';
+ PathCombine(szTmp, szCwd, szPath);
+ PathCanonicalize(szCwd, szTmp);
+ printf("%s\n", szCwd);
+ return 0;
+}
/*
* Local variables: