]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Update the "nmakehlp.c" utility program sources associated with the TCL
authordrh <>
Tue, 15 Jun 2021 15:36:05 +0000 (15:36 +0000)
committerdrh <>
Tue, 15 Jun 2021 15:36:05 +0000 (15:36 +0000)
Extension Architecture, obtained from
[https://core.tcl-lang.org/sampleextension/file].  Perhaps this new
version will sit better with salmonx's static analyzer
[forum:/forumpost/7f0beca9797ee23a|(ref1)],
[forum:/forumpost/7d5c8b19231ad57f|(ref2)].

FossilOrigin-Name: 603b851d7d923d71543760b09a55d72dbbc185ac9c353c954c331c0454992c80

autoconf/tea/win/nmakehlp.c
manifest
manifest.uuid

index e00f1b49965d07d0ac4862354131776bdaf714eb..7536edee33455deaee64028195b4a1aee9bc06a4 100644 (file)
 
 #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>
 
 #endif
 
 
-
 /* protos */
 
 static int CheckForCompilerFeature(const char *option);
-static int CheckForLinkerFeature(const char *option);
+static int CheckForLinkerFeature(const char **options, int count);
 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 int LocateDependency(const char *keyfile);
+static const char *GetVersionFromFile(const char *filename, const char *match, int numdots);
 static DWORD WINAPI ReadFromPipe(LPVOID args);
 
 /* globals */
@@ -74,6 +69,7 @@ main(
     char msg[300];
     DWORD dwWritten;
     int chars;
+    const char *s;
 
     /*
      * Make sure children (cl.exe and link.exe) are kept quiet.
@@ -102,16 +98,16 @@ main(
            }
            return CheckForCompilerFeature(argv[2]);
        case 'l':
-           if (argc != 3) {
+           if (argc < 3) {
                chars = snprintf(msg, sizeof(msg) - 1,
-                       "usage: %s -l <linker option>\n"
+                       "usage: %s -l <linker option> ?<mandatory 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);
                return 2;
            }
-           return CheckForLinkerFeature(argv[2]);
+           return CheckForLinkerFeature(&argv[2], argc-2);
        case 'f':
            if (argc == 2) {
                chars = snprintf(msg, sizeof(msg) - 1,
@@ -153,8 +149,13 @@ main(
                    &dwWritten, NULL);
                return 0;
            }
-           printf("%s\n", GetVersionFromFile(argv[2], argv[3]));
-           return 0;
+           s = GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0');
+           if (s && *s) {
+               printf("%s\n", s);
+               return 0;
+           } else
+               return 1; /* Version not found. Return non-0 exit code */
+
        case 'Q':
            if (argc != 3) {
                chars = snprintf(msg, sizeof(msg) - 1,
@@ -166,6 +167,18 @@ main(
                return 2;
            }
            return QualifyPath(argv[2]);
+
+       case 'L':
+           if (argc != 3) {
+               chars = snprintf(msg, sizeof(msg) - 1,
+                   "usage: %s -L keypath\n"
+                   "Emit the fully qualified path of directory containing keypath\n"
+                   "exitcodes: 0 == success, 1 == not found, 2 == error\n", argv[0]);
+               WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
+                   &dwWritten, NULL);
+               return 2;
+           }
+           return LocateDependency(argv[2]);
        }
     }
     chars = snprintf(msg, sizeof(msg) - 1,
@@ -313,7 +326,8 @@ CheckForCompilerFeature(
 \f
 static int
 CheckForLinkerFeature(
-    const char *option)
+    const char **options,
+    int count)
 {
     STARTUPINFO si;
     PROCESS_INFORMATION pi;
@@ -322,7 +336,8 @@ CheckForLinkerFeature(
     char msg[300];
     BOOL ok;
     HANDLE hProcess, h, pipeThreads[2];
-    char cmdline[100];
+    int i;
+    char cmdline[255];
 
     hProcess = GetCurrentProcess();
 
@@ -368,7 +383,11 @@ CheckForLinkerFeature(
      * Append our option for testing.
      */
 
-    lstrcat(cmdline, option);
+    for (i = 0; i < count; i++) {
+       lstrcat(cmdline, " \"");
+       lstrcat(cmdline, options[i]);
+       lstrcat(cmdline, "\"");
+    }
 
     ok = CreateProcess(
            NULL,           /* Module name. */
@@ -433,7 +452,9 @@ CheckForLinkerFeature(
     return !(strstr(Out.buffer, "LNK1117") != NULL ||
            strstr(Err.buffer, "LNK1117") != NULL ||
            strstr(Out.buffer, "LNK4044") != NULL ||
-           strstr(Err.buffer, "LNK4044") != NULL);
+           strstr(Err.buffer, "LNK4044") != NULL ||
+           strstr(Out.buffer, "LNK4224") != NULL ||
+           strstr(Err.buffer, "LNK4224") != NULL);
 }
 \f
 static DWORD WINAPI
@@ -479,7 +500,8 @@ IsIn(
 static const char *
 GetVersionFromFile(
     const char *filename,
-    const char *match)
+    const char *match,
+    int numdots)
 {
     size_t cbBuffer = 100;
     static char szBuffer[100];
@@ -497,9 +519,10 @@ GetVersionFromFile(
            p = strstr(szBuffer, match);
            if (p != NULL) {
                /*
-                * Skip to first digit.
+                * Skip to first digit after the match.
                 */
 
+               p += strlen(match);
                while (*p && !isdigit(*p)) {
                    ++p;
                }
@@ -509,7 +532,8 @@ GetVersionFromFile(
                 */
 
                q = p;
-               while (*q && (isalnum(*q) || *q == '.')) {
+               while (*q && (strchr("0123456789.ab", *q)) && ((!strchr(".ab", *q)
+                           && (!strchr("ab", q[-1])) || --numdots))) {
                    ++q;
                }
 
@@ -619,7 +643,7 @@ SubstituteFile(
        }
 
        /* debug: dump the list */
-#ifdef _DEBUG
+#ifndef NDEBUG
        {
            int n = 0;
            list_item_t *p = NULL;
@@ -628,11 +652,11 @@ SubstituteFile(
            }
        }
 #endif
-       
+
        /*
         * Run the substitutions over each line of the input
         */
-       
+
        while (fgets(szBuffer, cbBuffer, fp) != NULL) {
            list_item_t *p = NULL;
            for (p = substPtr; p != NULL; p = p->nextPtr) {
@@ -652,13 +676,24 @@ SubstituteFile(
            }
            printf(szBuffer);
        }
-       
+
        list_free(&substPtr);
     }
     fclose(fp);
     return 0;
 }
 \f
+BOOL FileExists(LPCTSTR szPath)
+{
+#ifndef INVALID_FILE_ATTRIBUTES
+    #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+#endif
+    DWORD pathAttr = GetFileAttributes(szPath);
+    return (pathAttr != INVALID_FILE_ATTRIBUTES &&
+           !(pathAttr & FILE_ATTRIBUTE_DIRECTORY));
+}
+\f
+
 /*
  * QualifyPath --
  *
@@ -672,17 +707,103 @@ 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);
+
+    GetFullPathName(szPath, sizeof(szCwd)-1, szCwd, NULL);
     printf("%s\n", szCwd);
     return 0;
 }
 
+/*
+ * Implements LocateDependency for a single directory. See that command
+ * for an explanation.
+ * Returns 0 if found after printing the directory.
+ * Returns 1 if not found but no errors.
+ * Returns 2 on any kind of error
+ * Basically, these are used as exit codes for the process.
+ */
+static int LocateDependencyHelper(const char *dir, const char *keypath)
+{
+    HANDLE hSearch;
+    char path[MAX_PATH+1];
+    int dirlen, keylen, ret;
+    WIN32_FIND_DATA finfo;
+
+    if (dir == NULL || keypath == NULL)
+       return 2; /* Have no real error reporting mechanism into nmake */
+    dirlen = strlen(dir);
+    if ((dirlen + 3) > sizeof(path))
+       return 2;
+    strncpy(path, dir, dirlen);
+    strncpy(path+dirlen, "\\*", 3);    /* Including terminating \0 */
+    keylen = strlen(keypath);
+
+#if 0 /* This function is not available in Visual C++ 6 */
+    /*
+     * Use numerics 0 -> FindExInfoStandard,
+     * 1 -> FindExSearchLimitToDirectories,
+     * as these are not defined in Visual C++ 6
+     */
+    hSearch = FindFirstFileEx(path, 0, &finfo, 1, NULL, 0);
+#else
+    hSearch = FindFirstFile(path, &finfo);
+#endif
+    if (hSearch == INVALID_HANDLE_VALUE)
+       return 1; /* Not found */
+
+    /* Loop through all subdirs checking if the keypath is under there */
+    ret = 1; /* Assume not found */
+    do {
+       int sublen;
+       /*
+        * We need to check it is a directory despite the
+        * FindExSearchLimitToDirectories in the above call. See SDK docs
+        */
+       if ((finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
+           continue;
+       sublen = strlen(finfo.cFileName);
+       if ((dirlen+1+sublen+1+keylen+1) > sizeof(path))
+           continue;           /* Path does not fit, assume not matched */
+       strncpy(path+dirlen+1, finfo.cFileName, sublen);
+       path[dirlen+1+sublen] = '\\';
+       strncpy(path+dirlen+1+sublen+1, keypath, keylen+1);
+       if (FileExists(path)) {
+           /* Found a match, print to stdout */
+           path[dirlen+1+sublen] = '\0';
+           QualifyPath(path);
+           ret = 0;
+           break;
+       }
+    } while (FindNextFile(hSearch, &finfo));
+    FindClose(hSearch);
+    return ret;
+}
+
+/*
+ * LocateDependency --
+ *
+ *     Locates a dependency for a package.
+ *        keypath - a relative path within the package directory
+ *          that is used to confirm it is the correct directory.
+ *     The search path for the package directory is currently only
+ *      the parent and grandparent of the current working directory.
+ *      If found, the command prints
+ *         name_DIRPATH=<full path of located directory>
+ *      and returns 0. If not found, does not print anything and returns 1.
+ */
+static int LocateDependency(const char *keypath)
+{
+    int i, ret;
+    static const char *paths[] = {"..", "..\\..", "..\\..\\.."};
+
+    for (i = 0; i < (sizeof(paths)/sizeof(paths[0])); ++i) {
+       ret = LocateDependencyHelper(paths[i], keypath);
+       if (ret == 0)
+           return ret;
+    }
+    return ret;
+}
+
+
 /*
  * Local variables:
  *   mode: c
index 6c3479e0b1a8697edb67ed68177467950deb93ba..5c040d1cdba1fe251ec3f3b1b7f82d7422aeca0c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sNULL\schecks\son\sall\ssqlite3_vfs_find(0)\scalls.\s\sThis\sis\snot\sstrictly\nnecessary.\s\sThere\sare\sno\svulnerabilities\shere.\s\sHowever,\sadding\sthese\nchecks\savoids\sunnecessary\sstatic\sanalyzer\scomplaints.\n[forum:/forumpost/ce1193be15|Forum\spost\sce1193be15].
-D 2021-06-15T15:15:40.609
+C Update\sthe\s"nmakehlp.c"\sutility\sprogram\ssources\sassociated\swith\sthe\sTCL\nExtension\sArchitecture,\sobtained\sfrom\n[https://core.tcl-lang.org/sampleextension/file].\s\sPerhaps\sthis\snew\nversion\swill\ssit\sbetter\swith\ssalmonx's\sstatic\sanalyzer\n[forum:/forumpost/7f0beca9797ee23a|(ref1)],\n[forum:/forumpost/7d5c8b19231ad57f|(ref2)].
+D 2021-06-15T15:36:05.310
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -29,7 +29,7 @@ F autoconf/tea/pkgIndex.tcl.in 3ef61715cf1c7bdcff56947ffadb26bc991ca39d
 F autoconf/tea/tclconfig/install-sh bdd5e293591621ae60d9824d86a4b1c5f22c3d00
 F autoconf/tea/tclconfig/tcl.m4 66ddf0a5d5e4b1d29bff472c0985fd7fa89d0fb5
 F autoconf/tea/win/makefile.vc a5ff708245260c2794c6aaa0151efe5403d5896566eaf096747be0d9075284e4
-F autoconf/tea/win/nmakehlp.c 247538ad8e8c508f33c03ec1fbd67d3a07ef6291
+F autoconf/tea/win/nmakehlp.c 190bf8b40f6f90eeb6cbc1e5c13a19fc7ad870e479e0314c88174f71bf9e28a7
 F autoconf/tea/win/rules.vc c511f222b80064096b705dbeb97060ee1d6b6d63
 F config.guess 883205ddf25b46f10c181818bf42c09da9888884af96f79e1719264345053bd6
 F config.h.in 6376abec766e9a0785178b1823b5a587e9f1ccbc
@@ -1918,7 +1918,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 829343c26ed7b87fafc70de3369625209bad91e79bb7ca2946d5c8d61cc1c3c4
-R 9aa6f2e0346815fa6d5daf16e2359ae5
+P 272a15b9f418fb0b31a9808f7c42c20cf52318035ff98935d8e8519634357e8d
+R 097386e0f9bf33b02f625d198897ad8a
 U drh
-Z 993cbec21430496a6c026bc47f824357
+Z 29173b5fde864001fb27d15e020c7b34
index 2fbcda8cbf587f6d4ae6f3bb00873df43ad3ff11..9402113a6f375d1d0712b013c40fbcbe9a63b222 100644 (file)
@@ -1 +1 @@
-272a15b9f418fb0b31a9808f7c42c20cf52318035ff98935d8e8519634357e8d
\ No newline at end of file
+603b851d7d923d71543760b09a55d72dbbc185ac9c353c954c331c0454992c80
\ No newline at end of file