sqlmath 0.0.1 → 2021.11.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.npmignore +10 -0
  2. package/CHANGELOG.md +53 -2
  3. package/LICENSE +16 -22
  4. package/README.md +18 -219
  5. package/_binary_sqlmath_napi8_darwin_x64.node +0 -0
  6. package/_binary_sqlmath_napi8_linux_x64.node +0 -0
  7. package/_binary_sqlmath_napi8_win32_x64.node +0 -0
  8. package/jslint.mjs +10998 -0
  9. package/package.json +23 -8
  10. package/sqlmath.mjs +1713 -0
  11. package/.gitconfig +0 -25
  12. package/.github/workflows/ci.yml +0 -61
  13. package/.gitignore +0 -24
  14. package/extension-functions.c +0 -2047
  15. package/jslint_ci.sh +0 -1968
  16. package/node_sqlite3.cc +0 -11877
  17. package/sqlite-autoconf-3360000/INSTALL +0 -370
  18. package/sqlite-autoconf-3360000/Makefile.am +0 -20
  19. package/sqlite-autoconf-3360000/Makefile.fallback +0 -19
  20. package/sqlite-autoconf-3360000/Makefile.in +0 -1028
  21. package/sqlite-autoconf-3360000/Makefile.msc +0 -1037
  22. package/sqlite-autoconf-3360000/README.txt +0 -113
  23. package/sqlite-autoconf-3360000/Replace.cs +0 -223
  24. package/sqlite-autoconf-3360000/aclocal.m4 +0 -10199
  25. package/sqlite-autoconf-3360000/compile +0 -347
  26. package/sqlite-autoconf-3360000/config.guess +0 -1480
  27. package/sqlite-autoconf-3360000/config.sub +0 -1801
  28. package/sqlite-autoconf-3360000/configure +0 -16135
  29. package/sqlite-autoconf-3360000/configure.ac +0 -285
  30. package/sqlite-autoconf-3360000/depcomp +0 -791
  31. package/sqlite-autoconf-3360000/install-sh +0 -508
  32. package/sqlite-autoconf-3360000/ltmain.sh +0 -11156
  33. package/sqlite-autoconf-3360000/missing +0 -215
  34. package/sqlite-autoconf-3360000/shell.c +0 -22381
  35. package/sqlite-autoconf-3360000/sqlite3.1 +0 -286
  36. package/sqlite-autoconf-3360000/sqlite3.c +0 -235517
  37. package/sqlite-autoconf-3360000/sqlite3.h +0 -12353
  38. package/sqlite-autoconf-3360000/sqlite3.pc.in +0 -13
  39. package/sqlite-autoconf-3360000/sqlite3.rc +0 -83
  40. package/sqlite-autoconf-3360000/sqlite3ext.h +0 -663
  41. package/sqlite-autoconf-3360000/sqlite3rc.h +0 -3
  42. package/sqlite-autoconf-3360000/tea/Makefile.in +0 -440
  43. package/sqlite-autoconf-3360000/tea/README +0 -36
  44. package/sqlite-autoconf-3360000/tea/aclocal.m4 +0 -9
  45. package/sqlite-autoconf-3360000/tea/configure +0 -9989
  46. package/sqlite-autoconf-3360000/tea/configure.ac +0 -201
  47. package/sqlite-autoconf-3360000/tea/doc/sqlite3.n +0 -15
  48. package/sqlite-autoconf-3360000/tea/generic/tclsqlite3.c +0 -4016
  49. package/sqlite-autoconf-3360000/tea/license.terms +0 -6
  50. package/sqlite-autoconf-3360000/tea/pkgIndex.tcl.in +0 -7
  51. package/sqlite-autoconf-3360000/tea/tclconfig/install-sh +0 -528
  52. package/sqlite-autoconf-3360000/tea/tclconfig/tcl.m4 +0 -4168
  53. package/sqlite-autoconf-3360000/tea/win/makefile.vc +0 -419
  54. package/sqlite-autoconf-3360000/tea/win/nmakehlp.c +0 -815
  55. package/sqlite-autoconf-3360000/tea/win/rules.vc +0 -711
  56. package/sqlmath.js +0 -238
  57. package/test/backup.test.js +0 -279
  58. package/test/blob.test.js +0 -54
  59. package/test/cache.test.js +0 -42
  60. package/test/constants.test.js +0 -44
  61. package/test/database_fail.test.js +0 -153
  62. package/test/each.test.js +0 -39
  63. package/test/exec.test.js +0 -39
  64. package/test/extension.test.js +0 -26
  65. package/test/extension_functions.test.js +0 -29
  66. package/test/fts-content.test.js +0 -13
  67. package/test/interrupt.test.js +0 -80
  68. package/test/issue-108.test.js +0 -28
  69. package/test/json.test.js +0 -22
  70. package/test/map.test.js +0 -63
  71. package/test/named_columns.test.js +0 -38
  72. package/test/named_params.test.js +0 -69
  73. package/test/null_error.test.js +0 -41
  74. package/test/nw/.gitignore +0 -3
  75. package/test/nw/Makefile +0 -39
  76. package/test/nw/index.html +0 -14
  77. package/test/nw/package.json +0 -9
  78. package/test/open_close.test.js +0 -187
  79. package/test/other_objects.test.js +0 -98
  80. package/test/parallel_insert.test.js +0 -44
  81. package/test/prepare.test.js +0 -427
  82. package/test/profile.test.js +0 -57
  83. package/test/rerun.test.js +0 -50
  84. package/test/scheduling.test.js +0 -44
  85. package/test/serialization.test.js +0 -104
  86. package/test/support/createdb-electron.js +0 -10
  87. package/test/support/createdb.js +0 -47
  88. package/test/support/elmo.png +0 -0
  89. package/test/support/helper.js +0 -37
  90. package/test/support/script.sql +0 -70
  91. package/test/trace.test.js +0 -67
  92. package/test/unicode.test.js +0 -114
  93. package/test/upsert.test.js +0 -27
  94. package/test/verbose.test.js +0 -60
  95. package/test.js +0 -141
  96. package/test.slr.mjs +0 -212
