0000: 2f 2a 0a 20 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d /*. * ----------
0010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0050: 2d 2d 0a 20 2a 20 6e 6d 61 6b 65 68 6c 70 2e 63 --. * nmakehlp.c
0060: 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 69 --. *. *.This i
0070: 73 20 75 73 65 64 20 74 6f 20 66 69 78 20 6c 69 s used to fix li
0080: 6d 69 74 61 74 69 6f 6e 73 20 77 69 74 68 69 6e mitations within
0090: 20 6e 6d 61 6b 65 20 61 6e 64 20 74 68 65 20 65 nmake and the e
00a0: 6e 76 69 72 6f 6e 6d 65 6e 74 2e 0a 20 2a 0a 20 nvironment.. *.
00b0: 2a 20 43 6f 70 79 72 69 67 68 74 20 28 63 29 20 * Copyright (c)
00c0: 32 30 30 32 20 44 61 76 69 64 20 47 72 61 76 65 2002 David Grave
00d0: 72 65 61 75 78 2e 0a 20 2a 20 43 6f 70 79 72 69 reaux.. * Copyri
00e0: 67 68 74 20 28 63 29 20 32 30 30 36 20 50 61 74 ght (c) 2006 Pat
00f0: 20 54 68 6f 79 74 73 0a 20 2a 0a 20 2a 20 53 65 Thoyts. *. * Se
0100: 65 20 74 68 65 20 66 69 6c 65 20 22 6c 69 63 65 e the file "lice
0110: 6e 73 65 2e 74 65 72 6d 73 22 20 66 6f 72 20 69 nse.terms" for i
0120: 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 75 73 nformation on us
0130: 61 67 65 20 61 6e 64 20 72 65 64 69 73 74 72 69 age and redistri
0140: 62 75 74 69 6f 6e 20 6f 66 0a 20 2a 20 74 68 69 bution of. * thi
0150: 73 20 66 69 6c 65 2c 20 61 6e 64 20 66 6f 72 20 s file, and for
0160: 61 20 44 49 53 43 4c 41 49 4d 45 52 20 4f 46 20 a DISCLAIMER OF
0170: 41 4c 4c 20 57 41 52 52 41 4e 54 49 45 53 2e 0a ALL WARRANTIES..
0180: 20 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d * -------------
0190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
01a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
01b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
01c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
01d0: 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 5f 43 52 */..#define _CR
01e0: 54 5f 53 45 43 55 52 45 5f 4e 4f 5f 44 45 50 52 T_SECURE_NO_DEPR
01f0: 45 43 41 54 45 0a 23 69 6e 63 6c 75 64 65 20 3c ECATE.#include <
0200: 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 69 66 64 65 windows.h>.#ifde
0210: 66 20 5f 4d 53 43 5f 56 45 52 0a 23 70 72 61 67 f _MSC_VER.#prag
0220: 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 6c 69 62 2c ma comment (lib,
0230: 20 22 75 73 65 72 33 32 2e 6c 69 62 22 29 0a 23 "user32.lib").#
0240: 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 pragma comment (
0250: 6c 69 62 2c 20 22 6b 65 72 6e 65 6c 33 32 2e 6c lib, "kernel32.l
0260: 69 62 22 29 0a 23 65 6e 64 69 66 0a 23 69 6e 63 ib").#endif.#inc
0270: 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 0a lude <stdio.h>..
0280: 2f 2a 0a 20 2a 20 54 68 69 73 20 6c 69 62 72 61 /*. * This libra
0290: 72 79 20 69 73 20 72 65 71 75 69 72 65 64 20 66 ry is required f
02a0: 6f 72 20 78 36 34 20 62 75 69 6c 64 73 20 77 69 or x64 builds wi
02b0: 74 68 20 5f 73 6f 6d 65 5f 20 76 65 72 73 69 6f th _some_ versio
02c0: 6e 73 20 6f 66 20 4d 53 56 43 0a 20 2a 2f 0a 23 ns of MSVC. */.#
02d0: 69 66 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 41 if defined(_M_IA
02e0: 36 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 64) || defined(_
02f0: 4d 5f 41 4d 44 36 34 29 0a 23 69 66 20 5f 4d 53 M_AMD64).#if _MS
0300: 43 5f 56 45 52 20 3e 3d 20 31 34 30 30 20 26 26 C_VER >= 1400 &&
0310: 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 35 30 30 _MSC_VER < 1500
0320: 0a 23 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 .#pragma comment
0330: 28 6c 69 62 2c 20 22 62 75 66 66 65 72 6f 76 65 (lib, "bufferove
0340: 72 66 6c 6f 77 55 22 29 0a 23 65 6e 64 69 66 0a rflowU").#endif.
0350: 23 65 6e 64 69 66 0a 0a 2f 2a 20 49 53 4f 20 68 #endif../* ISO h
0360: 61 63 6b 20 66 6f 72 20 64 75 6d 62 20 56 43 2b ack for dumb VC+
0370: 2b 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 + */.#if defined
0380: 28 5f 57 49 4e 33 32 29 20 26 26 20 64 65 66 69 (_WIN32) && defi
0390: 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 20 26 26 ned(_MSC_VER) &&
03a0: 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 39 30 30 _MSC_VER < 1900
03b0: 0a 23 64 65 66 69 6e 65 20 20 20 73 6e 70 72 69 .#define snpri
03c0: 6e 74 66 09 5f 73 6e 70 72 69 6e 74 66 0a 23 65 ntf._snprintf.#e
03d0: 6e 64 69 66 0a 0a 0a 2f 2a 20 70 72 6f 74 6f 73 ndif.../* protos
03e0: 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 */..static int
03f0: 43 68 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 CheckForCompiler
0400: 46 65 61 74 75 72 65 28 63 6f 6e 73 74 20 63 68 Feature(const ch
0410: 61 72 20 2a 6f 70 74 69 6f 6e 29 3b 0a 73 74 61 ar *option);.sta
0420: 74 69 63 20 69 6e 74 20 43 68 65 63 6b 46 6f 72 tic int CheckFor
0430: 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 63 68 LinkerFeature(ch
0440: 61 72 20 2a 2a 6f 70 74 69 6f 6e 73 2c 20 69 6e ar **options, in
0450: 74 20 63 6f 75 6e 74 29 3b 0a 73 74 61 74 69 63 t count);.static
0460: 20 69 6e 74 20 49 73 49 6e 28 63 6f 6e 73 74 20 int IsIn(const
0470: 63 68 61 72 20 2a 73 74 72 69 6e 67 2c 20 63 6f char *string, co
0480: 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73 74 72 nst char *substr
0490: 69 6e 67 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 ing);.static int
04a0: 20 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 28 SubstituteFile(
04b0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73 const char *subs
04c0: 74 73 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a ts, const char *
04d0: 66 69 6c 65 6e 61 6d 65 29 3b 0a 73 74 61 74 69 filename);.stati
04e0: 63 20 69 6e 74 20 51 75 61 6c 69 66 79 50 61 74 c int QualifyPat
04f0: 68 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 h(const char *pa
0500: 74 68 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 th);.static int
0510: 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 LocateDependency
0520: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b 65 79 (const char *key
0530: 66 69 6c 65 29 3b 0a 73 74 61 74 69 63 20 63 6f file);.static co
0540: 6e 73 74 20 63 68 61 72 20 2a 47 65 74 56 65 72 nst char *GetVer
0550: 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 63 6f 6e sionFromFile(con
0560: 73 74 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d st char *filenam
0570: 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6d e, const char *m
0580: 61 74 63 68 2c 20 69 6e 74 20 6e 75 6d 64 6f 74 atch, int numdot
0590: 73 29 3b 0a 73 74 61 74 69 63 20 44 57 4f 52 44 s);.static DWORD
05a0: 20 57 49 4e 41 50 49 20 52 65 61 64 46 72 6f 6d WINAPI ReadFrom
05b0: 50 69 70 65 28 4c 50 56 4f 49 44 20 61 72 67 73 Pipe(LPVOID args
05c0: 29 3b 0a 0a 2f 2a 20 67 6c 6f 62 61 6c 73 20 2a );../* globals *
05d0: 2f 0a 0a 23 64 65 66 69 6e 65 20 43 48 55 4e 4b /..#define CHUNK
05e0: 09 32 35 0a 23 64 65 66 69 6e 65 20 53 54 41 54 .25.#define STAT
05f0: 49 43 42 55 46 46 45 52 53 49 5a 45 20 20 20 20 ICBUFFERSIZE
0600: 31 30 30 30 0a 74 79 70 65 64 65 66 20 73 74 72 1000.typedef str
0610: 75 63 74 20 7b 0a 20 20 20 20 48 41 4e 44 4c 45 uct {. HANDLE
0620: 20 70 69 70 65 3b 0a 20 20 20 20 63 68 61 72 20 pipe;. char
0630: 62 75 66 66 65 72 5b 53 54 41 54 49 43 42 55 46 buffer[STATICBUF
0640: 46 45 52 53 49 5a 45 5d 3b 0a 7d 20 70 69 70 65 FERSIZE];.} pipe
0650: 69 6e 66 6f 3b 0a 0a 70 69 70 65 69 6e 66 6f 20 info;..pipeinfo
0660: 4f 75 74 20 3d 20 7b 49 4e 56 41 4c 49 44 5f 48 Out = {INVALID_H
0670: 41 4e 44 4c 45 5f 56 41 4c 55 45 2c 20 22 22 7d ANDLE_VALUE, ""}
0680: 3b 0a 70 69 70 65 69 6e 66 6f 20 45 72 72 20 3d ;.pipeinfo Err =
0690: 20 7b 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 {INVALID_HANDLE
06a0: 5f 56 41 4c 55 45 2c 20 22 22 7d 3b 0a 0c 0a 2f _VALUE, ""};.../
06b0: 2a 0a 20 2a 20 65 78 69 74 63 6f 64 65 73 3a 20 *. * exitcodes:
06c0: 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 0 == no, 1 == ye
06d0: 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 0a 20 2a s, 2 == error. *
06e0: 2f 0a 0a 69 6e 74 0a 6d 61 69 6e 28 0a 20 20 20 /..int.main(.
06f0: 20 69 6e 74 20 61 72 67 63 2c 0a 20 20 20 20 63 int argc,. c
0700: 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a 7b 0a 20 har *argv[]).{.
0710: 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 30 5d char msg[300]
0720: 3b 0a 20 20 20 20 44 57 4f 52 44 20 64 77 57 72 ;. DWORD dwWr
0730: 69 74 74 65 6e 3b 0a 20 20 20 20 69 6e 74 20 63 itten;. int c
0740: 68 61 72 73 3b 0a 20 20 20 20 63 6f 6e 73 74 20 hars;. const
0750: 63 68 61 72 20 2a 73 3b 0a 0a 20 20 20 20 2f 2a char *s;.. /*
0760: 0a 20 20 20 20 20 2a 20 4d 61 6b 65 20 73 75 72 . * Make sur
0770: 65 20 63 68 69 6c 64 72 65 6e 20 28 63 6c 2e 65 e children (cl.e
0780: 78 65 20 61 6e 64 20 6c 69 6e 6b 2e 65 78 65 29 xe and link.exe)
0790: 20 61 72 65 20 6b 65 70 74 20 71 75 69 65 74 2e are kept quiet.
07a0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 53 65 . */.. Se
07b0: 74 45 72 72 6f 72 4d 6f 64 65 28 53 45 4d 5f 46 tErrorMode(SEM_F
07c0: 41 49 4c 43 52 49 54 49 43 41 4c 45 52 52 4f 52 AILCRITICALERROR
07d0: 53 20 7c 20 53 45 4d 5f 4e 4f 4f 50 45 4e 46 49 S | SEM_NOOPENFI
07e0: 4c 45 45 52 52 4f 52 42 4f 58 29 3b 0a 0a 20 20 LEERRORBOX);..
07f0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4d 61 6b 65 /*. * Make
0800: 20 73 75 72 65 20 74 68 65 20 63 6f 6d 70 69 6c sure the compil
0810: 65 72 20 61 6e 64 20 6c 69 6e 6b 65 72 20 61 72 er and linker ar
0820: 65 6e 27 74 20 65 66 66 65 63 74 65 64 20 62 79 en't effected by
0830: 20 74 68 65 20 6f 75 74 73 69 64 65 20 77 6f 72 the outside wor
0840: 6c 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ld.. */..
0850: 20 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56 SetEnvironmentV
0860: 61 72 69 61 62 6c 65 28 22 43 4c 22 2c 20 22 22 ariable("CL", ""
0870: 29 3b 0a 20 20 20 20 53 65 74 45 6e 76 69 72 6f );. SetEnviro
0880: 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 22 4c nmentVariable("L
0890: 49 4e 4b 22 2c 20 22 22 29 3b 0a 0a 20 20 20 20 INK", "");..
08a0: 69 66 20 28 61 72 67 63 20 3e 20 31 20 26 26 20 if (argc > 1 &&
08b0: 2a 61 72 67 76 5b 31 5d 20 3d 3d 20 27 2d 27 29 *argv[1] == '-')
08c0: 20 7b 0a 09 73 77 69 74 63 68 20 28 2a 28 61 72 {..switch (*(ar
08d0: 67 76 5b 31 5d 2b 31 29 29 20 7b 0a 09 63 61 73 gv[1]+1)) {..cas
08e0: 65 20 27 63 27 3a 0a 09 20 20 20 20 69 66 20 28 e 'c':.. if (
08f0: 61 72 67 63 20 21 3d 20 33 29 20 7b 0a 09 09 63 argc != 3) {...c
0900: 68 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 hars = snprintf(
0910: 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 msg, sizeof(msg)
0920: 20 2d 20 31 2c 0a 09 09 20 20 20 20 20 20 20 20 - 1,...
0930: 22 75 73 61 67 65 3a 20 25 73 20 2d 63 20 3c 63 "usage: %s -c <c
0940: 6f 6d 70 69 6c 65 72 20 6f 70 74 69 6f 6e 3e 5c ompiler option>\
0950: 6e 22 0a 09 09 09 22 54 65 73 74 73 20 66 6f 72 n"...."Tests for
0960: 20 77 68 65 74 68 65 72 20 63 6c 2e 65 78 65 20 whether cl.exe
0970: 73 75 70 70 6f 72 74 73 20 61 6e 20 6f 70 74 69 supports an opti
0980: 6f 6e 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f on\n"...."exitco
0990: 64 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 des: 0 == no, 1
09a0: 3d 3d 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 == yes, 2 == err
09b0: 6f 72 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b or\n", argv[0]);
09c0: 0a 09 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 ...WriteFile(Get
09d0: 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 StdHandle(STD_ER
09e0: 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 ROR_HANDLE), msg
09f0: 2c 20 63 68 61 72 73 2c 0a 09 09 09 26 64 77 57 , chars,....&dwW
0a00: 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 ritten, NULL);..
0a10: 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 .return 2;..
0a20: 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 43 68 }.. return Ch
0a30: 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 eckForCompilerFe
0a40: 61 74 75 72 65 28 61 72 67 76 5b 32 5d 29 3b 0a ature(argv[2]);.
0a50: 09 63 61 73 65 20 27 6c 27 3a 0a 09 20 20 20 20 .case 'l':..
0a60: 69 66 20 28 61 72 67 63 20 3c 20 33 29 20 7b 0a if (argc < 3) {.
0a70: 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 69 6e ..chars = snprin
0a80: 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d tf(msg, sizeof(m
0a90: 73 67 29 20 2d 20 31 2c 0a 09 20 20 20 20 20 20 sg) - 1,..
0aa0: 20 09 09 22 75 73 61 67 65 3a 20 25 73 20 2d 6c .."usage: %s -l
0ab0: 20 3c 6c 69 6e 6b 65 72 20 6f 70 74 69 6f 6e 3e <linker option>
0ac0: 20 3f 3c 6d 61 6e 64 61 74 6f 72 79 20 6f 70 74 ?<mandatory opt
0ad0: 69 6f 6e 3e 20 2e 2e 2e 3f 5c 6e 22 0a 09 09 09 ion> ...?\n"....
0ae0: 22 54 65 73 74 73 20 66 6f 72 20 77 68 65 74 68 "Tests for wheth
0af0: 65 72 20 6c 69 6e 6b 2e 65 78 65 20 73 75 70 70 er link.exe supp
0b00: 6f 72 74 73 20 61 6e 20 6f 70 74 69 6f 6e 5c 6e orts an option\n
0b10: 22 0a 09 09 09 22 65 78 69 74 63 6f 64 65 73 3a "...."exitcodes:
0b20: 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 0 == no, 1 == y
0b30: 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e es, 2 == error\n
0b40: 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 ", argv[0]);...W
0b50: 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 riteFile(GetStdH
0b60: 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f andle(STD_ERROR_
0b70: 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 HANDLE), msg, ch
0b80: 61 72 73 2c 0a 09 09 09 26 64 77 57 72 69 74 74 ars,....&dwWritt
0b90: 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 en, NULL);...ret
0ba0: 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 urn 2;.. }..
0bb0: 20 20 20 72 65 74 75 72 6e 20 43 68 65 63 6b 46 return CheckF
0bc0: 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 orLinkerFeature(
0bd0: 26 61 72 67 76 5b 32 5d 2c 20 61 72 67 63 2d 32 &argv[2], argc-2
0be0: 29 3b 0a 09 63 61 73 65 20 27 66 27 3a 0a 09 20 );..case 'f':..
0bf0: 20 20 20 69 66 20 28 61 72 67 63 20 3d 3d 20 32 if (argc == 2
0c00: 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e ) {...chars = sn
0c10: 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 printf(msg, size
0c20: 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 09 of(msg) - 1,....
0c30: 22 75 73 61 67 65 3a 20 25 73 20 2d 66 20 3c 73 "usage: %s -f <s
0c40: 74 72 69 6e 67 3e 20 3c 73 75 62 73 74 72 69 6e tring> <substrin
0c50: 67 3e 5c 6e 22 0a 09 09 09 22 46 69 6e 64 20 61 g>\n"...."Find a
0c60: 20 73 75 62 73 74 72 69 6e 67 20 77 69 74 68 69 substring withi
0c70: 6e 20 61 6e 6f 74 68 65 72 5c 6e 22 0a 09 09 09 n another\n"....
0c80: 22 65 78 69 74 63 6f 64 65 73 3a 20 30 20 3d 3d "exitcodes: 0 ==
0c90: 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c 20 32 no, 1 == yes, 2
0ca0: 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c 20 61 72 == error\n", ar
0cb0: 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 65 46 gv[0]);...WriteF
0cc0: 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 ile(GetStdHandle
0cd0: 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c (STD_ERROR_HANDL
0ce0: 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 0a E), msg, chars,.
0cf0: 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c 20 4e ...&dwWritten, N
0d00: 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 32 ULL);...return 2
0d10: 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 69 66 ;.. } else if
0d20: 20 28 61 72 67 63 20 3d 3d 20 33 29 20 7b 0a 09 (argc == 3) {..
0d30: 09 2f 2a 0a 09 09 20 2a 20 49 66 20 74 68 65 20 ./*... * If the
0d40: 73 74 72 69 6e 67 20 69 73 20 62 6c 61 6e 6b 2c string is blank,
0d50: 20 74 68 65 72 65 20 69 73 20 6e 6f 20 6d 61 74 there is no mat
0d60: 63 68 2e 0a 09 09 20 2a 2f 0a 0a 09 09 72 65 74 ch.... */....ret
0d70: 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20 65 6c urn 0;.. } el
0d80: 73 65 20 7b 0a 09 09 72 65 74 75 72 6e 20 49 73 se {...return Is
0d90: 49 6e 28 61 72 67 76 5b 32 5d 2c 20 61 72 67 76 In(argv[2], argv
0da0: 5b 33 5d 29 3b 0a 09 20 20 20 20 7d 0a 09 63 61 [3]);.. }..ca
0db0: 73 65 20 27 73 27 3a 0a 09 20 20 20 20 69 66 20 se 's':.. if
0dc0: 28 61 72 67 63 20 3d 3d 20 32 29 20 7b 0a 09 09 (argc == 2) {...
0dd0: 63 68 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 chars = snprintf
0de0: 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 (msg, sizeof(msg
0df0: 29 20 2d 20 31 2c 0a 09 09 09 22 75 73 61 67 65 ) - 1,...."usage
0e00: 3a 20 25 73 20 2d 73 20 3c 73 75 62 73 74 69 74 : %s -s <substit
0e10: 75 74 69 6f 6e 73 20 66 69 6c 65 3e 20 3c 66 69 utions file> <fi
0e20: 6c 65 3e 5c 6e 22 0a 09 09 09 22 50 65 72 66 6f le>\n"...."Perfo
0e30: 72 6d 20 61 20 73 65 74 20 6f 66 20 73 74 72 69 rm a set of stri
0e40: 6e 67 20 6d 61 70 20 74 79 70 65 20 73 75 62 73 ng map type subs
0e50: 74 75 74 69 74 69 6f 6e 73 20 6f 6e 20 61 20 66 tutitions on a f
0e60: 69 6c 65 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 ile\n"...."exitc
0e70: 6f 64 65 73 3a 20 30 5c 6e 22 2c 0a 09 09 09 61 odes: 0\n",....a
0e80: 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 65 rgv[0]);...Write
0e90: 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 6c File(GetStdHandl
0ea0: 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 e(STD_ERROR_HAND
0eb0: 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c LE), msg, chars,
0ec0: 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c 20 ....&dwWritten,
0ed0: 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 NULL);...return
0ee0: 32 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 72 2;.. }.. r
0ef0: 65 74 75 72 6e 20 53 75 62 73 74 69 74 75 74 65 eturn Substitute
0f00: 46 69 6c 65 28 61 72 67 76 5b 32 5d 2c 20 61 72 File(argv[2], ar
0f10: 67 76 5b 33 5d 29 3b 0a 09 63 61 73 65 20 27 56 gv[3]);..case 'V
0f20: 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 67 63 ':.. if (argc
0f30: 20 21 3d 20 34 29 20 7b 0a 09 09 63 68 61 72 73 != 4) {...chars
0f40: 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c = snprintf(msg,
0f50: 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 sizeof(msg) - 1
0f60: 2c 0a 09 09 20 20 20 20 22 75 73 61 67 65 3a 20 ,... "usage:
0f70: 25 73 20 2d 56 20 66 69 6c 65 6e 61 6d 65 20 6d %s -V filename m
0f80: 61 74 63 68 73 74 72 69 6e 67 5c 6e 22 0a 09 09 atchstring\n"...
0f90: 20 20 20 20 22 45 78 74 72 61 63 74 20 61 20 76 "Extract a v
0fa0: 65 72 73 69 6f 6e 20 66 72 6f 6d 20 61 20 66 69 ersion from a fi
0fb0: 6c 65 3a 5c 6e 22 0a 09 09 20 20 20 20 22 65 67 le:\n"... "eg
0fc0: 3a 20 70 6b 67 49 6e 64 65 78 2e 74 63 6c 20 5c : pkgIndex.tcl \
0fd0: 22 70 61 63 6b 61 67 65 20 69 66 6e 65 65 64 65 "package ifneede
0fe0: 64 20 68 74 74 70 5c 22 22 2c 0a 09 09 20 20 20 d http\"",...
0ff0: 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 argv[0]);...Wri
1000: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e teFile(GetStdHan
1010: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 dle(STD_ERROR_HA
1020: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 NDLE), msg, char
1030: 73 2c 0a 09 09 20 20 20 20 26 64 77 57 72 69 74 s,... &dwWrit
1040: 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 ten, NULL);...re
1050: 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 0a 09 turn 0;.. }..
1060: 20 20 20 20 73 20 3d 20 47 65 74 56 65 72 73 69 s = GetVersi
1070: 6f 6e 46 72 6f 6d 46 69 6c 65 28 61 72 67 76 5b onFromFile(argv[
1080: 32 5d 2c 20 61 72 67 76 5b 33 5d 2c 20 2a 28 61 2], argv[3], *(a
1090: 72 67 76 5b 31 5d 2b 32 29 20 2d 20 27 30 27 29 rgv[1]+2) - '0')
10a0: 3b 0a 09 20 20 20 20 69 66 20 28 73 20 26 26 20 ;.. if (s &&
10b0: 2a 73 29 20 7b 0a 09 09 70 72 69 6e 74 66 28 22 *s) {...printf("
10c0: 25 73 5c 6e 22 2c 20 73 29 3b 0a 09 09 72 65 74 %s\n", s);...ret
10d0: 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20 65 6c urn 0;.. } el
10e0: 73 65 0a 09 09 72 65 74 75 72 6e 20 31 3b 20 2f se...return 1; /
10f0: 2a 20 56 65 72 73 69 6f 6e 20 6e 6f 74 20 66 6f * Version not fo
1100: 75 6e 64 2e 20 52 65 74 75 72 6e 20 6e 6f 6e 2d und. Return non-
1110: 30 20 65 78 69 74 20 63 6f 64 65 20 2a 2f 0a 0a 0 exit code */..
1120: 09 63 61 73 65 20 27 51 27 3a 0a 09 20 20 20 20 .case 'Q':..
1130: 69 66 20 28 61 72 67 63 20 21 3d 20 33 29 20 7b if (argc != 3) {
1140: 0a 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 69 ...chars = snpri
1150: 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 ntf(msg, sizeof(
1160: 6d 73 67 29 20 2d 20 31 2c 0a 09 09 20 20 20 20 msg) - 1,...
1170: 22 75 73 61 67 65 3a 20 25 73 20 2d 51 20 70 61 "usage: %s -Q pa
1180: 74 68 5c 6e 22 0a 09 09 20 20 20 20 22 45 6d 69 th\n"... "Emi
1190: 74 20 74 68 65 20 66 75 6c 6c 79 20 71 75 61 6c t the fully qual
11a0: 69 66 69 65 64 20 70 61 74 68 5c 6e 22 0a 09 09 ified path\n"...
11b0: 20 20 20 20 22 65 78 69 74 63 6f 64 65 73 3a 20 "exitcodes:
11c0: 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 0 == no, 1 == ye
11d0: 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 s, 2 == error\n"
11e0: 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 , argv[0]);...Wr
11f0: 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 iteFile(GetStdHa
1200: 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 ndle(STD_ERROR_H
1210: 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 ANDLE), msg, cha
1220: 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57 72 69 rs,... &dwWri
1230: 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 tten, NULL);...r
1240: 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a eturn 2;.. }.
1250: 09 20 20 20 20 72 65 74 75 72 6e 20 51 75 61 6c . return Qual
1260: 69 66 79 50 61 74 68 28 61 72 67 76 5b 32 5d 29 ifyPath(argv[2])
1270: 3b 0a 0a 09 63 61 73 65 20 27 4c 27 3a 0a 09 20 ;...case 'L':..
1280: 20 20 20 69 66 20 28 61 72 67 63 20 21 3d 20 33 if (argc != 3
1290: 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e ) {...chars = sn
12a0: 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 printf(msg, size
12b0: 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 20 of(msg) - 1,...
12c0: 20 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 4c "usage: %s -L
12d0: 20 6b 65 79 70 61 74 68 5c 6e 22 0a 09 09 20 20 keypath\n"...
12e0: 20 20 22 45 6d 69 74 20 74 68 65 20 66 75 6c 6c "Emit the full
12f0: 79 20 71 75 61 6c 69 66 69 65 64 20 70 61 74 68 y qualified path
1300: 20 6f 66 20 64 69 72 65 63 74 6f 72 79 20 63 6f of directory co
1310: 6e 74 61 69 6e 69 6e 67 20 6b 65 79 70 61 74 68 ntaining keypath
1320: 5c 6e 22 0a 09 09 20 20 20 20 22 65 78 69 74 63 \n"... "exitc
1330: 6f 64 65 73 3a 20 30 20 3d 3d 20 73 75 63 63 65 odes: 0 == succe
1340: 73 73 2c 20 31 20 3d 3d 20 6e 6f 74 20 66 6f 75 ss, 1 == not fou
1350: 6e 64 2c 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e nd, 2 == error\n
1360: 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 ", argv[0]);...W
1370: 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 riteFile(GetStdH
1380: 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f andle(STD_ERROR_
1390: 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 HANDLE), msg, ch
13a0: 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57 72 ars,... &dwWr
13b0: 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 itten, NULL);...
13c0: 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d return 2;.. }
13d0: 0a 09 20 20 20 20 72 65 74 75 72 6e 20 4c 6f 63 .. return Loc
13e0: 61 74 65 44 65 70 65 6e 64 65 6e 63 79 28 61 72 ateDependency(ar
13f0: 67 76 5b 32 5d 29 3b 0a 09 7d 0a 20 20 20 20 7d gv[2]);..}. }
1400: 0a 20 20 20 20 63 68 61 72 73 20 3d 20 73 6e 70 . chars = snp
1410: 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f rintf(msg, sizeo
1420: 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 20 20 20 f(msg) - 1,..
1430: 20 22 75 73 61 67 65 3a 20 25 73 20 2d 63 7c 2d "usage: %s -c|-
1440: 66 7c 2d 6c 7c 2d 51 7c 2d 73 7c 2d 56 20 2e 2e f|-l|-Q|-s|-V ..
1450: 2e 5c 6e 22 0a 09 20 20 20 20 22 54 68 69 73 20 .\n".. "This
1460: 69 73 20 61 20 6c 69 74 74 6c 65 20 68 65 6c 70 is a little help
1470: 65 72 20 61 70 70 20 74 6f 20 65 71 75 61 6c 69 er app to equali
1480: 7a 65 20 73 68 65 6c 6c 20 64 69 66 66 65 72 65 ze shell differe
1490: 6e 63 65 73 20 62 65 74 77 65 65 6e 20 57 69 6e nces between Win
14a0: 4e 54 20 61 6e 64 5c 6e 22 0a 09 20 20 20 20 22 NT and\n".. "
14b0: 57 69 6e 39 78 20 61 6e 64 20 67 65 74 20 6e 6d Win9x and get nm
14c0: 61 6b 65 2e 65 78 65 20 74 6f 20 61 63 63 6f 6d ake.exe to accom
14d0: 70 6c 69 73 68 20 69 74 73 20 6a 6f 62 2e 5c 6e plish its job.\n
14e0: 22 2c 0a 09 20 20 20 20 61 72 67 76 5b 30 5d 29 ",.. argv[0])
14f0: 3b 0a 20 20 20 20 57 72 69 74 65 46 69 6c 65 28 ;. WriteFile(
1500: 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 GetStdHandle(STD
1510: 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 _ERROR_HANDLE),
1520: 6d 73 67 2c 20 63 68 61 72 73 2c 20 26 64 77 57 msg, chars, &dwW
1530: 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 20 ritten, NULL);.
1540: 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 7d 0a 0c return 2;.}..
1550: 0a 73 74 61 74 69 63 20 69 6e 74 0a 43 68 65 63 .static int.Chec
1560: 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 61 74 kForCompilerFeat
1570: 75 72 65 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 ure(. const c
1580: 68 61 72 20 2a 6f 70 74 69 6f 6e 29 0a 7b 0a 20 har *option).{.
1590: 20 20 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 STARTUPINFO s
15a0: 69 3b 0a 20 20 20 20 50 52 4f 43 45 53 53 5f 49 i;. PROCESS_I
15b0: 4e 46 4f 52 4d 41 54 49 4f 4e 20 70 69 3b 0a 20 NFORMATION pi;.
15c0: 20 20 20 53 45 43 55 52 49 54 59 5f 41 54 54 52 SECURITY_ATTR
15d0: 49 42 55 54 45 53 20 73 61 3b 0a 20 20 20 20 44 IBUTES sa;. D
15e0: 57 4f 52 44 20 74 68 72 65 61 64 49 44 3b 0a 20 WORD threadID;.
15f0: 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 30 5d char msg[300]
1600: 3b 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 20 ;. BOOL ok;.
1610: 20 20 20 48 41 4e 44 4c 45 20 68 50 72 6f 63 65 HANDLE hProce
1620: 73 73 2c 20 68 2c 20 70 69 70 65 54 68 72 65 61 ss, h, pipeThrea
1630: 64 73 5b 32 5d 3b 0a 20 20 20 20 63 68 61 72 20 ds[2];. char
1640: 63 6d 64 6c 69 6e 65 5b 31 30 30 5d 3b 0a 0a 20 cmdline[100];..
1650: 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20 47 65 hProcess = Ge
1660: 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73 73 28 tCurrentProcess(
1670: 29 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26 );.. memset(&
1680: 70 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 50 52 pi, 0, sizeof(PR
1690: 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 4f OCESS_INFORMATIO
16a0: 4e 29 29 3b 0a 20 20 20 20 6d 65 6d 73 65 74 28 N));. memset(
16b0: 26 73 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 &si, 0, sizeof(S
16c0: 54 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a 20 20 TARTUPINFO));.
16d0: 20 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 6f 66 si.cb = sizeof
16e0: 28 53 54 41 52 54 55 50 49 4e 46 4f 29 3b 0a 20 (STARTUPINFO);.
16f0: 20 20 20 73 69 2e 64 77 46 6c 61 67 73 20 20 20 si.dwFlags
1700: 3d 20 53 54 41 52 54 46 5f 55 53 45 53 54 44 48 = STARTF_USESTDH
1710: 41 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 2e 68 ANDLES;. si.h
1720: 53 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 41 4c StdInput = INVAL
1730: 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 3b ID_HANDLE_VALUE;
1740: 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26 73 61 .. memset(&sa
1750: 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 45 43 55 , 0, sizeof(SECU
1760: 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 RITY_ATTRIBUTES)
1770: 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e 67 74 );. sa.nLengt
1780: 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43 55 52 h = sizeof(SECUR
1790: 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 3b ITY_ATTRIBUTES);
17a0: 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75 72 69 . sa.lpSecuri
17b0: 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d 20 4e tyDescriptor = N
17c0: 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49 6e 68 ULL;. sa.bInh
17d0: 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 46 41 4c eritHandle = FAL
17e0: 53 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 SE;.. /*.
17f0: 20 2a 20 43 72 65 61 74 65 20 61 20 6e 6f 6e 2d * Create a non-
1800: 69 6e 68 65 72 69 74 61 62 6c 65 20 70 69 70 65 inheritable pipe
1810: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 .. */.. C
1820: 72 65 61 74 65 50 69 70 65 28 26 4f 75 74 2e 70 reatePipe(&Out.p
1830: 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 ipe, &h, &sa, 0)
1840: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
1850: 20 44 75 70 65 20 74 68 65 20 77 72 69 74 65 20 Dupe the write
1860: 73 69 64 65 2c 20 6d 61 6b 65 20 69 74 20 69 6e side, make it in
1870: 68 65 72 69 74 61 62 6c 65 2c 20 61 6e 64 20 63 heritable, and c
1880: 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 69 6e 61 lose the origina
1890: 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 l.. */..
18a0: 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 DuplicateHandle(
18b0: 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 hProcess, h, hPr
18c0: 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 4f ocess, &si.hStdO
18d0: 75 74 70 75 74 2c 20 30 2c 20 54 52 55 45 2c 0a utput, 0, TRUE,.
18e0: 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 . DUPLICATE_S
18f0: 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 AME_ACCESS | DUP
1900: 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 LICATE_CLOSE_SOU
1910: 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 RCE);.. /*.
1920: 20 20 20 2a 20 53 61 6d 65 20 61 73 20 61 62 6f * Same as abo
1930: 76 65 2c 20 62 75 74 20 66 6f 72 20 74 68 65 20 ve, but for the
1940: 65 72 72 6f 72 20 73 69 64 65 2e 0a 20 20 20 20 error side..
1950: 20 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 65 50 */.. CreateP
1960: 69 70 65 28 26 45 72 72 2e 70 69 70 65 2c 20 26 ipe(&Err.pipe, &
1970: 68 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20 20 20 h, &sa, 0);.
1980: 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 DuplicateHandle(
1990: 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 hProcess, h, hPr
19a0: 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 45 ocess, &si.hStdE
19b0: 72 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c 0a 09 rror, 0, TRUE,..
19c0: 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 41 DUPLICATE_SA
19d0: 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 4c ME_ACCESS | DUPL
19e0: 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 52 ICATE_CLOSE_SOUR
19f0: 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 CE);.. /*.
1a00: 20 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61 6e 64 * Base command
1a10: 20 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a line.. */..
1a20: 20 20 20 20 6c 73 74 72 63 70 79 28 63 6d 64 6c lstrcpy(cmdl
1a30: 69 6e 65 2c 20 22 63 6c 2e 65 78 65 20 2d 6e 6f ine, "cl.exe -no
1a40: 6c 6f 67 6f 20 2d 63 20 2d 54 43 20 2d 5a 73 20 logo -c -TC -Zs
1a50: 2d 58 20 2d 46 70 2e 5c 5c 5f 6a 75 6e 6b 2e 70 -X -Fp.\\_junk.p
1a60: 63 68 20 22 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 ch ");.. /*.
1a70: 20 20 20 20 2a 20 41 70 70 65 6e 64 20 6f 75 72 * Append our
1a80: 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 65 73 74 option for test
1a90: 69 6e 67 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ing. */..
1aa0: 20 6c 73 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 lstrcat(cmdline
1ab0: 2c 20 6f 70 74 69 6f 6e 29 3b 0a 0a 20 20 20 20 , option);..
1ac0: 2f 2a 0a 20 20 20 20 20 2a 20 46 69 6c 65 6e 61 /*. * Filena
1ad0: 6d 65 20 74 6f 20 63 6f 6d 70 69 6c 65 2c 20 77 me to compile, w
1ae0: 68 69 63 68 20 65 78 69 73 74 73 2c 20 62 75 74 hich exists, but
1af0: 20 69 73 20 6e 6f 74 68 69 6e 67 20 61 6e 64 20 is nothing and
1b00: 65 6d 70 74 79 2e 0a 20 20 20 20 20 2a 2f 0a 0a empty.. */..
1b10: 20 20 20 20 6c 73 74 72 63 61 74 28 63 6d 64 6c lstrcat(cmdl
1b20: 69 6e 65 2c 20 22 20 2e 5c 5c 6e 75 6c 22 29 3b ine, " .\\nul");
1b30: 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 65 61 74 .. ok = Creat
1b40: 65 50 72 6f 63 65 73 73 28 0a 09 20 20 20 20 4e eProcess(.. N
1b50: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d 6f 64 75 ULL,. /* Modu
1b60: 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 20 20 20 le name. */..
1b70: 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 20 2f 2a cmdline,. /*
1b80: 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 20 2a Command line. *
1b90: 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 /.. NULL,.
1ba0: 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 61 6e 64 /* Process hand
1bb0: 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 74 61 62 le not inheritab
1bc0: 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c le. */.. NULL
1bd0: 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 61 64 20 ,. /* Thread
1be0: 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 handle not inher
1bf0: 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 itable. */..
1c00: 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 79 65 73 TRUE,. /* yes
1c10: 2c 20 69 6e 68 65 72 69 74 20 68 61 6e 64 6c 65 , inherit handle
1c20: 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 54 41 43 s. */.. DETAC
1c30: 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 2f 2a 20 HED_PROCESS, /*
1c40: 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f 72 20 79 No console for y
1c50: 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c ou. */.. NULL
1c60: 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 70 61 72 ,. /* Use par
1c70: 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e 6d 65 6e ent's environmen
1c80: 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 20 20 20 t block. */..
1c90: 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 NULL,. /* Us
1ca0: 65 20 70 61 72 65 6e 74 27 73 20 73 74 61 72 74 e parent's start
1cb0: 69 6e 67 20 64 69 72 65 63 74 6f 72 79 2e 20 2a ing directory. *
1cc0: 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 20 20 20 /.. &si,.
1cd0: 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 53 54 /* Pointer to ST
1ce0: 41 52 54 55 50 49 4e 46 4f 20 73 74 72 75 63 74 ARTUPINFO struct
1cf0: 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 26 70 69 ure. */.. &pi
1d00: 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 );. /* Pointe
1d10: 72 20 74 6f 20 50 52 4f 43 45 53 53 5f 49 4e 46 r to PROCESS_INF
1d20: 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 63 74 75 ORMATION structu
1d30: 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 re. */.. if (
1d40: 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 20 65 72 !ok) {..DWORD er
1d50: 72 20 3d 20 47 65 74 4c 61 73 74 45 72 72 6f 72 r = GetLastError
1d60: 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 73 20 3d ();..int chars =
1d70: 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 snprintf(msg, s
1d80: 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a izeof(msg) - 1,.
1d90: 09 09 22 54 72 69 65 64 20 74 6f 20 6c 61 75 6e .."Tried to laun
1da0: 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 75 74 20 ch: \"%s\", but
1db0: 67 6f 74 20 65 72 72 6f 72 20 5b 25 6c 75 5d 3a got error [%lu]:
1dc0: 20 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65 72 72 ", cmdline, err
1dd0: 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73 73 61 );...FormatMessa
1de0: 67 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 ge(FORMAT_MESSAG
1df0: 45 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c 46 4f E_FROM_SYSTEM|FO
1e00: 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49 47 4e RMAT_MESSAGE_IGN
1e10: 4f 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09 09 46 ORE_INSERTS|...F
1e20: 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 4d 41 ORMAT_MESSAGE_MA
1e30: 58 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20 30 4c X_WIDTH_MASK, 0L
1e40: 2c 20 65 72 72 2c 20 30 2c 20 28 4c 50 53 54 52 , err, 0, (LPSTR
1e50: 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c 0a 09 09 )&msg[chars],...
1e60: 28 33 30 30 2d 63 68 61 72 73 29 2c 20 30 29 3b (300-chars), 0);
1e70: 0a 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 ..WriteFile(GetS
1e80: 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 tdHandle(STD_ERR
1e90: 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c OR_HANDLE), msg,
1ea0: 20 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c 20 26 lstrlen(msg), &
1eb0: 65 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65 74 75 err,NULL);..retu
1ec0: 72 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 rn 2;. }..
1ed0: 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f 73 65 /*. * Close
1ee0: 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65 73 20 our references
1ef0: 74 6f 20 74 68 65 20 77 72 69 74 65 20 68 61 6e to the write han
1f00: 64 6c 65 73 20 74 68 61 74 20 68 61 76 65 20 6e dles that have n
1f10: 6f 77 20 62 65 65 6e 20 69 6e 68 65 72 69 74 65 ow been inherite
1f20: 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 d.. */..
1f30: 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 CloseHandle(si.h
1f40: 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 20 20 StdOutput);.
1f50: 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 CloseHandle(si.h
1f60: 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 20 20 StdError);..
1f70: 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64 6c 65 WaitForInputIdle
1f80: 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 35 30 (pi.hProcess, 50
1f90: 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 00);. CloseHa
1fa0: 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61 64 29 ndle(pi.hThread)
1fb0: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
1fc0: 20 53 74 61 72 74 20 74 68 65 20 70 69 70 65 20 Start the pipe
1fd0: 72 65 61 64 65 72 20 74 68 72 65 61 64 73 2e 0a reader threads..
1fe0: 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70 69 70 */.. pip
1ff0: 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 43 72 eThreads[0] = Cr
2000: 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c eateThread(NULL,
2010: 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 0, ReadFromPipe
2020: 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 72 65 , &Out, 0, &thre
2030: 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70 65 54 adID);. pipeT
2040: 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 65 61 hreads[1] = Crea
2050: 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 30 teThread(NULL, 0
2060: 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 2c 20 , ReadFromPipe,
2070: 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65 61 64 &Err, 0, &thread
2080: 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 ID);.. /*.
2090: 20 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74 69 6e * Block waitin
20a0: 67 20 66 6f 72 20 74 68 65 20 70 72 6f 63 65 73 g for the proces
20b0: 73 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20 20 2a s to end.. *
20c0: 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f 72 53 69 /.. WaitForSi
20d0: 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e 68 50 ngleObject(pi.hP
20e0: 72 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49 54 45 rocess, INFINITE
20f0: 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 );. CloseHand
2100: 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 29 3b le(pi.hProcess);
2110: 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 .. /*. *
2120: 57 61 69 74 20 66 6f 72 20 6f 75 72 20 70 69 70 Wait for our pip
2130: 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 72 65 e to get done re
2140: 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 69 74 ading, should it
2150: 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73 6c 6f be a little slo
2160: 77 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 w.. */..
2170: 57 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c 65 4f WaitForMultipleO
2180: 62 6a 65 63 74 73 28 32 2c 20 70 69 70 65 54 68 bjects(2, pipeTh
2190: 72 65 61 64 73 2c 20 54 52 55 45 2c 20 35 30 30 reads, TRUE, 500
21a0: 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 );. CloseHand
21b0: 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 5b 30 le(pipeThreads[0
21c0: 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e ]);. CloseHan
21d0: 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 5b dle(pipeThreads[
21e0: 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 1]);.. /*.
21f0: 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74 68 65 * Look for the
2200: 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77 61 72 commandline war
2210: 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 62 6f 74 ning code in bot
2220: 68 20 73 74 72 65 61 6d 73 2e 0a 20 20 20 20 20 h streams..
2230: 2a 20 20 2d 20 69 6e 20 4d 53 56 43 20 36 20 26 * - in MSVC 6 &
2240: 20 37 20 77 65 20 67 65 74 20 44 34 30 30 32 2c 7 we get D4002,
2250: 20 69 6e 20 4d 53 56 43 20 38 20 77 65 20 67 65 in MSVC 8 we ge
2260: 74 20 44 39 30 30 32 2e 0a 20 20 20 20 20 2a 2f t D9002.. */
2270: 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 21 28 73 .. return !(s
2280: 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 72 trstr(Out.buffer
2290: 2c 20 22 44 34 30 30 32 22 29 20 21 3d 20 4e 55 , "D4002") != NU
22a0: 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 LL.
22b0: 7c 7c 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 || strstr(Err.bu
22c0: 66 66 65 72 2c 20 22 44 34 30 30 32 22 29 20 21 ffer, "D4002") !
22d0: 3d 20 4e 55 4c 4c 0a 20 20 20 20 20 20 20 20 20 = NULL.
22e0: 20 20 20 20 7c 7c 20 73 74 72 73 74 72 28 4f 75 || strstr(Ou
22f0: 74 2e 62 75 66 66 65 72 2c 20 22 44 39 30 30 32 t.buffer, "D9002
2300: 22 29 20 21 3d 20 4e 55 4c 4c 0a 20 20 20 20 20 ") != NULL.
2310: 20 20 20 20 20 20 20 20 7c 7c 20 73 74 72 73 74 || strst
2320: 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 44 r(Err.buffer, "D
2330: 39 30 30 32 22 29 20 21 3d 20 4e 55 4c 4c 0a 20 9002") != NULL.
2340: 20 20 20 20 20 20 20 20 20 20 20 20 7c 7c 20 73 || s
2350: 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 72 trstr(Out.buffer
2360: 2c 20 22 44 32 30 32 31 22 29 20 21 3d 20 4e 55 , "D2021") != NU
2370: 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 LL.
2380: 7c 7c 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 || strstr(Err.bu
2390: 66 66 65 72 2c 20 22 44 32 30 32 31 22 29 20 21 ffer, "D2021") !
23a0: 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a 73 74 61 = NULL);.}...sta
23b0: 74 69 63 20 69 6e 74 0a 43 68 65 63 6b 46 6f 72 tic int.CheckFor
23c0: 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 0a 20 LinkerFeature(.
23d0: 20 20 20 63 68 61 72 20 2a 2a 6f 70 74 69 6f 6e char **option
23e0: 73 2c 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e 74 s,. int count
23f0: 29 0a 7b 0a 20 20 20 20 53 54 41 52 54 55 50 49 ).{. STARTUPI
2400: 4e 46 4f 20 73 69 3b 0a 20 20 20 20 50 52 4f 43 NFO si;. PROC
2410: 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 ESS_INFORMATION
2420: 70 69 3b 0a 20 20 20 20 53 45 43 55 52 49 54 59 pi;. SECURITY
2430: 5f 41 54 54 52 49 42 55 54 45 53 20 73 61 3b 0a _ATTRIBUTES sa;.
2440: 20 20 20 20 44 57 4f 52 44 20 74 68 72 65 61 64 DWORD thread
2450: 49 44 3b 0a 20 20 20 20 63 68 61 72 20 6d 73 67 ID;. char msg
2460: 5b 33 30 30 5d 3b 0a 20 20 20 20 42 4f 4f 4c 20 [300];. BOOL
2470: 6f 6b 3b 0a 20 20 20 20 48 41 4e 44 4c 45 20 68 ok;. HANDLE h
2480: 50 72 6f 63 65 73 73 2c 20 68 2c 20 70 69 70 65 Process, h, pipe
2490: 54 68 72 65 61 64 73 5b 32 5d 3b 0a 20 20 20 20 Threads[2];.
24a0: 69 6e 74 20 69 3b 0a 20 20 20 20 63 68 61 72 20 int i;. char
24b0: 63 6d 64 6c 69 6e 65 5b 32 35 35 5d 3b 0a 0a 20 cmdline[255];..
24c0: 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20 47 65 hProcess = Ge
24d0: 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73 73 28 tCurrentProcess(
24e0: 29 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26 );.. memset(&
24f0: 70 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 50 52 pi, 0, sizeof(PR
2500: 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 4f OCESS_INFORMATIO
2510: 4e 29 29 3b 0a 20 20 20 20 6d 65 6d 73 65 74 28 N));. memset(
2520: 26 73 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 &si, 0, sizeof(S
2530: 54 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a 20 20 TARTUPINFO));.
2540: 20 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 6f 66 si.cb = sizeof
2550: 28 53 54 41 52 54 55 50 49 4e 46 4f 29 3b 0a 20 (STARTUPINFO);.
2560: 20 20 20 73 69 2e 64 77 46 6c 61 67 73 20 20 20 si.dwFlags
2570: 3d 20 53 54 41 52 54 46 5f 55 53 45 53 54 44 48 = STARTF_USESTDH
2580: 41 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 2e 68 ANDLES;. si.h
2590: 53 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 41 4c StdInput = INVAL
25a0: 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 3b ID_HANDLE_VALUE;
25b0: 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26 73 61 .. memset(&sa
25c0: 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 45 43 55 , 0, sizeof(SECU
25d0: 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 RITY_ATTRIBUTES)
25e0: 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e 67 74 );. sa.nLengt
25f0: 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43 55 52 h = sizeof(SECUR
2600: 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 3b ITY_ATTRIBUTES);
2610: 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75 72 69 . sa.lpSecuri
2620: 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d 20 4e tyDescriptor = N
2630: 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49 6e 68 ULL;. sa.bInh
2640: 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 54 52 55 eritHandle = TRU
2650: 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 E;.. /*.
2660: 2a 20 43 72 65 61 74 65 20 61 20 6e 6f 6e 2d 69 * Create a non-i
2670: 6e 68 65 72 69 74 69 62 6c 65 20 70 69 70 65 2e nheritible pipe.
2680: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 72 . */.. Cr
2690: 65 61 74 65 50 69 70 65 28 26 4f 75 74 2e 70 69 eatePipe(&Out.pi
26a0: 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 3b pe, &h, &sa, 0);
26b0: 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 .. /*. *
26c0: 44 75 70 65 20 74 68 65 20 77 72 69 74 65 20 73 Dupe the write s
26d0: 69 64 65 2c 20 6d 61 6b 65 20 69 74 20 69 6e 68 ide, make it inh
26e0: 65 72 69 74 61 62 6c 65 2c 20 61 6e 64 20 63 6c eritable, and cl
26f0: 6f 73 65 20 74 68 65 20 6f 72 69 67 69 6e 61 6c ose the original
2700: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 44 .. */.. D
2710: 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 68 uplicateHandle(h
2720: 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 6f Process, h, hPro
2730: 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 4f 75 cess, &si.hStdOu
2740: 74 70 75 74 2c 20 30 2c 20 54 52 55 45 2c 0a 09 tput, 0, TRUE,..
2750: 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 41 DUPLICATE_SA
2760: 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 4c ME_ACCESS | DUPL
2770: 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 52 ICATE_CLOSE_SOUR
2780: 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 CE);.. /*.
2790: 20 20 2a 20 53 61 6d 65 20 61 73 20 61 62 6f 76 * Same as abov
27a0: 65 2c 20 62 75 74 20 66 6f 72 20 74 68 65 20 65 e, but for the e
27b0: 72 72 6f 72 20 73 69 64 65 2e 0a 20 20 20 20 20 rror side..
27c0: 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 65 50 69 */.. CreatePi
27d0: 70 65 28 26 45 72 72 2e 70 69 70 65 2c 20 26 68 pe(&Err.pipe, &h
27e0: 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20 20 20 44 , &sa, 0);. D
27f0: 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 68 uplicateHandle(h
2800: 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 6f Process, h, hPro
2810: 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 45 72 cess, &si.hStdEr
2820: 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c 0a 09 20 ror, 0, TRUE,..
2830: 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 41 4d DUPLICATE_SAM
2840: 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 4c 49 E_ACCESS | DUPLI
2850: 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 52 43 CATE_CLOSE_SOURC
2860: 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 E);.. /*.
2870: 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61 6e 64 20 * Base command
2880: 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 line.. */..
2890: 20 20 20 6c 73 74 72 63 70 79 28 63 6d 64 6c 69 lstrcpy(cmdli
28a0: 6e 65 2c 20 22 6c 69 6e 6b 2e 65 78 65 20 2d 6e ne, "link.exe -n
28b0: 6f 6c 6f 67 6f 20 22 29 3b 0a 0a 20 20 20 20 2f ologo ");.. /
28c0: 2a 0a 20 20 20 20 20 2a 20 41 70 70 65 6e 64 20 *. * Append
28d0: 6f 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 our option for t
28e0: 65 73 74 69 6e 67 2e 0a 20 20 20 20 20 2a 2f 0a esting.. */.
28f0: 0a 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 3b . for (i = 0;
2900: 20 69 20 3c 20 63 6f 75 6e 74 3b 20 69 2b 2b 29 i < count; i++)
2910: 20 7b 0a 09 6c 73 74 72 63 61 74 28 63 6d 64 6c {..lstrcat(cmdl
2920: 69 6e 65 2c 20 22 20 5c 22 22 29 3b 0a 09 6c 73 ine, " \"");..ls
2930: 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 6f trcat(cmdline, o
2940: 70 74 69 6f 6e 73 5b 69 5d 29 3b 0a 09 6c 73 74 ptions[i]);..lst
2950: 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 22 5c rcat(cmdline, "\
2960: 22 22 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 "");. }..
2970: 6f 6b 20 3d 20 43 72 65 61 74 65 50 72 6f 63 65 ok = CreateProce
2980: 73 73 28 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 ss(.. NULL,.
2990: 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 6e 61 6d /* Module nam
29a0: 65 2e 20 2a 2f 0a 09 20 20 20 20 63 6d 64 6c 69 e. */.. cmdli
29b0: 6e 65 2c 09 20 20 20 20 2f 2a 20 43 6f 6d 6d 61 ne,. /* Comma
29c0: 6e 64 20 6c 69 6e 65 2e 20 2a 2f 0a 09 20 20 20 nd line. */..
29d0: 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 50 72 NULL,. /* Pr
29e0: 6f 63 65 73 73 20 68 61 6e 64 6c 65 20 6e 6f 74 ocess handle not
29f0: 20 69 6e 68 65 72 69 74 61 62 6c 65 2e 20 2a 2f inheritable. */
2a00: 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 .. NULL,.
2a10: 2f 2a 20 54 68 72 65 61 64 20 68 61 6e 64 6c 65 /* Thread handle
2a20: 20 6e 6f 74 20 69 6e 68 65 72 69 74 61 62 6c 65 not inheritable
2a30: 2e 20 2a 2f 0a 09 20 20 20 20 54 52 55 45 2c 09 . */.. TRUE,.
2a40: 20 20 20 20 2f 2a 20 79 65 73 2c 20 69 6e 68 65 /* yes, inhe
2a50: 72 69 74 20 68 61 6e 64 6c 65 73 2e 20 2a 2f 0a rit handles. */.
2a60: 09 20 20 20 20 44 45 54 41 43 48 45 44 5f 50 52 . DETACHED_PR
2a70: 4f 43 45 53 53 2c 20 2f 2a 20 4e 6f 20 63 6f 6e OCESS, /* No con
2a80: 73 6f 6c 65 20 66 6f 72 20 79 6f 75 2e 20 2a 2f sole for you. */
2a90: 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 .. NULL,.
2aa0: 2f 2a 20 55 73 65 20 70 61 72 65 6e 74 27 73 20 /* Use parent's
2ab0: 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 62 6c 6f 63 environment bloc
2ac0: 6b 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c k. */.. NULL,
2ad0: 09 20 20 20 20 2f 2a 20 55 73 65 20 70 61 72 65 . /* Use pare
2ae0: 6e 74 27 73 20 73 74 61 72 74 69 6e 67 20 64 69 nt's starting di
2af0: 72 65 63 74 6f 72 79 2e 20 2a 2f 0a 09 20 20 20 rectory. */..
2b00: 20 26 73 69 2c 09 20 20 20 20 2f 2a 20 50 6f 69 &si,. /* Poi
2b10: 6e 74 65 72 20 74 6f 20 53 54 41 52 54 55 50 49 nter to STARTUPI
2b20: 4e 46 4f 20 73 74 72 75 63 74 75 72 65 2e 20 2a NFO structure. *
2b30: 2f 0a 09 20 20 20 20 26 70 69 29 3b 09 20 20 20 /.. &pi);.
2b40: 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 50 /* Pointer to P
2b50: 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 ROCESS_INFORMATI
2b60: 4f 4e 20 73 74 72 75 63 74 75 72 65 2e 20 2a 2f ON structure. */
2b70: 0a 0a 20 20 20 20 69 66 20 28 21 6f 6b 29 20 7b .. if (!ok) {
2b80: 0a 09 44 57 4f 52 44 20 65 72 72 20 3d 20 47 65 ..DWORD err = Ge
2b90: 74 4c 61 73 74 45 72 72 6f 72 28 29 3b 0a 09 69 tLastError();..i
2ba0: 6e 74 20 63 68 61 72 73 20 3d 20 73 6e 70 72 69 nt chars = snpri
2bb0: 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 ntf(msg, sizeof(
2bc0: 6d 73 67 29 20 2d 20 31 2c 0a 09 09 22 54 72 69 msg) - 1,..."Tri
2bd0: 65 64 20 74 6f 20 6c 61 75 6e 63 68 3a 20 5c 22 ed to launch: \"
2be0: 25 73 5c 22 2c 20 62 75 74 20 67 6f 74 20 65 72 %s\", but got er
2bf0: 72 6f 72 20 5b 25 6c 75 5d 3a 20 22 2c 20 63 6d ror [%lu]: ", cm
2c00: 64 6c 69 6e 65 2c 20 65 72 72 29 3b 0a 0a 09 46 dline, err);...F
2c10: 6f 72 6d 61 74 4d 65 73 73 61 67 65 28 46 4f 52 ormatMessage(FOR
2c20: 4d 41 54 5f 4d 45 53 53 41 47 45 5f 46 52 4f 4d MAT_MESSAGE_FROM
2c30: 5f 53 59 53 54 45 4d 7c 46 4f 52 4d 41 54 5f 4d _SYSTEM|FORMAT_M
2c40: 45 53 53 41 47 45 5f 49 47 4e 4f 52 45 5f 49 4e ESSAGE_IGNORE_IN
2c50: 53 45 52 54 53 7c 0a 09 09 46 4f 52 4d 41 54 5f SERTS|...FORMAT_
2c60: 4d 45 53 53 41 47 45 5f 4d 41 58 5f 57 49 44 54 MESSAGE_MAX_WIDT
2c70: 48 5f 4d 41 53 4b 2c 20 30 4c 2c 20 65 72 72 2c H_MASK, 0L, err,
2c80: 20 30 2c 20 28 4c 50 53 54 52 29 26 6d 73 67 5b 0, (LPSTR)&msg[
2c90: 63 68 61 72 73 5d 2c 0a 09 09 28 33 30 30 2d 63 chars],...(300-c
2ca0: 68 61 72 73 29 2c 20 30 29 3b 0a 09 57 72 69 74 hars), 0);..Writ
2cb0: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 eFile(GetStdHand
2cc0: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e le(STD_ERROR_HAN
2cd0: 44 4c 45 29 2c 20 6d 73 67 2c 20 6c 73 74 72 6c DLE), msg, lstrl
2ce0: 65 6e 28 6d 73 67 29 2c 20 26 65 72 72 2c 4e 55 en(msg), &err,NU
2cf0: 4c 4c 29 3b 0a 09 72 65 74 75 72 6e 20 32 3b 0a LL);..return 2;.
2d00: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 }.. /*.
2d10: 20 20 20 2a 20 43 6c 6f 73 65 20 6f 75 72 20 72 * Close our r
2d20: 65 66 65 72 65 6e 63 65 73 20 74 6f 20 74 68 65 eferences to the
2d30: 20 77 72 69 74 65 20 68 61 6e 64 6c 65 73 20 74 write handles t
2d40: 68 61 74 20 68 61 76 65 20 6e 6f 77 20 62 65 65 hat have now bee
2d50: 6e 20 69 6e 68 65 72 69 74 65 64 2e 0a 20 20 20 n inherited..
2d60: 20 20 2a 2f 0a 0a 20 20 20 20 43 6c 6f 73 65 48 */.. CloseH
2d70: 61 6e 64 6c 65 28 73 69 2e 68 53 74 64 4f 75 74 andle(si.hStdOut
2d80: 70 75 74 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 put);. CloseH
2d90: 61 6e 64 6c 65 28 73 69 2e 68 53 74 64 45 72 72 andle(si.hStdErr
2da0: 6f 72 29 3b 0a 0a 20 20 20 20 57 61 69 74 46 6f or);.. WaitFo
2db0: 72 49 6e 70 75 74 49 64 6c 65 28 70 69 2e 68 50 rInputIdle(pi.hP
2dc0: 72 6f 63 65 73 73 2c 20 35 30 30 30 29 3b 0a 20 rocess, 5000);.
2dd0: 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 CloseHandle(p
2de0: 69 2e 68 54 68 72 65 61 64 29 3b 0a 0a 20 20 20 i.hThread);..
2df0: 20 2f 2a 0a 20 20 20 20 20 2a 20 53 74 61 72 74 /*. * Start
2e00: 20 74 68 65 20 70 69 70 65 20 72 65 61 64 65 72 the pipe reader
2e10: 20 74 68 72 65 61 64 73 2e 0a 20 20 20 20 20 2a threads.. *
2e20: 2f 0a 0a 20 20 20 20 70 69 70 65 54 68 72 65 61 /.. pipeThrea
2e30: 64 73 5b 30 5d 20 3d 20 43 72 65 61 74 65 54 68 ds[0] = CreateTh
2e40: 72 65 61 64 28 4e 55 4c 4c 2c 20 30 2c 20 52 65 read(NULL, 0, Re
2e50: 61 64 46 72 6f 6d 50 69 70 65 2c 20 26 4f 75 74 adFromPipe, &Out
2e60: 2c 20 30 2c 20 26 74 68 72 65 61 64 49 44 29 3b , 0, &threadID);
2e70: 0a 20 20 20 20 70 69 70 65 54 68 72 65 61 64 73 . pipeThreads
2e80: 5b 31 5d 20 3d 20 43 72 65 61 74 65 54 68 72 65 [1] = CreateThre
2e90: 61 64 28 4e 55 4c 4c 2c 20 30 2c 20 52 65 61 64 ad(NULL, 0, Read
2ea0: 46 72 6f 6d 50 69 70 65 2c 20 26 45 72 72 2c 20 FromPipe, &Err,
2eb0: 30 2c 20 26 74 68 72 65 61 64 49 44 29 3b 0a 0a 0, &threadID);..
2ec0: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 42 6c /*. * Bl
2ed0: 6f 63 6b 20 77 61 69 74 69 6e 67 20 66 6f 72 20 ock waiting for
2ee0: 74 68 65 20 70 72 6f 63 65 73 73 20 74 6f 20 65 the process to e
2ef0: 6e 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 nd.. */..
2f00: 20 57 61 69 74 46 6f 72 53 69 6e 67 6c 65 4f 62 WaitForSingleOb
2f10: 6a 65 63 74 28 70 69 2e 68 50 72 6f 63 65 73 73 ject(pi.hProcess
2f20: 2c 20 49 4e 46 49 4e 49 54 45 29 3b 0a 20 20 20 , INFINITE);.
2f30: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 2e CloseHandle(pi.
2f40: 68 50 72 6f 63 65 73 73 29 3b 0a 0a 20 20 20 20 hProcess);..
2f50: 2f 2a 0a 20 20 20 20 20 2a 20 57 61 69 74 20 66 /*. * Wait f
2f60: 6f 72 20 6f 75 72 20 70 69 70 65 20 74 6f 20 67 or our pipe to g
2f70: 65 74 20 64 6f 6e 65 20 72 65 61 64 69 6e 67 2c et done reading,
2f80: 20 73 68 6f 75 6c 64 20 69 74 20 62 65 20 61 20 should it be a
2f90: 6c 69 74 74 6c 65 20 73 6c 6f 77 2e 0a 20 20 20 little slow..
2fa0: 20 20 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f */.. WaitFo
2fb0: 72 4d 75 6c 74 69 70 6c 65 4f 62 6a 65 63 74 73 rMultipleObjects
2fc0: 28 32 2c 20 70 69 70 65 54 68 72 65 61 64 73 2c (2, pipeThreads,
2fd0: 20 54 52 55 45 2c 20 35 30 30 29 3b 0a 20 20 20 TRUE, 500);.
2fe0: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 70 CloseHandle(pip
2ff0: 65 54 68 72 65 61 64 73 5b 30 5d 29 3b 0a 20 20 eThreads[0]);.
3000: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 CloseHandle(pi
3010: 70 65 54 68 72 65 61 64 73 5b 31 5d 29 3b 0a 0a peThreads[1]);..
3020: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4c 6f /*. * Lo
3030: 6f 6b 20 66 6f 72 20 74 68 65 20 63 6f 6d 6d 61 ok for the comma
3040: 6e 64 6c 69 6e 65 20 77 61 72 6e 69 6e 67 20 63 ndline warning c
3050: 6f 64 65 20 69 6e 20 74 68 65 20 73 74 64 65 72 ode in the stder
3060: 72 20 73 74 72 65 61 6d 2e 0a 20 20 20 20 20 2a r stream.. *
3070: 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 21 28 /.. return !(
3080: 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 strstr(Out.buffe
3090: 72 2c 20 22 4c 4e 4b 31 31 31 37 22 29 20 21 3d r, "LNK1117") !=
30a0: 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 73 74 NULL ||.. st
30b0: 72 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c rstr(Err.buffer,
30c0: 20 22 4c 4e 4b 31 31 31 37 22 29 20 21 3d 20 4e "LNK1117") != N
30d0: 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 73 74 72 73 ULL ||.. strs
30e0: 74 72 28 4f 75 74 2e 62 75 66 66 65 72 2c 20 22 tr(Out.buffer, "
30f0: 4c 4e 4b 34 30 34 34 22 29 20 21 3d 20 4e 55 4c LNK4044") != NUL
3100: 4c 20 7c 7c 0a 09 20 20 20 20 73 74 72 73 74 72 L ||.. strstr
3110: 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 4c 4e (Err.buffer, "LN
3120: 4b 34 30 34 34 22 29 20 21 3d 20 4e 55 4c 4c 20 K4044") != NULL
3130: 7c 7c 0a 09 20 20 20 20 73 74 72 73 74 72 28 4f ||.. strstr(O
3140: 75 74 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 34 ut.buffer, "LNK4
3150: 32 32 34 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 224") != NULL ||
3160: 0a 09 20 20 20 20 73 74 72 73 74 72 28 45 72 72 .. strstr(Err
3170: 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 34 32 32 .buffer, "LNK422
3180: 34 22 29 20 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 4") != NULL);.}.
3190: 0c 0a 73 74 61 74 69 63 20 44 57 4f 52 44 20 57 ..static DWORD W
31a0: 49 4e 41 50 49 0a 52 65 61 64 46 72 6f 6d 50 69 INAPI.ReadFromPi
31b0: 70 65 28 0a 20 20 20 20 4c 50 56 4f 49 44 20 61 pe(. LPVOID a
31c0: 72 67 73 29 0a 7b 0a 20 20 20 20 70 69 70 65 69 rgs).{. pipei
31d0: 6e 66 6f 20 2a 70 69 20 3d 20 28 70 69 70 65 69 nfo *pi = (pipei
31e0: 6e 66 6f 20 2a 29 20 61 72 67 73 3b 0a 20 20 20 nfo *) args;.
31f0: 20 63 68 61 72 20 2a 6c 61 73 74 42 75 66 20 3d char *lastBuf =
3200: 20 70 69 2d 3e 62 75 66 66 65 72 3b 0a 20 20 20 pi->buffer;.
3210: 20 44 57 4f 52 44 20 64 77 52 65 61 64 3b 0a 20 DWORD dwRead;.
3220: 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 0a 20 20 61 BOOL ok;.. a
3230: 67 61 69 6e 3a 0a 20 20 20 20 69 66 20 28 6c 61 gain:. if (la
3240: 73 74 42 75 66 20 2d 20 70 69 2d 3e 62 75 66 66 stBuf - pi->buff
3250: 65 72 20 2b 20 43 48 55 4e 4b 20 3e 20 53 54 41 er + CHUNK > STA
3260: 54 49 43 42 55 46 46 45 52 53 49 5a 45 29 20 7b TICBUFFERSIZE) {
3270: 0a 09 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 ..CloseHandle(pi
3280: 2d 3e 70 69 70 65 29 3b 0a 09 72 65 74 75 72 6e ->pipe);..return
3290: 20 28 44 57 4f 52 44 29 2d 31 3b 0a 20 20 20 20 (DWORD)-1;.
32a0: 7d 0a 20 20 20 20 6f 6b 20 3d 20 52 65 61 64 46 }. ok = ReadF
32b0: 69 6c 65 28 70 69 2d 3e 70 69 70 65 2c 20 6c 61 ile(pi->pipe, la
32c0: 73 74 42 75 66 2c 20 43 48 55 4e 4b 2c 20 26 64 stBuf, CHUNK, &d
32d0: 77 52 65 61 64 2c 20 30 4c 29 3b 0a 20 20 20 20 wRead, 0L);.
32e0: 69 66 20 28 21 6f 6b 20 7c 7c 20 64 77 52 65 61 if (!ok || dwRea
32f0: 64 20 3d 3d 20 30 29 20 7b 0a 09 43 6c 6f 73 65 d == 0) {..Close
3300: 48 61 6e 64 6c 65 28 70 69 2d 3e 70 69 70 65 29 Handle(pi->pipe)
3310: 3b 0a 09 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 ;..return 0;.
3320: 20 7d 0a 20 20 20 20 6c 61 73 74 42 75 66 20 2b }. lastBuf +
3330: 3d 20 64 77 52 65 61 64 3b 0a 20 20 20 20 67 6f = dwRead;. go
3340: 74 6f 20 61 67 61 69 6e 3b 0a 0a 20 20 20 20 72 to again;.. r
3350: 65 74 75 72 6e 20 30 3b 20 20 2f 2a 20 6d 61 6b eturn 0; /* mak
3360: 65 73 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 es the compiler
3370: 68 61 70 70 79 20 2a 2f 0a 7d 0a 0c 0a 73 74 61 happy */.}...sta
3380: 74 69 63 20 69 6e 74 0a 49 73 49 6e 28 0a 20 20 tic int.IsIn(.
3390: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 const char *st
33a0: 72 69 6e 67 2c 0a 20 20 20 20 63 6f 6e 73 74 20 ring,. const
33b0: 63 68 61 72 20 2a 73 75 62 73 74 72 69 6e 67 29 char *substring)
33c0: 0a 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 28 73 .{. return (s
33d0: 74 72 73 74 72 28 73 74 72 69 6e 67 2c 20 73 75 trstr(string, su
33e0: 62 73 74 72 69 6e 67 29 20 21 3d 20 4e 55 4c 4c bstring) != NULL
33f0: 29 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74 );.}.../*. * Get
3400: 56 65 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 20 VersionFromFile
3410: 2d 2d 0a 20 2a 20 09 4c 6f 6f 6b 73 20 66 6f 72 --. * .Looks for
3420: 20 61 20 6d 61 74 63 68 20 73 74 72 69 6e 67 20 a match string
3430: 69 6e 20 61 20 66 69 6c 65 20 61 6e 64 20 74 68 in a file and th
3440: 65 6e 20 72 65 74 75 72 6e 73 20 74 68 65 20 76 en returns the v
3450: 65 72 73 69 6f 6e 0a 20 2a 20 09 66 6f 6c 6c 6f ersion. * .follo
3460: 77 69 6e 67 20 74 68 65 20 6d 61 74 63 68 20 77 wing the match w
3470: 68 65 72 65 20 61 20 76 65 72 73 69 6f 6e 20 69 here a version i
3480: 73 20 61 6e 79 74 68 69 6e 67 20 61 63 63 65 70 s anything accep
3490: 74 61 62 6c 65 20 74 6f 0a 20 2a 20 09 70 61 63 table to. * .pac
34a0: 6b 61 67 65 20 70 72 6f 76 69 64 65 20 6f 72 20 kage provide or
34b0: 70 61 63 6b 61 67 65 20 69 66 6e 65 65 64 65 64 package ifneeded
34c0: 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 63 6f .. */..static co
34d0: 6e 73 74 20 63 68 61 72 20 2a 0a 47 65 74 56 65 nst char *.GetVe
34e0: 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 0a 20 rsionFromFile(.
34f0: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 const char *f
3500: 69 6c 65 6e 61 6d 65 2c 0a 20 20 20 20 63 6f 6e ilename,. con
3510: 73 74 20 63 68 61 72 20 2a 6d 61 74 63 68 2c 0a st char *match,.
3520: 20 20 20 20 69 6e 74 20 6e 75 6d 64 6f 74 73 29 int numdots)
3530: 0a 7b 0a 20 20 20 20 73 74 61 74 69 63 20 63 68 .{. static ch
3540: 61 72 20 73 7a 42 75 66 66 65 72 5b 31 30 30 5d ar szBuffer[100]
3550: 3b 0a 20 20 20 20 63 68 61 72 20 2a 73 7a 52 65 ;. char *szRe
3560: 73 75 6c 74 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 sult = NULL;.
3570: 20 46 49 4c 45 20 2a 66 70 20 3d 20 66 6f 70 65 FILE *fp = fope
3580: 6e 28 66 69 6c 65 6e 61 6d 65 2c 20 22 72 74 22 n(filename, "rt"
3590: 29 3b 0a 0a 20 20 20 20 69 66 20 28 66 70 20 21 );.. if (fp !
35a0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 2f 2a 0a 09 20 = NULL) {../*..
35b0: 2a 20 52 65 61 64 20 64 61 74 61 20 75 6e 74 69 * Read data unti
35c0: 6c 20 77 65 20 73 65 65 20 6f 75 72 20 6d 61 74 l we see our mat
35d0: 63 68 20 73 74 72 69 6e 67 2e 0a 09 20 2a 2f 0a ch string... */.
35e0: 0a 09 77 68 69 6c 65 20 28 66 67 65 74 73 28 73 ..while (fgets(s
35f0: 7a 42 75 66 66 65 72 2c 20 73 69 7a 65 6f 66 28 zBuffer, sizeof(
3600: 73 7a 42 75 66 66 65 72 29 2c 20 66 70 29 20 21 szBuffer), fp) !
3610: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 4c = NULL) {.. L
3620: 50 53 54 52 20 70 2c 20 71 3b 0a 0a 09 20 20 20 PSTR p, q;...
3630: 20 70 20 3d 20 73 74 72 73 74 72 28 73 7a 42 75 p = strstr(szBu
3640: 66 66 65 72 2c 20 6d 61 74 63 68 29 3b 0a 09 20 ffer, match);..
3650: 20 20 20 69 66 20 28 70 20 21 3d 20 4e 55 4c 4c if (p != NULL
3660: 29 20 7b 0a 09 09 2f 2a 0a 09 09 20 2a 20 53 6b ) {.../*... * Sk
3670: 69 70 20 74 6f 20 66 69 72 73 74 20 64 69 67 69 ip to first digi
3680: 74 20 61 66 74 65 72 20 74 68 65 20 6d 61 74 63 t after the matc
3690: 68 2e 0a 09 09 20 2a 2f 0a 0a 09 09 70 20 2b 3d h.... */....p +=
36a0: 20 73 74 72 6c 65 6e 28 6d 61 74 63 68 29 3b 0a strlen(match);.
36b0: 09 09 77 68 69 6c 65 20 28 2a 70 20 26 26 20 21 ..while (*p && !
36c0: 69 73 64 69 67 69 74 28 28 75 6e 73 69 67 6e 65 isdigit((unsigne
36d0: 64 20 63 68 61 72 29 2a 70 29 29 20 7b 0a 09 09 d char)*p)) {...
36e0: 20 20 20 20 2b 2b 70 3b 0a 09 09 7d 0a 0a 09 09 ++p;...}....
36f0: 2f 2a 0a 09 09 20 2a 20 46 69 6e 64 20 65 6e 64 /*... * Find end
3700: 69 6e 67 20 77 68 69 74 65 73 70 61 63 65 2e 0a ing whitespace..
3710: 09 09 20 2a 2f 0a 0a 09 09 71 20 3d 20 70 3b 0a .. */....q = p;.
3720: 09 09 77 68 69 6c 65 20 28 2a 71 20 26 26 20 28 ..while (*q && (
3730: 73 74 72 63 68 72 28 22 30 31 32 33 34 35 36 37 strchr("01234567
3740: 38 39 2e 61 62 22 2c 20 2a 71 29 29 20 26 26 20 89.ab", *q)) &&
3750: 28 28 28 21 73 74 72 63 68 72 28 22 2e 61 62 22 (((!strchr(".ab"
3760: 2c 20 2a 71 29 0a 09 09 09 20 20 20 20 26 26 20 , *q).... &&
3770: 21 73 74 72 63 68 72 28 22 61 62 22 2c 20 71 5b !strchr("ab", q[
3780: 2d 31 5d 29 29 20 7c 7c 20 2d 2d 6e 75 6d 64 6f -1])) || --numdo
3790: 74 73 29 29 29 20 7b 0a 09 09 20 20 20 20 2b 2b ts))) {... ++
37a0: 71 3b 0a 09 09 7d 0a 0a 09 09 2a 71 20 3d 20 30 q;...}....*q = 0
37b0: 3b 0a 09 09 73 7a 52 65 73 75 6c 74 20 3d 20 70 ;...szResult = p
37c0: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 20 20 20 20 ;...break;..
37d0: 7d 0a 09 7d 0a 09 66 63 6c 6f 73 65 28 66 70 29 }..}..fclose(fp)
37e0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 ;. }. retu
37f0: 72 6e 20 73 7a 52 65 73 75 6c 74 3b 0a 7d 0a 0c rn szResult;.}..
3800: 0a 2f 2a 0a 20 2a 20 4c 69 73 74 20 68 65 6c 70 ./*. * List help
3810: 65 72 73 20 66 6f 72 20 74 68 65 20 53 75 62 73 ers for the Subs
3820: 74 69 74 75 74 65 46 69 6c 65 20 66 75 6e 63 74 tituteFile funct
3830: 69 6f 6e 0a 20 2a 2f 0a 0a 74 79 70 65 64 65 66 ion. */..typedef
3840: 20 73 74 72 75 63 74 20 6c 69 73 74 5f 69 74 65 struct list_ite
3850: 6d 5f 74 20 7b 0a 20 20 20 20 73 74 72 75 63 74 m_t {. struct
3860: 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 6e 65 list_item_t *ne
3870: 78 74 50 74 72 3b 0a 20 20 20 20 63 68 61 72 20 xtPtr;. char
3880: 2a 20 6b 65 79 3b 0a 20 20 20 20 63 68 61 72 20 * key;. char
3890: 2a 20 76 61 6c 75 65 3b 0a 7d 20 6c 69 73 74 5f * value;.} list_
38a0: 69 74 65 6d 5f 74 3b 0a 0a 2f 2a 20 69 6e 73 65 item_t;../* inse
38b0: 72 74 20 61 20 6c 69 73 74 20 69 74 65 6d 20 69 rt a list item i
38c0: 6e 74 6f 20 74 68 65 20 6c 69 73 74 20 28 6c 69 nto the list (li
38d0: 73 74 20 6d 61 79 20 62 65 20 6e 75 6c 6c 29 20 st may be null)
38e0: 2a 2f 0a 73 74 61 74 69 63 20 6c 69 73 74 5f 69 */.static list_i
38f0: 74 65 6d 5f 74 20 2a 0a 6c 69 73 74 5f 69 6e 73 tem_t *.list_ins
3900: 65 72 74 28 6c 69 73 74 5f 69 74 65 6d 5f 74 20 ert(list_item_t
3910: 2a 2a 6c 69 73 74 50 74 72 50 74 72 2c 20 63 6f **listPtrPtr, co
3920: 6e 73 74 20 63 68 61 72 20 2a 6b 65 79 2c 20 63 nst char *key, c
3930: 6f 6e 73 74 20 63 68 61 72 20 2a 76 61 6c 75 65 onst char *value
3940: 29 0a 7b 0a 20 20 20 20 6c 69 73 74 5f 69 74 65 ).{. list_ite
3950: 6d 5f 74 20 2a 69 74 65 6d 50 74 72 20 3d 20 28 m_t *itemPtr = (
3960: 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 29 6d 61 list_item_t *)ma
3970: 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 6c 69 73 74 lloc(sizeof(list
3980: 5f 69 74 65 6d 5f 74 29 29 3b 0a 20 20 20 20 69 _item_t));. i
3990: 66 20 28 69 74 65 6d 50 74 72 29 20 7b 0a 09 69 f (itemPtr) {..i
39a0: 74 65 6d 50 74 72 2d 3e 6b 65 79 20 3d 20 73 74 temPtr->key = st
39b0: 72 64 75 70 28 6b 65 79 29 3b 0a 09 69 74 65 6d rdup(key);..item
39c0: 50 74 72 2d 3e 76 61 6c 75 65 20 3d 20 73 74 72 Ptr->value = str
39d0: 64 75 70 28 76 61 6c 75 65 29 3b 0a 09 69 74 65 dup(value);..ite
39e0: 6d 50 74 72 2d 3e 6e 65 78 74 50 74 72 20 3d 20 mPtr->nextPtr =
39f0: 4e 55 4c 4c 3b 0a 0a 09 77 68 69 6c 65 28 2a 6c NULL;...while(*l
3a00: 69 73 74 50 74 72 50 74 72 29 20 7b 0a 09 20 20 istPtrPtr) {..
3a10: 20 20 6c 69 73 74 50 74 72 50 74 72 20 3d 20 26 listPtrPtr = &
3a20: 28 2a 6c 69 73 74 50 74 72 50 74 72 29 2d 3e 6e (*listPtrPtr)->n
3a30: 65 78 74 50 74 72 3b 0a 09 7d 0a 09 2a 6c 69 73 extPtr;..}..*lis
3a40: 74 50 74 72 50 74 72 20 3d 20 69 74 65 6d 50 74 tPtrPtr = itemPt
3a50: 72 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 r;. }. ret
3a60: 75 72 6e 20 69 74 65 6d 50 74 72 3b 0a 7d 0a 0a urn itemPtr;.}..
3a70: 73 74 61 74 69 63 20 76 6f 69 64 0a 6c 69 73 74 static void.list
3a80: 5f 66 72 65 65 28 6c 69 73 74 5f 69 74 65 6d 5f _free(list_item_
3a90: 74 20 2a 2a 6c 69 73 74 50 74 72 50 74 72 29 0a t **listPtrPtr).
3aa0: 7b 0a 20 20 20 20 6c 69 73 74 5f 69 74 65 6d 5f {. list_item_
3ab0: 74 20 2a 74 6d 70 50 74 72 2c 20 2a 6c 69 73 74 t *tmpPtr, *list
3ac0: 50 74 72 20 3d 20 2a 6c 69 73 74 50 74 72 50 74 Ptr = *listPtrPt
3ad0: 72 3b 0a 20 20 20 20 77 68 69 6c 65 20 28 6c 69 r;. while (li
3ae0: 73 74 50 74 72 29 20 7b 0a 09 74 6d 70 50 74 72 stPtr) {..tmpPtr
3af0: 20 3d 20 6c 69 73 74 50 74 72 3b 0a 09 6c 69 73 = listPtr;..lis
3b00: 74 50 74 72 20 3d 20 6c 69 73 74 50 74 72 2d 3e tPtr = listPtr->
3b10: 6e 65 78 74 50 74 72 3b 0a 09 66 72 65 65 28 74 nextPtr;..free(t
3b20: 6d 70 50 74 72 2d 3e 6b 65 79 29 3b 0a 09 66 72 mpPtr->key);..fr
3b30: 65 65 28 74 6d 70 50 74 72 2d 3e 76 61 6c 75 65 ee(tmpPtr->value
3b40: 29 3b 0a 09 66 72 65 65 28 74 6d 70 50 74 72 29 );..free(tmpPtr)
3b50: 3b 0a 20 20 20 20 7d 0a 7d 0a 0c 0a 2f 2a 0a 20 ;. }.}.../*.
3b60: 2a 20 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 * SubstituteFile
3b70: 20 2d 2d 0a 20 2a 09 41 73 20 77 69 6e 64 6f 77 --. *.As window
3b80: 73 20 64 6f 65 73 6e 27 74 20 70 72 6f 76 69 64 s doesn't provid
3b90: 65 20 61 6e 79 74 68 69 6e 67 20 75 73 65 66 75 e anything usefu
3ba0: 6c 20 6c 69 6b 65 20 73 65 64 20 61 6e 64 20 69 l like sed and i
3bb0: 74 27 73 20 75 6e 72 65 6c 69 61 62 6c 65 0a 20 t's unreliable.
3bc0: 2a 09 74 6f 20 75 73 65 20 74 68 65 20 74 63 6c *.to use the tcl
3bd0: 73 68 20 79 6f 75 20 61 72 65 20 62 75 69 6c 64 sh you are build
3be0: 69 6e 67 20 61 67 61 69 6e 73 74 20 28 63 6f 6e ing against (con
3bf0: 73 69 64 65 72 20 78 2d 70 6c 61 74 66 6f 72 6d sider x-platform
3c00: 20 62 75 69 6c 64 73 20 2d 0a 20 2a 09 65 2e 67 builds -. *.e.g
3c10: 2e 20 63 6f 6d 70 69 6c 69 6e 67 20 41 4d 44 36 . compiling AMD6
3c20: 34 20 74 61 72 67 65 74 20 66 72 6f 6d 20 49 58 4 target from IX
3c30: 38 36 29 20 77 65 20 70 72 6f 76 69 64 65 20 61 86) we provide a
3c40: 20 73 69 6d 70 6c 65 20 73 75 62 73 74 69 74 75 simple substitu
3c50: 74 69 6f 6e 0a 20 2a 09 6f 70 74 69 6f 6e 20 68 tion. *.option h
3c60: 65 72 65 20 74 6f 20 68 61 6e 64 6c 65 20 61 75 ere to handle au
3c70: 74 6f 63 6f 6e 66 20 73 74 79 6c 65 20 73 75 62 toconf style sub
3c80: 73 74 69 74 75 74 69 6f 6e 73 2e 0a 20 2a 09 54 stitutions.. *.T
3c90: 68 65 20 73 75 62 73 74 69 74 75 74 69 6f 6e 20 he substitution
3ca0: 66 69 6c 65 20 69 73 20 77 68 69 74 65 73 70 61 file is whitespa
3cb0: 63 65 20 61 6e 64 20 6c 69 6e 65 20 64 65 6c 69 ce and line deli
3cc0: 6d 69 74 65 64 2e 20 54 68 65 20 66 69 6c 65 20 mited. The file
3cd0: 73 68 6f 75 6c 64 0a 20 2a 09 63 6f 6e 73 69 73 should. *.consis
3ce0: 74 20 6f 66 20 6c 69 6e 65 73 20 6d 61 74 63 68 t of lines match
3cf0: 69 6e 67 20 74 68 65 20 72 65 67 75 6c 61 72 20 ing the regular
3d00: 65 78 70 72 65 73 73 69 6f 6e 3a 0a 20 2a 09 20 expression:. *.
3d10: 20 5c 73 2a 5c 53 2b 5c 73 2b 5c 53 2a 24 0a 20 \s*\S+\s+\S*$.
3d20: 2a 0a 20 2a 09 55 73 61 67 65 20 69 73 20 73 6f *. *.Usage is so
3d30: 6d 65 74 68 69 6e 67 20 6c 69 6b 65 3a 0a 20 2a mething like:. *
3d40: 09 20 20 6e 6d 61 6b 65 68 6c 70 20 2d 53 20 3c . nmakehlp -S <
3d50: 3c 20 24 2a 2a 20 3e 20 24 40 0a 20 2a 20 20 20 < $** > $@. *
3d60: 20 20 20 20 20 40 50 41 43 4b 41 47 45 5f 4e 41 @PACKAGE_NA
3d70: 4d 45 40 20 24 28 50 41 43 4b 41 47 45 5f 4e 41 ME@ $(PACKAGE_NA
3d80: 4d 45 29 0a 20 2a 20 20 20 20 20 20 20 20 40 50 ME). * @P
3d90: 41 43 4b 41 47 45 5f 56 45 52 53 49 4f 4e 40 20 ACKAGE_VERSION@
3da0: 24 28 50 41 43 4b 41 47 45 5f 56 45 52 53 49 4f $(PACKAGE_VERSIO
3db0: 4e 29 0a 20 2a 20 20 20 20 20 20 20 20 3c 3c 0a N). * <<.
3dc0: 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a */..static int.
3dd0: 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 28 0a SubstituteFile(.
3de0: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
3df0: 73 75 62 73 74 69 74 75 74 69 6f 6e 73 2c 0a 20 substitutions,.
3e00: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 const char *f
3e10: 69 6c 65 6e 61 6d 65 29 0a 7b 0a 20 20 20 20 73 ilename).{. s
3e20: 74 61 74 69 63 20 63 68 61 72 20 73 7a 42 75 66 tatic char szBuf
3e30: 66 65 72 5b 31 30 32 34 5d 2c 20 73 7a 43 6f 70 fer[1024], szCop
3e40: 79 5b 31 30 32 34 5d 3b 0a 20 20 20 20 6c 69 73 y[1024];. lis
3e50: 74 5f 69 74 65 6d 5f 74 20 2a 73 75 62 73 74 50 t_item_t *substP
3e60: 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 46 tr = NULL;. F
3e70: 49 4c 45 20 2a 66 70 2c 20 2a 73 70 3b 0a 0a 20 ILE *fp, *sp;..
3e80: 20 20 20 66 70 20 3d 20 66 6f 70 65 6e 28 66 69 fp = fopen(fi
3e90: 6c 65 6e 61 6d 65 2c 20 22 72 74 22 29 3b 0a 20 lename, "rt");.
3ea0: 20 20 20 69 66 20 28 66 70 20 21 3d 20 4e 55 4c if (fp != NUL
3eb0: 4c 29 20 7b 0a 0a 09 2f 2a 0a 09 20 2a 20 42 75 L) {.../*.. * Bu
3ec0: 69 6c 64 20 61 20 6c 69 73 74 20 6f 66 20 73 75 ild a list of su
3ed0: 62 73 74 69 74 75 74 69 6f 6e 73 20 66 72 6f 6d bstitutions from
3ee0: 20 74 68 65 20 66 69 72 73 74 20 66 69 6c 65 6e the first filen
3ef0: 61 6d 65 0a 09 20 2a 2f 0a 0a 09 73 70 20 3d 20 ame.. */...sp =
3f00: 66 6f 70 65 6e 28 73 75 62 73 74 69 74 75 74 69 fopen(substituti
3f10: 6f 6e 73 2c 20 22 72 74 22 29 3b 0a 09 69 66 20 ons, "rt");..if
3f20: 28 73 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 (sp != NULL) {..
3f30: 20 20 20 20 77 68 69 6c 65 20 28 66 67 65 74 73 while (fgets
3f40: 28 73 7a 42 75 66 66 65 72 2c 20 73 69 7a 65 6f (szBuffer, sizeo
3f50: 66 28 73 7a 42 75 66 66 65 72 29 2c 20 73 70 29 f(szBuffer), sp)
3f60: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 75 6e != NULL) {...un
3f70: 73 69 67 6e 65 64 20 63 68 61 72 20 2a 6b 73 2c signed char *ks,
3f80: 20 2a 6b 65 2c 20 2a 76 73 2c 20 2a 76 65 3b 0a *ke, *vs, *ve;.
3f90: 09 09 6b 73 20 3d 20 28 75 6e 73 69 67 6e 65 64 ..ks = (unsigned
3fa0: 20 63 68 61 72 2a 29 73 7a 42 75 66 66 65 72 3b char*)szBuffer;
3fb0: 0a 09 09 77 68 69 6c 65 20 28 6b 73 20 26 26 20 ...while (ks &&
3fc0: 2a 6b 73 20 26 26 20 69 73 73 70 61 63 65 28 2a *ks && isspace(*
3fd0: 6b 73 29 29 20 2b 2b 6b 73 3b 0a 09 09 6b 65 20 ks)) ++ks;...ke
3fe0: 3d 20 6b 73 3b 0a 09 09 77 68 69 6c 65 20 28 6b = ks;...while (k
3ff0: 65 20 26 26 20 2a 6b 65 20 26 26 20 21 69 73 73 e && *ke && !iss
4000: 70 61 63 65 28 2a 6b 65 29 29 20 2b 2b 6b 65 3b pace(*ke)) ++ke;
4010: 0a 09 09 76 73 20 3d 20 6b 65 3b 0a 09 09 77 68 ...vs = ke;...wh
4020: 69 6c 65 20 28 76 73 20 26 26 20 2a 76 73 20 26 ile (vs && *vs &
4030: 26 20 69 73 73 70 61 63 65 28 2a 76 73 29 29 20 & isspace(*vs))
4040: 2b 2b 76 73 3b 0a 09 09 76 65 20 3d 20 76 73 3b ++vs;...ve = vs;
4050: 0a 09 09 77 68 69 6c 65 20 28 76 65 20 26 26 20 ...while (ve &&
4060: 2a 76 65 20 26 26 20 21 28 2a 76 65 20 3d 3d 20 *ve && !(*ve ==
4070: 27 5c 72 27 20 7c 7c 20 2a 76 65 20 3d 3d 20 27 '\r' || *ve == '
4080: 5c 6e 27 29 29 20 2b 2b 76 65 3b 0a 09 09 2a 6b \n')) ++ve;...*k
4090: 65 20 3d 20 30 2c 20 2a 76 65 20 3d 20 30 3b 0a e = 0, *ve = 0;.
40a0: 09 09 6c 69 73 74 5f 69 6e 73 65 72 74 28 26 73 ..list_insert(&s
40b0: 75 62 73 74 50 74 72 2c 20 28 63 68 61 72 2a 29 ubstPtr, (char*)
40c0: 6b 73 2c 20 28 63 68 61 72 2a 29 76 73 29 3b 0a ks, (char*)vs);.
40d0: 09 20 20 20 20 7d 0a 09 20 20 20 20 66 63 6c 6f . }.. fclo
40e0: 73 65 28 73 70 29 3b 0a 09 7d 0a 0a 09 2f 2a 20 se(sp);..}.../*
40f0: 64 65 62 75 67 3a 20 64 75 6d 70 20 74 68 65 20 debug: dump the
4100: 6c 69 73 74 20 2a 2f 0a 23 69 66 6e 64 65 66 20 list */.#ifndef
4110: 4e 44 45 42 55 47 0a 09 7b 0a 09 20 20 20 20 69 NDEBUG..{.. i
4120: 6e 74 20 6e 20 3d 20 30 3b 0a 09 20 20 20 20 6c nt n = 0;.. l
4130: 69 73 74 5f 69 74 65 6d 5f 74 20 2a 70 20 3d 20 ist_item_t *p =
4140: 4e 55 4c 4c 3b 0a 09 20 20 20 20 66 6f 72 20 28 NULL;.. for (
4150: 70 20 3d 20 73 75 62 73 74 50 74 72 3b 20 70 20 p = substPtr; p
4160: 21 3d 20 4e 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e != NULL; p = p->
4170: 6e 65 78 74 50 74 72 2c 20 2b 2b 6e 29 20 7b 0a nextPtr, ++n) {.
4180: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
4190: 2c 20 22 25 20 33 64 20 27 25 73 27 20 3d 3e 20 , "% 3d '%s' =>
41a0: 27 25 73 27 5c 6e 22 2c 20 6e 2c 20 70 2d 3e 6b '%s'\n", n, p->k
41b0: 65 79 2c 20 70 2d 3e 76 61 6c 75 65 29 3b 0a 09 ey, p->value);..
41c0: 20 20 20 20 7d 0a 09 7d 0a 23 65 6e 64 69 66 0a }..}.#endif.
41d0: 0a 09 2f 2a 0a 09 20 2a 20 52 75 6e 20 74 68 65 ../*.. * Run the
41e0: 20 73 75 62 73 74 69 74 75 74 69 6f 6e 73 20 6f substitutions o
41f0: 76 65 72 20 65 61 63 68 20 6c 69 6e 65 20 6f 66 ver each line of
4200: 20 74 68 65 20 69 6e 70 75 74 0a 09 20 2a 2f 0a the input.. */.
4210: 0a 09 77 68 69 6c 65 20 28 66 67 65 74 73 28 73 ..while (fgets(s
4220: 7a 42 75 66 66 65 72 2c 20 73 69 7a 65 6f 66 28 zBuffer, sizeof(
4230: 73 7a 42 75 66 66 65 72 29 2c 20 66 70 29 20 21 szBuffer), fp) !
4240: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 6c = NULL) {.. l
4250: 69 73 74 5f 69 74 65 6d 5f 74 20 2a 70 20 3d 20 ist_item_t *p =
4260: 4e 55 4c 4c 3b 0a 09 20 20 20 20 66 6f 72 20 28 NULL;.. for (
4270: 70 20 3d 20 73 75 62 73 74 50 74 72 3b 20 70 20 p = substPtr; p
4280: 21 3d 20 4e 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e != NULL; p = p->
4290: 6e 65 78 74 50 74 72 29 20 7b 0a 09 09 63 68 61 nextPtr) {...cha
42a0: 72 20 2a 6d 20 3d 20 73 74 72 73 74 72 28 73 7a r *m = strstr(sz
42b0: 42 75 66 66 65 72 2c 20 70 2d 3e 6b 65 79 29 3b Buffer, p->key);
42c0: 0a 09 09 69 66 20 28 6d 29 20 7b 0a 09 09 20 20 ...if (m) {...
42d0: 20 20 63 68 61 72 20 2a 63 70 2c 20 2a 6f 70 2c char *cp, *op,
42e0: 20 2a 73 70 3b 0a 09 09 20 20 20 20 63 70 20 3d *sp;... cp =
42f0: 20 73 7a 43 6f 70 79 3b 0a 09 09 20 20 20 20 6f szCopy;... o
4300: 70 20 3d 20 73 7a 42 75 66 66 65 72 3b 0a 09 09 p = szBuffer;...
4310: 20 20 20 20 77 68 69 6c 65 20 28 6f 70 20 21 3d while (op !=
4320: 20 6d 29 20 2a 63 70 2b 2b 20 3d 20 2a 6f 70 2b m) *cp++ = *op+
4330: 2b 3b 0a 09 09 20 20 20 20 73 70 20 3d 20 70 2d +;... sp = p-
4340: 3e 76 61 6c 75 65 3b 0a 09 09 20 20 20 20 77 68 >value;... wh
4350: 69 6c 65 20 28 73 70 20 26 26 20 2a 73 70 29 20 ile (sp && *sp)
4360: 2a 63 70 2b 2b 20 3d 20 2a 73 70 2b 2b 3b 0a 09 *cp++ = *sp++;..
4370: 09 20 20 20 20 6f 70 20 2b 3d 20 73 74 72 6c 65 . op += strle
4380: 6e 28 70 2d 3e 6b 65 79 29 3b 0a 09 09 20 20 20 n(p->key);...
4390: 20 77 68 69 6c 65 20 28 2a 6f 70 29 20 2a 63 70 while (*op) *cp
43a0: 2b 2b 20 3d 20 2a 6f 70 2b 2b 3b 0a 09 09 20 20 ++ = *op++;...
43b0: 20 20 2a 63 70 20 3d 20 30 3b 0a 09 09 20 20 20 *cp = 0;...
43c0: 20 6d 65 6d 63 70 79 28 73 7a 42 75 66 66 65 72 memcpy(szBuffer
43d0: 2c 20 73 7a 43 6f 70 79 2c 20 73 69 7a 65 6f 66 , szCopy, sizeof
43e0: 28 73 7a 43 6f 70 79 29 29 3b 0a 09 09 7d 0a 09 (szCopy));...}..
43f0: 20 20 20 20 7d 0a 09 20 20 20 20 70 72 69 6e 74 }.. print
4400: 66 28 22 25 73 22 2c 20 73 7a 42 75 66 66 65 72 f("%s", szBuffer
4410: 29 3b 0a 09 7d 0a 0a 09 6c 69 73 74 5f 66 72 65 );..}...list_fre
4420: 65 28 26 73 75 62 73 74 50 74 72 29 3b 0a 20 20 e(&substPtr);.
4430: 20 20 7d 0a 20 20 20 20 66 63 6c 6f 73 65 28 66 }. fclose(f
4440: 70 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 p);. return 0
4450: 3b 0a 7d 0a 0c 0a 42 4f 4f 4c 20 46 69 6c 65 45 ;.}...BOOL FileE
4460: 78 69 73 74 73 28 4c 50 43 54 53 54 52 20 73 7a xists(LPCTSTR sz
4470: 50 61 74 68 29 0a 7b 0a 23 69 66 6e 64 65 66 20 Path).{.#ifndef
4480: 49 4e 56 41 4c 49 44 5f 46 49 4c 45 5f 41 54 54 INVALID_FILE_ATT
4490: 52 49 42 55 54 45 53 0a 20 20 20 20 23 64 65 66 RIBUTES. #def
44a0: 69 6e 65 20 49 4e 56 41 4c 49 44 5f 46 49 4c 45 ine INVALID_FILE
44b0: 5f 41 54 54 52 49 42 55 54 45 53 20 28 28 44 57 _ATTRIBUTES ((DW
44c0: 4f 52 44 29 2d 31 29 0a 23 65 6e 64 69 66 0a 20 ORD)-1).#endif.
44d0: 20 20 20 44 57 4f 52 44 20 70 61 74 68 41 74 74 DWORD pathAtt
44e0: 72 20 3d 20 47 65 74 46 69 6c 65 41 74 74 72 69 r = GetFileAttri
44f0: 62 75 74 65 73 28 73 7a 50 61 74 68 29 3b 0a 20 butes(szPath);.
4500: 20 20 20 72 65 74 75 72 6e 20 28 70 61 74 68 41 return (pathA
4510: 74 74 72 20 21 3d 20 49 4e 56 41 4c 49 44 5f 46 ttr != INVALID_F
4520: 49 4c 45 5f 41 54 54 52 49 42 55 54 45 53 20 26 ILE_ATTRIBUTES &
4530: 26 0a 09 20 20 20 20 21 28 70 61 74 68 41 74 74 &.. !(pathAtt
4540: 72 20 26 20 46 49 4c 45 5f 41 54 54 52 49 42 55 r & FILE_ATTRIBU
4550: 54 45 5f 44 49 52 45 43 54 4f 52 59 29 29 3b 0a TE_DIRECTORY));.
4560: 7d 0a 0c 0a 0a 2f 2a 0a 20 2a 20 51 75 61 6c 69 }..../*. * Quali
4570: 66 79 50 61 74 68 20 2d 2d 0a 20 2a 0a 20 2a 09 fyPath --. *. *.
4580: 54 68 69 73 20 63 6f 6d 70 6f 73 65 73 20 74 68 This composes th
4590: 65 20 63 75 72 72 65 6e 74 20 77 6f 72 6b 69 6e e current workin
45a0: 67 20 64 69 72 65 63 74 6f 72 79 20 77 69 74 68 g directory with
45b0: 20 61 20 70 72 6f 76 69 64 65 64 20 70 61 74 68 a provided path
45c0: 0a 20 2a 09 61 6e 64 20 72 65 74 75 72 6e 73 20 . *.and returns
45d0: 74 68 65 20 66 75 6c 6c 79 20 71 75 61 6c 69 66 the fully qualif
45e0: 69 65 64 20 61 6e 64 20 6e 6f 72 6d 61 6c 69 7a ied and normaliz
45f0: 65 64 20 70 61 74 68 2e 0a 20 2a 09 4d 6f 73 74 ed path.. *.Most
4600: 6c 79 20 6e 65 65 64 65 64 20 74 6f 20 73 65 74 ly needed to set
4610: 75 70 20 70 61 74 68 73 20 66 6f 72 20 74 65 73 up paths for tes
4620: 74 69 6e 67 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 ting.. */..stati
4630: 63 20 69 6e 74 0a 51 75 61 6c 69 66 79 50 61 74 c int.QualifyPat
4640: 68 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 h(. const cha
4650: 72 20 2a 73 7a 50 61 74 68 29 0a 7b 0a 20 20 20 r *szPath).{.
4660: 20 63 68 61 72 20 73 7a 43 77 64 5b 4d 41 58 5f char szCwd[MAX_
4670: 50 41 54 48 20 2b 20 31 5d 3b 0a 0a 20 20 20 20 PATH + 1];..
4680: 47 65 74 46 75 6c 6c 50 61 74 68 4e 61 6d 65 28 GetFullPathName(
4690: 73 7a 50 61 74 68 2c 20 73 69 7a 65 6f 66 28 73 szPath, sizeof(s
46a0: 7a 43 77 64 29 2d 31 2c 20 73 7a 43 77 64 2c 20 zCwd)-1, szCwd,
46b0: 4e 55 4c 4c 29 3b 0a 20 20 20 20 70 72 69 6e 74 NULL);. print
46c0: 66 28 22 25 73 5c 6e 22 2c 20 73 7a 43 77 64 29 f("%s\n", szCwd)
46d0: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a ;. return 0;.
46e0: 7d 0a 0a 2f 2a 0a 20 2a 20 49 6d 70 6c 65 6d 65 }../*. * Impleme
46f0: 6e 74 73 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 nts LocateDepend
4700: 65 6e 63 79 20 66 6f 72 20 61 20 73 69 6e 67 6c ency for a singl
4710: 65 20 64 69 72 65 63 74 6f 72 79 2e 20 53 65 65 e directory. See
4720: 20 74 68 61 74 20 63 6f 6d 6d 61 6e 64 0a 20 2a that command. *
4730: 20 66 6f 72 20 61 6e 20 65 78 70 6c 61 6e 61 74 for an explanat
4740: 69 6f 6e 2e 0a 20 2a 20 52 65 74 75 72 6e 73 20 ion.. * Returns
4750: 30 20 69 66 20 66 6f 75 6e 64 20 61 66 74 65 72 0 if found after
4760: 20 70 72 69 6e 74 69 6e 67 20 74 68 65 20 64 69 printing the di
4770: 72 65 63 74 6f 72 79 2e 0a 20 2a 20 52 65 74 75 rectory.. * Retu
4780: 72 6e 73 20 31 20 69 66 20 6e 6f 74 20 66 6f 75 rns 1 if not fou
4790: 6e 64 20 62 75 74 20 6e 6f 20 65 72 72 6f 72 73 nd but no errors
47a0: 2e 0a 20 2a 20 52 65 74 75 72 6e 73 20 32 20 6f .. * Returns 2 o
47b0: 6e 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20 65 72 n any kind of er
47c0: 72 6f 72 0a 20 2a 20 42 61 73 69 63 61 6c 6c 79 ror. * Basically
47d0: 2c 20 74 68 65 73 65 20 61 72 65 20 75 73 65 64 , these are used
47e0: 20 61 73 20 65 78 69 74 20 63 6f 64 65 73 20 66 as exit codes f
47f0: 6f 72 20 74 68 65 20 70 72 6f 63 65 73 73 2e 0a or the process..
4800: 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 4c */.static int L
4810: 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 48 ocateDependencyH
4820: 65 6c 70 65 72 28 63 6f 6e 73 74 20 63 68 61 72 elper(const char
4830: 20 2a 64 69 72 2c 20 63 6f 6e 73 74 20 63 68 61 *dir, const cha
4840: 72 20 2a 6b 65 79 70 61 74 68 29 0a 7b 0a 20 20 r *keypath).{.
4850: 20 20 48 41 4e 44 4c 45 20 68 53 65 61 72 63 68 HANDLE hSearch
4860: 3b 0a 20 20 20 20 63 68 61 72 20 70 61 74 68 5b ;. char path[
4870: 4d 41 58 5f 50 41 54 48 2b 31 5d 3b 0a 20 20 20 MAX_PATH+1];.
4880: 20 73 69 7a 65 5f 74 20 64 69 72 6c 65 6e 3b 0a size_t dirlen;.
4890: 20 20 20 20 69 6e 74 20 6b 65 79 6c 65 6e 2c 20 int keylen,
48a0: 72 65 74 3b 0a 20 20 20 20 57 49 4e 33 32 5f 46 ret;. WIN32_F
48b0: 49 4e 44 5f 44 41 54 41 20 66 69 6e 66 6f 3b 0a IND_DATA finfo;.
48c0: 0a 20 20 20 20 69 66 20 28 64 69 72 20 3d 3d 20 . if (dir ==
48d0: 4e 55 4c 4c 20 7c 7c 20 6b 65 79 70 61 74 68 20 NULL || keypath
48e0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 == NULL) {..retu
48f0: 72 6e 20 32 3b 20 2f 2a 20 48 61 76 65 20 6e 6f rn 2; /* Have no
4900: 20 72 65 61 6c 20 65 72 72 6f 72 20 72 65 70 6f real error repo
4910: 72 74 69 6e 67 20 6d 65 63 68 61 6e 69 73 6d 20 rting mechanism
4920: 69 6e 74 6f 20 6e 6d 61 6b 65 20 2a 2f 0a 20 20 into nmake */.
4930: 20 20 7d 0a 20 20 20 20 64 69 72 6c 65 6e 20 3d }. dirlen =
4940: 20 73 74 72 6c 65 6e 28 64 69 72 29 3b 0a 20 20 strlen(dir);.
4950: 20 20 69 66 20 28 64 69 72 6c 65 6e 20 3e 20 73 if (dirlen > s
4960: 69 7a 65 6f 66 28 70 61 74 68 29 20 2d 20 33 29 izeof(path) - 3)
4970: 20 7b 0a 09 72 65 74 75 72 6e 20 32 3b 0a 20 20 {..return 2;.
4980: 20 20 7d 0a 20 20 20 20 73 74 72 6e 63 70 79 28 }. strncpy(
4990: 70 61 74 68 2c 20 64 69 72 2c 20 64 69 72 6c 65 path, dir, dirle
49a0: 6e 29 3b 0a 20 20 20 20 73 74 72 6e 63 70 79 28 n);. strncpy(
49b0: 70 61 74 68 2b 64 69 72 6c 65 6e 2c 20 22 5c 5c path+dirlen, "\\
49c0: 2a 22 2c 20 33 29 3b 09 2f 2a 20 49 6e 63 6c 75 *", 3);./* Inclu
49d0: 64 69 6e 67 20 74 65 72 6d 69 6e 61 74 69 6e 67 ding terminating
49e0: 20 5c 30 20 2a 2f 0a 20 20 20 20 6b 65 79 6c 65 \0 */. keyle
49f0: 6e 20 3d 20 73 74 72 6c 65 6e 28 6b 65 79 70 61 n = strlen(keypa
4a00: 74 68 29 3b 0a 0a 23 69 66 20 30 20 2f 2a 20 54 th);..#if 0 /* T
4a10: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 his function is
4a20: 6e 6f 74 20 61 76 61 69 6c 61 62 6c 65 20 69 6e not available in
4a30: 20 56 69 73 75 61 6c 20 43 2b 2b 20 36 20 2a 2f Visual C++ 6 */
4a40: 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 55 . /*. * U
4a50: 73 65 20 6e 75 6d 65 72 69 63 73 20 30 20 2d 3e se numerics 0 ->
4a60: 20 46 69 6e 64 45 78 49 6e 66 6f 53 74 61 6e 64 FindExInfoStand
4a70: 61 72 64 2c 0a 20 20 20 20 20 2a 20 31 20 2d 3e ard,. * 1 ->
4a80: 20 46 69 6e 64 45 78 53 65 61 72 63 68 4c 69 6d FindExSearchLim
4a90: 69 74 54 6f 44 69 72 65 63 74 6f 72 69 65 73 2c itToDirectories,
4aa0: 0a 20 20 20 20 20 2a 20 61 73 20 74 68 65 73 65 . * as these
4ab0: 20 61 72 65 20 6e 6f 74 20 64 65 66 69 6e 65 64 are not defined
4ac0: 20 69 6e 20 56 69 73 75 61 6c 20 43 2b 2b 20 36 in Visual C++ 6
4ad0: 0a 20 20 20 20 20 2a 2f 0a 20 20 20 20 68 53 65 . */. hSe
4ae0: 61 72 63 68 20 3d 20 46 69 6e 64 46 69 72 73 74 arch = FindFirst
4af0: 46 69 6c 65 45 78 28 70 61 74 68 2c 20 30 2c 20 FileEx(path, 0,
4b00: 26 66 69 6e 66 6f 2c 20 31 2c 20 4e 55 4c 4c 2c &finfo, 1, NULL,
4b10: 20 30 29 3b 0a 23 65 6c 73 65 0a 20 20 20 20 68 0);.#else. h
4b20: 53 65 61 72 63 68 20 3d 20 46 69 6e 64 46 69 72 Search = FindFir
4b30: 73 74 46 69 6c 65 28 70 61 74 68 2c 20 26 66 69 stFile(path, &fi
4b40: 6e 66 6f 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 nfo);.#endif.
4b50: 20 69 66 20 28 68 53 65 61 72 63 68 20 3d 3d 20 if (hSearch ==
4b60: 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 INVALID_HANDLE_V
4b70: 41 4c 55 45 29 0a 09 72 65 74 75 72 6e 20 31 3b ALUE)..return 1;
4b80: 20 2f 2a 20 4e 6f 74 20 66 6f 75 6e 64 20 2a 2f /* Not found */
4b90: 0a 0a 20 20 20 20 2f 2a 20 4c 6f 6f 70 20 74 68 .. /* Loop th
4ba0: 72 6f 75 67 68 20 61 6c 6c 20 73 75 62 64 69 72 rough all subdir
4bb0: 73 20 63 68 65 63 6b 69 6e 67 20 69 66 20 74 68 s checking if th
4bc0: 65 20 6b 65 79 70 61 74 68 20 69 73 20 75 6e 64 e keypath is und
4bd0: 65 72 20 74 68 65 72 65 20 2a 2f 0a 20 20 20 20 er there */.
4be0: 72 65 74 20 3d 20 31 3b 20 2f 2a 20 41 73 73 75 ret = 1; /* Assu
4bf0: 6d 65 20 6e 6f 74 20 66 6f 75 6e 64 20 2a 2f 0a me not found */.
4c00: 20 20 20 20 64 6f 20 7b 0a 09 69 6e 74 20 73 75 do {..int su
4c10: 62 6c 65 6e 3b 0a 09 2f 2a 0a 09 20 2a 20 57 65 blen;../*.. * We
4c20: 20 6e 65 65 64 20 74 6f 20 63 68 65 63 6b 20 69 need to check i
4c30: 74 20 69 73 20 61 20 64 69 72 65 63 74 6f 72 79 t is a directory
4c40: 20 64 65 73 70 69 74 65 20 74 68 65 0a 09 20 2a despite the.. *
4c50: 20 46 69 6e 64 45 78 53 65 61 72 63 68 4c 69 6d FindExSearchLim
4c60: 69 74 54 6f 44 69 72 65 63 74 6f 72 69 65 73 20 itToDirectories
4c70: 69 6e 20 74 68 65 20 61 62 6f 76 65 20 63 61 6c in the above cal
4c80: 6c 2e 20 53 65 65 20 53 44 4b 20 64 6f 63 73 0a l. See SDK docs.
4c90: 09 20 2a 2f 0a 09 69 66 20 28 28 66 69 6e 66 6f . */..if ((finfo
4ca0: 2e 64 77 46 69 6c 65 41 74 74 72 69 62 75 74 65 .dwFileAttribute
4cb0: 73 20 26 20 46 49 4c 45 5f 41 54 54 52 49 42 55 s & FILE_ATTRIBU
4cc0: 54 45 5f 44 49 52 45 43 54 4f 52 59 29 20 3d 3d TE_DIRECTORY) ==
4cd0: 20 30 29 0a 09 20 20 20 20 63 6f 6e 74 69 6e 75 0).. continu
4ce0: 65 3b 0a 09 73 75 62 6c 65 6e 20 3d 20 73 74 72 e;..sublen = str
4cf0: 6c 65 6e 28 66 69 6e 66 6f 2e 63 46 69 6c 65 4e len(finfo.cFileN
4d00: 61 6d 65 29 3b 0a 09 69 66 20 28 28 64 69 72 6c ame);..if ((dirl
4d10: 65 6e 2b 31 2b 73 75 62 6c 65 6e 2b 31 2b 6b 65 en+1+sublen+1+ke
4d20: 79 6c 65 6e 2b 31 29 20 3e 20 73 69 7a 65 6f 66 ylen+1) > sizeof
4d30: 28 70 61 74 68 29 29 0a 09 20 20 20 20 63 6f 6e (path)).. con
4d40: 74 69 6e 75 65 3b 09 09 2f 2a 20 50 61 74 68 20 tinue;../* Path
4d50: 64 6f 65 73 20 6e 6f 74 20 66 69 74 2c 20 61 73 does not fit, as
4d60: 73 75 6d 65 20 6e 6f 74 20 6d 61 74 63 68 65 64 sume not matched
4d70: 20 2a 2f 0a 09 73 74 72 6e 63 70 79 28 70 61 74 */..strncpy(pat
4d80: 68 2b 64 69 72 6c 65 6e 2b 31 2c 20 66 69 6e 66 h+dirlen+1, finf
4d90: 6f 2e 63 46 69 6c 65 4e 61 6d 65 2c 20 73 75 62 o.cFileName, sub
4da0: 6c 65 6e 29 3b 0a 09 70 61 74 68 5b 64 69 72 6c len);..path[dirl
4db0: 65 6e 2b 31 2b 73 75 62 6c 65 6e 5d 20 3d 20 27 en+1+sublen] = '
4dc0: 5c 5c 27 3b 0a 09 73 74 72 6e 63 70 79 28 70 61 \\';..strncpy(pa
4dd0: 74 68 2b 64 69 72 6c 65 6e 2b 31 2b 73 75 62 6c th+dirlen+1+subl
4de0: 65 6e 2b 31 2c 20 6b 65 79 70 61 74 68 2c 20 6b en+1, keypath, k
4df0: 65 79 6c 65 6e 2b 31 29 3b 0a 09 69 66 20 28 46 eylen+1);..if (F
4e00: 69 6c 65 45 78 69 73 74 73 28 70 61 74 68 29 29 ileExists(path))
4e10: 20 7b 0a 09 20 20 20 20 2f 2a 20 46 6f 75 6e 64 {.. /* Found
4e20: 20 61 20 6d 61 74 63 68 2c 20 70 72 69 6e 74 20 a match, print
4e30: 74 6f 20 73 74 64 6f 75 74 20 2a 2f 0a 09 20 20 to stdout */..
4e40: 20 20 70 61 74 68 5b 64 69 72 6c 65 6e 2b 31 2b path[dirlen+1+
4e50: 73 75 62 6c 65 6e 5d 20 3d 20 27 5c 30 27 3b 0a sublen] = '\0';.
4e60: 09 20 20 20 20 51 75 61 6c 69 66 79 50 61 74 68 . QualifyPath
4e70: 28 70 61 74 68 29 3b 0a 09 20 20 20 20 72 65 74 (path);.. ret
4e80: 20 3d 20 30 3b 0a 09 20 20 20 20 62 72 65 61 6b = 0;.. break
4e90: 3b 0a 09 7d 0a 20 20 20 20 7d 20 77 68 69 6c 65 ;..}. } while
4ea0: 20 28 46 69 6e 64 4e 65 78 74 46 69 6c 65 28 68 (FindNextFile(h
4eb0: 53 65 61 72 63 68 2c 20 26 66 69 6e 66 6f 29 29 Search, &finfo))
4ec0: 3b 0a 20 20 20 20 46 69 6e 64 43 6c 6f 73 65 28 ;. FindClose(
4ed0: 68 53 65 61 72 63 68 29 3b 0a 20 20 20 20 72 65 hSearch);. re
4ee0: 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 2f 2a 0a turn ret;.}../*.
4ef0: 20 2a 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 * LocateDepende
4f00: 6e 63 79 20 2d 2d 0a 20 2a 0a 20 2a 09 4c 6f 63 ncy --. *. *.Loc
4f10: 61 74 65 73 20 61 20 64 65 70 65 6e 64 65 6e 63 ates a dependenc
4f20: 79 20 66 6f 72 20 61 20 70 61 63 6b 61 67 65 2e y for a package.
4f30: 0a 20 2a 20 20 20 20 20 20 20 20 6b 65 79 70 61 . * keypa
4f40: 74 68 20 2d 20 61 20 72 65 6c 61 74 69 76 65 20 th - a relative
4f50: 70 61 74 68 20 77 69 74 68 69 6e 20 74 68 65 20 path within the
4f60: 70 61 63 6b 61 67 65 20 64 69 72 65 63 74 6f 72 package director
4f70: 79 0a 20 2a 20 20 20 20 20 20 20 20 20 20 74 68 y. * th
4f80: 61 74 20 69 73 20 75 73 65 64 20 74 6f 20 63 6f at is used to co
4f90: 6e 66 69 72 6d 20 69 74 20 69 73 20 74 68 65 20 nfirm it is the
4fa0: 63 6f 72 72 65 63 74 20 64 69 72 65 63 74 6f 72 correct director
4fb0: 79 2e 0a 20 2a 09 54 68 65 20 73 65 61 72 63 68 y.. *.The search
4fc0: 20 70 61 74 68 20 66 6f 72 20 74 68 65 20 70 61 path for the pa
4fd0: 63 6b 61 67 65 20 64 69 72 65 63 74 6f 72 79 20 ckage directory
4fe0: 69 73 20 63 75 72 72 65 6e 74 6c 79 20 6f 6e 6c is currently onl
4ff0: 79 0a 20 2a 20 20 20 20 20 20 74 68 65 20 70 61 y. * the pa
5000: 72 65 6e 74 20 61 6e 64 20 67 72 61 6e 64 70 61 rent and grandpa
5010: 72 65 6e 74 20 6f 66 20 74 68 65 20 63 75 72 72 rent of the curr
5020: 65 6e 74 20 77 6f 72 6b 69 6e 67 20 64 69 72 65 ent working dire
5030: 63 74 6f 72 79 2e 0a 20 2a 20 20 20 20 20 20 49 ctory.. * I
5040: 66 20 66 6f 75 6e 64 2c 20 74 68 65 20 63 6f 6d f found, the com
5050: 6d 61 6e 64 20 70 72 69 6e 74 73 0a 20 2a 20 20 mand prints. *
5060: 20 20 20 20 20 20 20 6e 61 6d 65 5f 44 49 52 50 name_DIRP
5070: 41 54 48 3d 3c 66 75 6c 6c 20 70 61 74 68 20 6f ATH=<full path o
5080: 66 20 6c 6f 63 61 74 65 64 20 64 69 72 65 63 74 f located direct
5090: 6f 72 79 3e 0a 20 2a 20 20 20 20 20 20 61 6e 64 ory>. * and
50a0: 20 72 65 74 75 72 6e 73 20 30 2e 20 49 66 20 6e returns 0. If n
50b0: 6f 74 20 66 6f 75 6e 64 2c 20 64 6f 65 73 20 6e ot found, does n
50c0: 6f 74 20 70 72 69 6e 74 20 61 6e 79 74 68 69 6e ot print anythin
50d0: 67 20 61 6e 64 20 72 65 74 75 72 6e 73 20 31 2e g and returns 1.
50e0: 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 . */.static int
50f0: 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 LocateDependency
5100: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b 65 79 (const char *key
5110: 70 61 74 68 29 0a 7b 0a 20 20 20 20 73 69 7a 65 path).{. size
5120: 5f 74 20 69 3b 0a 20 20 20 20 69 6e 74 20 72 65 _t i;. int re
5130: 74 3b 0a 20 20 20 20 73 74 61 74 69 63 20 63 6f t;. static co
5140: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 73 5b nst char *paths[
5150: 5d 20 3d 20 7b 22 2e 2e 22 2c 20 22 2e 2e 5c 5c ] = {"..", "..\\
5160: 2e 2e 22 2c 20 22 2e 2e 5c 5c 2e 2e 5c 5c 2e 2e ..", "..\\..\\..
5170: 22 7d 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69 20 "};.. for (i
5180: 3d 20 30 3b 20 69 20 3c 20 28 73 69 7a 65 6f 66 = 0; i < (sizeof
5190: 28 70 61 74 68 73 29 2f 73 69 7a 65 6f 66 28 70 (paths)/sizeof(p
51a0: 61 74 68 73 5b 30 5d 29 29 3b 20 2b 2b 69 29 20 aths[0])); ++i)
51b0: 7b 0a 09 72 65 74 20 3d 20 4c 6f 63 61 74 65 44 {..ret = LocateD
51c0: 65 70 65 6e 64 65 6e 63 79 48 65 6c 70 65 72 28 ependencyHelper(
51d0: 70 61 74 68 73 5b 69 5d 2c 20 6b 65 79 70 61 74 paths[i], keypat
51e0: 68 29 3b 0a 09 69 66 20 28 72 65 74 20 3d 3d 20 h);..if (ret ==
51f0: 30 29 20 7b 0a 09 20 20 20 20 72 65 74 75 72 6e 0) {.. return
5200: 20 72 65 74 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 ret;..}. }.
5210: 20 20 20 72 65 74 75 72 6e 20 72 65 74 3b 0a 7d return ret;.}
5220: 0a 0a 0a 2f 2a 0a 20 2a 20 4c 6f 63 61 6c 20 76 .../*. * Local v
5230: 61 72 69 61 62 6c 65 73 3a 0a 20 2a 20 20 20 6d ariables:. * m
5240: 6f 64 65 3a 20 63 0a 20 2a 20 20 20 63 2d 62 61 ode: c. * c-ba
5250: 73 69 63 2d 6f 66 66 73 65 74 3a 20 34 0a 20 2a sic-offset: 4. *
5260: 20 20 20 66 69 6c 6c 2d 63 6f 6c 75 6d 6e 3a 20 fill-column:
5270: 37 38 0a 20 2a 20 20 20 69 6e 64 65 6e 74 2d 74 78. * indent-t
5280: 61 62 73 2d 6d 6f 64 65 3a 20 74 0a 20 2a 20 20 abs-mode: t. *
5290: 20 74 61 62 2d 77 69 64 74 68 3a 20 38 0a 20 2a tab-width: 8. *
52a0: 20 45 6e 64 3a 0a 20 2a 2f 0a End:. */.