@@ -1,815 +0,0 @@
1
- /*
2
- * ----------------------------------------------------------------------------
3
- * nmakehlp.c --
4
- *
5
- * This is used to fix limitations within nmake and the environment.
6
- *
7
- * Copyright (c) 2002 by David Gravereaux.
8
- * Copyright (c) 2006 by Pat Thoyts
9
- *
10
- * See the file "license.terms" for information on usage and redistribution of
11
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
- * ----------------------------------------------------------------------------
13
- */
14
-
15
- #define _CRT_SECURE_NO_DEPRECATE
16
- #include <windows.h>
17
- #pragma comment (lib, "user32.lib")
18
- #pragma comment (lib, "kernel32.lib")
19
- #include <stdio.h>
20
- #include <math.h>
21
-
22
- /*
23
- * This library is required for x64 builds with _some_ versions of MSVC
24
- */
25
- #if defined(_M_IA64) || defined(_M_AMD64)
26
- #if _MSC_VER >= 1400 && _MSC_VER < 1500
27
- #pragma comment(lib, "bufferoverflowU")
28
- #endif
29
- #endif
30
-
31
- /* ISO hack for dumb VC++ */
32
- #ifdef _MSC_VER
33
- #define snprintf _snprintf
34
- #endif
35
-
36
-
37
- /* protos */
38
-
39
- static int CheckForCompilerFeature(const char *option);
40
- static int CheckForLinkerFeature(const char **options, int count);
41
- static int IsIn(const char *string, const char *substring);
42
- static int SubstituteFile(const char *substs, const char *filename);
43
- static int QualifyPath(const char *path);
44
- static int LocateDependency(const char *keyfile);
45
- static const char *GetVersionFromFile(const char *filename, const char *match, int numdots);
46
- static DWORD WINAPI ReadFromPipe(LPVOID args);
47
-
48
- /* globals */
49
-
50
- #define CHUNK 25
51
- #define STATICBUFFERSIZE 1000
52
- typedef struct {
53
- HANDLE pipe;
54
- char buffer[STATICBUFFERSIZE];
55
- } pipeinfo;
56
-
57
- pipeinfo Out = {INVALID_HANDLE_VALUE, '\0'};
58
- pipeinfo Err = {INVALID_HANDLE_VALUE, '\0'};
59
-
60
- /*
61
- * exitcodes: 0 == no, 1 == yes, 2 == error
62
- */
63
-
64
- int
65
- main(
66
- int argc,
67
- char *argv[])
68
- {
69
- char msg[300];
70
- DWORD dwWritten;
71
- int chars;
72
- const char *s;
73
-
74
- /*
75
- * Make sure children (cl.exe and link.exe) are kept quiet.
76
- */
77
-
78
- SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
79
-
80
- /*
81
- * Make sure the compiler and linker aren't effected by the outside world.
82
- */
83
-
84
- SetEnvironmentVariable("CL", "");
85
- SetEnvironmentVariable("LINK", "");
86
-
87
- if (argc > 1 && *argv[1] == '-') {
88
- switch (*(argv[1]+1)) {
89
- case 'c':
90
- if (argc != 3) {
91
- chars = snprintf(msg, sizeof(msg) - 1,
92
- "usage: %s -c <compiler option>\n"
93
- "Tests for whether cl.exe supports an option\n"
94
- "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
95
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
96
- &dwWritten, NULL);
97
- return 2;
98
- }
99
- return CheckForCompilerFeature(argv[2]);
100
- case 'l':
101
- if (argc < 3) {
102
- chars = snprintf(msg, sizeof(msg) - 1,
103
- "usage: %s -l <linker option> ?<mandatory option> ...?\n"
104
- "Tests for whether link.exe supports an option\n"
105
- "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
106
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
107
- &dwWritten, NULL);
108
- return 2;
109
- }
110
- return CheckForLinkerFeature(&argv[2], argc-2);
111
- case 'f':
112
- if (argc == 2) {
113
- chars = snprintf(msg, sizeof(msg) - 1,
114
- "usage: %s -f <string> <substring>\n"
115
- "Find a substring within another\n"
116
- "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
117
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
118
- &dwWritten, NULL);
119
- return 2;
120
- } else if (argc == 3) {
121
- /*
122
- * If the string is blank, there is no match.
123
- */
124
-
125
- return 0;
126
- } else {
127
- return IsIn(argv[2], argv[3]);
128
- }
129
- case 's':
130
- if (argc == 2) {
131
- chars = snprintf(msg, sizeof(msg) - 1,
132
- "usage: %s -s <substitutions file> <file>\n"
133
- "Perform a set of string map type substutitions on a file\n"
134
- "exitcodes: 0\n",
135
- argv[0]);
136
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
137
- &dwWritten, NULL);
138
- return 2;
139
- }
140
- return SubstituteFile(argv[2], argv[3]);
141
- case 'V':
142
- if (argc != 4) {
143
- chars = snprintf(msg, sizeof(msg) - 1,
144
- "usage: %s -V filename matchstring\n"
145
- "Extract a version from a file:\n"
146
- "eg: pkgIndex.tcl \"package ifneeded http\"",
147
- argv[0]);
148
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
149
- &dwWritten, NULL);
150
- return 0;
151
- }
152
- s = GetVersionFromFile(argv[2], argv[3], *(argv[1]+2) - '0');
153
- if (s && *s) {
154
- printf("%s\n", s);
155
- return 0;
156
- } else
157
- return 1; /* Version not found. Return non-0 exit code */
158
-
159
- case 'Q':
160
- if (argc != 3) {
161
- chars = snprintf(msg, sizeof(msg) - 1,
162
- "usage: %s -Q path\n"
163
- "Emit the fully qualified path\n"
164
- "exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
165
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
166
- &dwWritten, NULL);
167
- return 2;
168
- }
169
- return QualifyPath(argv[2]);
170
-
171
- case 'L':
172
- if (argc != 3) {
173
- chars = snprintf(msg, sizeof(msg) - 1,
174
- "usage: %s -L keypath\n"
175
- "Emit the fully qualified path of directory containing keypath\n"
176
- "exitcodes: 0 == success, 1 == not found, 2 == error\n", argv[0]);
177
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
178
- &dwWritten, NULL);
179
- return 2;
180
- }
181
- return LocateDependency(argv[2]);
182
- }
183
- }
184
- chars = snprintf(msg, sizeof(msg) - 1,
185
- "usage: %s -c|-f|-l|-Q|-s|-V ...\n"
186
- "This is a little helper app to equalize shell differences between WinNT and\n"
187
- "Win9x and get nmake.exe to accomplish its job.\n",
188
- argv[0]);
189
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars, &dwWritten, NULL);
190
- return 2;
191
- }
192
-
193
- static int
194
- CheckForCompilerFeature(
195
- const char *option)
196
- {
197
- STARTUPINFO si;
198
- PROCESS_INFORMATION pi;
199
- SECURITY_ATTRIBUTES sa;
200
- DWORD threadID;
201
- char msg[300];
202
- BOOL ok;
203
- HANDLE hProcess, h, pipeThreads[2];
204
- char cmdline[100];
205
-
206
- hProcess = GetCurrentProcess();
207
-
208
- ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
209
- ZeroMemory(&si, sizeof(STARTUPINFO));
210
- si.cb = sizeof(STARTUPINFO);
211
- si.dwFlags = STARTF_USESTDHANDLES;
212
- si.hStdInput = INVALID_HANDLE_VALUE;
213
-
214
- ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
215
- sa.nLength = sizeof(SECURITY_ATTRIBUTES);
216
- sa.lpSecurityDescriptor = NULL;
217
- sa.bInheritHandle = FALSE;
218
-
219
- /*
220
- * Create a non-inheritible pipe.
221
- */
222
-
223
- CreatePipe(&Out.pipe, &h, &sa, 0);
224
-
225
- /*
226
- * Dupe the write side, make it inheritible, and close the original.
227
- */
228
-
229
- DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
230
- DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
231
-
232
- /*
233
- * Same as above, but for the error side.
234
- */
235
-
236
- CreatePipe(&Err.pipe, &h, &sa, 0);
237
- DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
238
- DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
239
-
240
- /*
241
- * Base command line.
242
- */
243
-
244
- lstrcpy(cmdline, "cl.exe -nologo -c -TC -Zs -X -Fp.\\_junk.pch ");
245
-
246
- /*
247
- * Append our option for testing
248
- */
249
-
250
- lstrcat(cmdline, option);
251
-
252
- /*
253
- * Filename to compile, which exists, but is nothing and empty.
254
- */
255
-
256
- lstrcat(cmdline, " .\\nul");
257
-
258
- ok = CreateProcess(
259
- NULL, /* Module name. */
260
- cmdline, /* Command line. */
261
- NULL, /* Process handle not inheritable. */
262
- NULL, /* Thread handle not inheritable. */
263
- TRUE, /* yes, inherit handles. */
264
- DETACHED_PROCESS, /* No console for you. */
265
- NULL, /* Use parent's environment block. */
266
- NULL, /* Use parent's starting directory. */
267
- &si, /* Pointer to STARTUPINFO structure. */
268
- &pi); /* Pointer to PROCESS_INFORMATION structure. */
269
-
270
- if (!ok) {
271
- DWORD err = GetLastError();
272
- int chars = snprintf(msg, sizeof(msg) - 1,
273
- "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
274
-
275
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
276
- FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
277
- (300-chars), 0);
278
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
279
- return 2;
280
- }
281
-
282
- /*
283
- * Close our references to the write handles that have now been inherited.
284
- */
285
-
286
- CloseHandle(si.hStdOutput);
287
- CloseHandle(si.hStdError);
288
-
289
- WaitForInputIdle(pi.hProcess, 5000);
290
- CloseHandle(pi.hThread);
291
-
292
- /*
293
- * Start the pipe reader threads.
294
- */
295
-
296
- pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
297
- pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
298
-
299
- /*
300
- * Block waiting for the process to end.
301
- */
302
-
303
- WaitForSingleObject(pi.hProcess, INFINITE);
304
- CloseHandle(pi.hProcess);
305
-
306
- /*
307
- * Wait for our pipe to get done reading, should it be a little slow.
308
- */
309
-
310
- WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
311
- CloseHandle(pipeThreads[0]);
312
- CloseHandle(pipeThreads[1]);
313
-
314
- /*
315
- * Look for the commandline warning code in both streams.
316
- * - in MSVC 6 & 7 we get D4002, in MSVC 8 we get D9002.
317
- */
318
-
319
- return !(strstr(Out.buffer, "D4002") != NULL
320
- || strstr(Err.buffer, "D4002") != NULL
321
- || strstr(Out.buffer, "D9002") != NULL
322
- || strstr(Err.buffer, "D9002") != NULL
323
- || strstr(Out.buffer, "D2021") != NULL
324
- || strstr(Err.buffer, "D2021") != NULL);
325
- }
326
-
327
- static int
328
- CheckForLinkerFeature(
329
- const char **options,
330
- int count)
331
- {
332
- STARTUPINFO si;
333
- PROCESS_INFORMATION pi;
334
- SECURITY_ATTRIBUTES sa;
335
- DWORD threadID;
336
- char msg[300];
337
- BOOL ok;
338
- HANDLE hProcess, h, pipeThreads[2];
339
- int i;
340
- char cmdline[255];
341
-
342
- hProcess = GetCurrentProcess();
343
-
344
- ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
345
- ZeroMemory(&si, sizeof(STARTUPINFO));
346
- si.cb = sizeof(STARTUPINFO);
347
- si.dwFlags = STARTF_USESTDHANDLES;
348
- si.hStdInput = INVALID_HANDLE_VALUE;
349
-
350
- ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
351
- sa.nLength = sizeof(SECURITY_ATTRIBUTES);
352
- sa.lpSecurityDescriptor = NULL;
353
- sa.bInheritHandle = TRUE;
354
-
355
- /*
356
- * Create a non-inheritible pipe.
357
- */
358
-
359
- CreatePipe(&Out.pipe, &h, &sa, 0);
360
-
361
- /*
362
- * Dupe the write side, make it inheritible, and close the original.
363
- */
364
-
365
- DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
366
- DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
367
-
368
- /*
369
- * Same as above, but for the error side.
370
- */
371
-
372
- CreatePipe(&Err.pipe, &h, &sa, 0);
373
- DuplicateHandle(hProcess, h, hProcess, &si.hStdError, 0, TRUE,
374
- DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);
375
-
376
- /*
377
- * Base command line.
378
- */
379
-
380
- lstrcpy(cmdline, "link.exe -nologo ");
381
-
382
- /*
383
- * Append our option for testing.
384
- */
385
-
386
- for (i = 0; i < count; i++) {
387
- lstrcat(cmdline, " \"");
388
- lstrcat(cmdline, options[i]);
389
- lstrcat(cmdline, "\"");
390
- }
391
-
392
- ok = CreateProcess(
393
- NULL, /* Module name. */
394
- cmdline, /* Command line. */
395
- NULL, /* Process handle not inheritable. */
396
- NULL, /* Thread handle not inheritable. */
397
- TRUE, /* yes, inherit handles. */
398
- DETACHED_PROCESS, /* No console for you. */
399
- NULL, /* Use parent's environment block. */
400
- NULL, /* Use parent's starting directory. */
401
- &si, /* Pointer to STARTUPINFO structure. */
402
- &pi); /* Pointer to PROCESS_INFORMATION structure. */
403
-
404
- if (!ok) {
405
- DWORD err = GetLastError();
406
- int chars = snprintf(msg, sizeof(msg) - 1,
407
- "Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);
408
-
409
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
410
- FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
411
- (300-chars), 0);
412
- WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
413
- return 2;
414
- }
415
-
416
- /*
417
- * Close our references to the write handles that have now been inherited.
418
- */
419
-
420
- CloseHandle(si.hStdOutput);
421
- CloseHandle(si.hStdError);
422
-
423
- WaitForInputIdle(pi.hProcess, 5000);
424
- CloseHandle(pi.hThread);
425
-
426
- /*
427
- * Start the pipe reader threads.
428
- */
429
-
430
- pipeThreads[0] = CreateThread(NULL, 0, ReadFromPipe, &Out, 0, &threadID);
431
- pipeThreads[1] = CreateThread(NULL, 0, ReadFromPipe, &Err, 0, &threadID);
432
-
433
- /*
434
- * Block waiting for the process to end.
435
- */
436
-
437
- WaitForSingleObject(pi.hProcess, INFINITE);
438
- CloseHandle(pi.hProcess);
439
-
440
- /*
441
- * Wait for our pipe to get done reading, should it be a little slow.
442
- */
443
-
444
- WaitForMultipleObjects(2, pipeThreads, TRUE, 500);
445
- CloseHandle(pipeThreads[0]);
446
- CloseHandle(pipeThreads[1]);
447
-
448
- /*
449
- * Look for the commandline warning code in the stderr stream.
450
- */
451
-
452
- return !(strstr(Out.buffer, "LNK1117") != NULL ||
453
- strstr(Err.buffer, "LNK1117") != NULL ||
454
- strstr(Out.buffer, "LNK4044") != NULL ||
455
- strstr(Err.buffer, "LNK4044") != NULL ||
456
- strstr(Out.buffer, "LNK4224") != NULL ||
457
- strstr(Err.buffer, "LNK4224") != NULL);
458
- }
459
-
460
- static DWORD WINAPI
461
- ReadFromPipe(
462
- LPVOID args)
463
- {
464
- pipeinfo *pi = (pipeinfo *) args;
465
- char *lastBuf = pi->buffer;
466
- DWORD dwRead;
467
- BOOL ok;
468
-
469
- again:
470
- if (lastBuf - pi->buffer + CHUNK > STATICBUFFERSIZE) {
471
- CloseHandle(pi->pipe);
472
- return (DWORD)-1;
473
- }
474
- ok = ReadFile(pi->pipe, lastBuf, CHUNK, &dwRead, 0L);
475
- if (!ok || dwRead == 0) {
476
- CloseHandle(pi->pipe);
477
- return 0;
478
- }
479
- lastBuf += dwRead;
480
- goto again;
481
-
482
- return 0; /* makes the compiler happy */
483
- }
484
-
485
- static int
486
- IsIn(
487
- const char *string,
488
- const char *substring)
489
- {
490
- return (strstr(string, substring) != NULL);
491
- }
492
-
493
- /*
494
- * GetVersionFromFile --
495
- * Looks for a match string in a file and then returns the version
496
- * following the match where a version is anything acceptable to
497
- * package provide or package ifneeded.
498
- */
499
-
500
- static const char *
501
- GetVersionFromFile(
502
- const char *filename,
503
- const char *match,
504
- int numdots)
505
- {
506
- size_t cbBuffer = 100;
507
- static char szBuffer[100];
508
- char *szResult = NULL;
509
- FILE *fp = fopen(filename, "rt");
510
-
511
- if (fp != NULL) {
512
- /*
513
- * Read data until we see our match string.
514
- */
515
-
516
- while (fgets(szBuffer, cbBuffer, fp) != NULL) {
517
- LPSTR p, q;
518
-
519
- p = strstr(szBuffer, match);
520
- if (p != NULL) {
521
- /*
522
- * Skip to first digit after the match.
523
- */
524
-
525
- p += strlen(match);
526
- while (*p && !isdigit(*p)) {
527
- ++p;
528
- }
529
-
530
- /*
531
- * Find ending whitespace.
532
- */
533
-
534
- q = p;
535
- while (*q && (strchr("0123456789.ab", *q)) && ((!strchr(".ab", *q)
536
- && (!strchr("ab", q[-1])) || --numdots))) {
537
- ++q;
538
- }
539
-
540
- memcpy(szBuffer, p, q - p);
541
- szBuffer[q-p] = 0;
542
- szResult = szBuffer;
543
- break;
544
- }
545
- }
546
- fclose(fp);
547
- }
548
- return szResult;
549
- }
550
-
551
- /*
552
- * List helpers for the SubstituteFile function
553
- */
554
-
555
- typedef struct list_item_t {
556
- struct list_item_t *nextPtr;
557
- char * key;
558
- char * value;
559
- } list_item_t;
560
-
561
- /* insert a list item into the list (list may be null) */
562
- static list_item_t *
563
- list_insert(list_item_t **listPtrPtr, const char *key, const char *value)
564
- {
565
- list_item_t *itemPtr = malloc(sizeof(list_item_t));
566
- if (itemPtr) {
567
- itemPtr->key = strdup(key);
568
- itemPtr->value = strdup(value);
569
- itemPtr->nextPtr = NULL;
570
-
571
- while(*listPtrPtr) {
572
- listPtrPtr = &(*listPtrPtr)->nextPtr;
573
- }
574
- *listPtrPtr = itemPtr;
575
- }
576
- return itemPtr;
577
- }
578
-
579
- static void
580
- list_free(list_item_t **listPtrPtr)
581
- {
582
- list_item_t *tmpPtr, *listPtr = *listPtrPtr;
583
- while (listPtr) {
584
- tmpPtr = listPtr;
585
- listPtr = listPtr->nextPtr;
586
- free(tmpPtr->key);
587
- free(tmpPtr->value);
588
- free(tmpPtr);
589
- }
590
- }
591
-
592
- /*
593
- * SubstituteFile --
594
- * As windows doesn't provide anything useful like sed and it's unreliable
595
- * to use the tclsh you are building against (consider x-platform builds -
596
- * eg compiling AMD64 target from IX86) we provide a simple substitution
597
- * option here to handle autoconf style substitutions.
598
- * The substitution file is whitespace and line delimited. The file should
599
- * consist of lines matching the regular expression:
600
- * \s*\S+\s+\S*$
601
- *
602
- * Usage is something like:
603
- * nmakehlp -S << $** > $@
604
- * @PACKAGE_NAME@ $(PACKAGE_NAME)
605
- * @PACKAGE_VERSION@ $(PACKAGE_VERSION)
606
- * <<
607
- */
608
-
609
- static int
610
- SubstituteFile(
611
- const char *substitutions,
612
- const char *filename)
613
- {
614
- size_t cbBuffer = 1024;
615
- static char szBuffer[1024], szCopy[1024];
616
- char *szResult = NULL;
617
- list_item_t *substPtr = NULL;
618
- FILE *fp, *sp;
619
-
620
- fp = fopen(filename, "rt");
621
- if (fp != NULL) {
622
-
623
- /*
624
- * Build a list of substutitions from the first filename
625
- */
626
-
627
- sp = fopen(substitutions, "rt");
628
- if (sp != NULL) {
629
- while (fgets(szBuffer, cbBuffer, sp) != NULL) {
630
- unsigned char *ks, *ke, *vs, *ve;
631
- ks = (unsigned char*)szBuffer;
632
- while (ks && *ks && isspace(*ks)) ++ks;
633
- ke = ks;
634
- while (ke && *ke && !isspace(*ke)) ++ke;
635
- vs = ke;
636
- while (vs && *vs && isspace(*vs)) ++vs;
637
- ve = vs;
638
- while (ve && *ve && !(*ve == '\r' || *ve == '\n')) ++ve;
639
- *ke = 0, *ve = 0;
640
- list_insert(&substPtr, (char*)ks, (char*)vs);
641
- }
642
- fclose(sp);
643
- }
644
-
645
- /* debug: dump the list */
646
- #ifndef NDEBUG
647
- {
648
- int n = 0;
649
- list_item_t *p = NULL;
650
- for (p = substPtr; p != NULL; p = p->nextPtr, ++n) {
651
- fprintf(stderr, "% 3d '%s' => '%s'\n", n, p->key, p->value);
652
- }
653
- }
654
- #endif
655
-
656
- /*
657
- * Run the substitutions over each line of the input
658
- */
659
-
660
- while (fgets(szBuffer, cbBuffer, fp) != NULL) {
661
- list_item_t *p = NULL;
662
- for (p = substPtr; p != NULL; p = p->nextPtr) {
663
- char *m = strstr(szBuffer, p->key);
664
- if (m) {
665
- char *cp, *op, *sp;
666
- cp = szCopy;
667
- op = szBuffer;
668
- while (op != m) *cp++ = *op++;
669
- sp = p->value;
670
- while (sp && *sp) *cp++ = *sp++;
671
- op += strlen(p->key);
672
- while (*op) *cp++ = *op++;
673
- *cp = 0;
674
- memcpy(szBuffer, szCopy, sizeof(szCopy));
675
- }
676
- }
677
- printf(szBuffer);
678
- }
679
-
680
- list_free(&substPtr);
681
- }
682
- fclose(fp);
683
- return 0;
684
- }
685
-
686
- BOOL FileExists(LPCTSTR szPath)
687
- {
688
- #ifndef INVALID_FILE_ATTRIBUTES
689
- #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
690
- #endif
691
- DWORD pathAttr = GetFileAttributes(szPath);
692
- return (pathAttr != INVALID_FILE_ATTRIBUTES &&
693
- !(pathAttr & FILE_ATTRIBUTE_DIRECTORY));
694
- }
695
-
696
-
697
- /*
698
- * QualifyPath --
699
- *
700
- * This composes the current working directory with a provided path
701
- * and returns the fully qualified and normalized path.
702
- * Mostly needed to setup paths for testing.
703
- */
704
-
705
- static int
706
- QualifyPath(
707
- const char *szPath)
708
- {
709
- char szCwd[MAX_PATH + 1];
710
-
711
- GetFullPathName(szPath, sizeof(szCwd)-1, szCwd, NULL);
712
- printf("%s\n", szCwd);
713
- return 0;
714
- }
715
-
716
- /*
717
- * Implements LocateDependency for a single directory. See that command
718
- * for an explanation.
719
- * Returns 0 if found after printing the directory.
720
- * Returns 1 if not found but no errors.
721
- * Returns 2 on any kind of error
722
- * Basically, these are used as exit codes for the process.
723
- */
724
- static int LocateDependencyHelper(const char *dir, const char *keypath)
725
- {
726
- HANDLE hSearch;
727
- char path[MAX_PATH+1];
728
- int dirlen, keylen, ret;
729
- WIN32_FIND_DATA finfo;
730
-
731
- if (dir == NULL || keypath == NULL)
732
- return 2; /* Have no real error reporting mechanism into nmake */
733
- dirlen = strlen(dir);
734
- if ((dirlen + 3) > sizeof(path))
735
- return 2;
736
- strncpy(path, dir, dirlen);
737
- strncpy(path+dirlen, "\\*", 3); /* Including terminating \0 */
738
- keylen = strlen(keypath);
739
-
740
- #if 0 /* This function is not available in Visual C++ 6 */
741
- /*
742
- * Use numerics 0 -> FindExInfoStandard,
743
- * 1 -> FindExSearchLimitToDirectories,
744
- * as these are not defined in Visual C++ 6
745
- */
746
- hSearch = FindFirstFileEx(path, 0, &finfo, 1, NULL, 0);
747
- #else
748
- hSearch = FindFirstFile(path, &finfo);
749
- #endif
750
- if (hSearch == INVALID_HANDLE_VALUE)
751
- return 1; /* Not found */
752
-
753
- /* Loop through all subdirs checking if the keypath is under there */
754
- ret = 1; /* Assume not found */
755
- do {
756
- int sublen;
757
- /*
758
- * We need to check it is a directory despite the
759
- * FindExSearchLimitToDirectories in the above call. See SDK docs
760
- */
761
- if ((finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
762
- continue;
763
- sublen = strlen(finfo.cFileName);
764
- if ((dirlen+1+sublen+1+keylen+1) > sizeof(path))
765
- continue; /* Path does not fit, assume not matched */
766
- strncpy(path+dirlen+1, finfo.cFileName, sublen);
767
- path[dirlen+1+sublen] = '\\';
768
- strncpy(path+dirlen+1+sublen+1, keypath, keylen+1);
769
- if (FileExists(path)) {
770
- /* Found a match, print to stdout */
771
- path[dirlen+1+sublen] = '\0';
772
- QualifyPath(path);
773
- ret = 0;
774
- break;
775
- }
776
- } while (FindNextFile(hSearch, &finfo));
777
- FindClose(hSearch);
778
- return ret;
779
- }
780
-
781
- /*
782
- * LocateDependency --
783
- *
784
- * Locates a dependency for a package.
785
- * keypath - a relative path within the package directory
786
- * that is used to confirm it is the correct directory.
787
- * The search path for the package directory is currently only
788
- * the parent and grandparent of the current working directory.
789
- * If found, the command prints
790
- * name_DIRPATH=<full path of located directory>
791
- * and returns 0. If not found, does not print anything and returns 1.
792
- */
793
- static int LocateDependency(const char *keypath)
794
- {
795
- int i, ret;
796
- static const char *paths[] = {"..", "..\\..", "..\\..\\.."};
797
-
798
- for (i = 0; i < (sizeof(paths)/sizeof(paths[0])); ++i) {
799
- ret = LocateDependencyHelper(paths[i], keypath);
800
- if (ret == 0)
801
- return ret;
802
- }
803
- return ret;
804
- }
805
-
806
-
807
- /*
808
- * Local variables:
809
- * mode: c
810
- * c-basic-offset: 4
811
- * fill-column: 78
812
- * indent-tabs-mode: t
813
- * tab-width: 8
814
- * End:
815
- */