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 23 lude <stdio.h>.#
0280: 69 6e 63 6c 75 64 65 20 3c 6d 61 74 68 2e 68 3e include <math.h>
0290: 0a 0a 2f 2a 0a 20 2a 20 54 68 69 73 20 6c 69 62 ../*. * This lib
02a0: 72 61 72 79 20 69 73 20 72 65 71 75 69 72 65 64 rary is required
02b0: 20 66 6f 72 20 78 36 34 20 62 75 69 6c 64 73 20 for x64 builds
02c0: 77 69 74 68 20 5f 73 6f 6d 65 5f 20 76 65 72 73 with _some_ vers
02d0: 69 6f 6e 73 20 6f 66 20 4d 53 56 43 0a 20 2a 2f ions of MSVC. */
02e0: 0a 23 69 66 20 64 65 66 69 6e 65 64 28 5f 4d 5f .#if defined(_M_
02f0: 49 41 36 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 IA64) || defined
0300: 28 5f 4d 5f 41 4d 44 36 34 29 0a 23 69 66 20 5f (_M_AMD64).#if _
0310: 4d 53 43 5f 56 45 52 20 3e 3d 20 31 34 30 30 20 MSC_VER >= 1400
0320: 26 26 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 35 && _MSC_VER < 15
0330: 30 30 0a 23 70 72 61 67 6d 61 20 63 6f 6d 6d 65 00.#pragma comme
0340: 6e 74 28 6c 69 62 2c 20 22 62 75 66 66 65 72 6f nt(lib, "buffero
0350: 76 65 72 66 6c 6f 77 55 22 29 0a 23 65 6e 64 69 verflowU").#endi
0360: 66 0a 23 65 6e 64 69 66 0a 0a 2f 2a 20 49 53 4f f.#endif../* ISO
0370: 20 68 61 63 6b 20 66 6f 72 20 64 75 6d 62 20 56 hack for dumb V
0380: 43 2b 2b 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e C++ */.#if defin
0390: 65 64 28 5f 57 49 4e 33 32 29 20 26 26 20 64 65 ed(_WIN32) && de
03a0: 66 69 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 20 fined(_MSC_VER)
03b0: 26 26 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 39 && _MSC_VER < 19
03c0: 30 30 0a 23 64 65 66 69 6e 65 20 20 20 73 6e 70 00.#define snp
03d0: 72 69 6e 74 66 09 5f 73 6e 70 72 69 6e 74 66 0a rintf._snprintf.
03e0: 23 65 6e 64 69 66 0a 0a 0a 2f 2a 20 70 72 6f 74 #endif.../* prot
03f0: 6f 73 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e os */..static in
0400: 74 20 43 68 65 63 6b 46 6f 72 43 6f 6d 70 69 6c t CheckForCompil
0410: 65 72 46 65 61 74 75 72 65 28 63 6f 6e 73 74 20 erFeature(const
0420: 63 68 61 72 20 2a 6f 70 74 69 6f 6e 29 3b 0a 73 char *option);.s
0430: 74 61 74 69 63 20 69 6e 74 20 43 68 65 63 6b 46 tatic int CheckF
0440: 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 orLinkerFeature(
0450: 63 68 61 72 20 2a 2a 6f 70 74 69 6f 6e 73 2c 20 char **options,
0460: 69 6e 74 20 63 6f 75 6e 74 29 3b 0a 73 74 61 74 int count);.stat
0470: 69 63 20 69 6e 74 20 49 73 49 6e 28 63 6f 6e 73 ic int IsIn(cons
0480: 74 20 63 68 61 72 20 2a 73 74 72 69 6e 67 2c 20 t char *string,
0490: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73 const char *subs
04a0: 74 72 69 6e 67 29 3b 0a 73 74 61 74 69 63 20 69 tring);.static i
04b0: 6e 74 20 53 75 62 73 74 69 74 75 74 65 46 69 6c nt SubstituteFil
04c0: 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 75 e(const char *su
04d0: 62 73 74 73 2c 20 63 6f 6e 73 74 20 63 68 61 72 bsts, const char
04e0: 20 2a 66 69 6c 65 6e 61 6d 65 29 3b 0a 73 74 61 *filename);.sta
04f0: 74 69 63 20 69 6e 74 20 51 75 61 6c 69 66 79 50 tic int QualifyP
0500: 61 74 68 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ath(const char *
0510: 70 61 74 68 29 3b 0a 73 74 61 74 69 63 20 69 6e path);.static in
0520: 74 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e t LocateDependen
0530: 63 79 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b cy(const char *k
0540: 65 79 66 69 6c 65 29 3b 0a 73 74 61 74 69 63 20 eyfile);.static
0550: 63 6f 6e 73 74 20 63 68 61 72 20 2a 47 65 74 56 const char *GetV
0560: 65 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 63 ersionFromFile(c
0570: 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c 65 6e onst char *filen
0580: 61 6d 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 ame, const char
0590: 2a 6d 61 74 63 68 2c 20 69 6e 74 20 6e 75 6d 64 *match, int numd
05a0: 6f 74 73 29 3b 0a 73 74 61 74 69 63 20 44 57 4f ots);.static DWO
05b0: 52 44 20 57 49 4e 41 50 49 20 52 65 61 64 46 72 RD WINAPI ReadFr
05c0: 6f 6d 50 69 70 65 28 4c 50 56 4f 49 44 20 61 72 omPipe(LPVOID ar
05d0: 67 73 29 3b 0a 0a 2f 2a 20 67 6c 6f 62 61 6c 73 gs);../* globals
05e0: 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 43 48 55 */..#define CHU
05f0: 4e 4b 09 32 35 0a 23 64 65 66 69 6e 65 20 53 54 NK.25.#define ST
0600: 41 54 49 43 42 55 46 46 45 52 53 49 5a 45 20 20 ATICBUFFERSIZE
0610: 20 20 31 30 30 30 0a 74 79 70 65 64 65 66 20 73 1000.typedef s
0620: 74 72 75 63 74 20 7b 0a 20 20 20 20 48 41 4e 44 truct {. HAND
0630: 4c 45 20 70 69 70 65 3b 0a 20 20 20 20 63 68 61 LE pipe;. cha
0640: 72 20 62 75 66 66 65 72 5b 53 54 41 54 49 43 42 r buffer[STATICB
0650: 55 46 46 45 52 53 49 5a 45 5d 3b 0a 7d 20 70 69 UFFERSIZE];.} pi
0660: 70 65 69 6e 66 6f 3b 0a 0a 70 69 70 65 69 6e 66 peinfo;..pipeinf
0670: 6f 20 4f 75 74 20 3d 20 7b 49 4e 56 41 4c 49 44 o Out = {INVALID
0680: 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 2c 20 22 _HANDLE_VALUE, "
0690: 22 7d 3b 0a 70 69 70 65 69 6e 66 6f 20 45 72 72 "};.pipeinfo Err
06a0: 20 3d 20 7b 49 4e 56 41 4c 49 44 5f 48 41 4e 44 = {INVALID_HAND
06b0: 4c 45 5f 56 41 4c 55 45 2c 20 22 22 7d 3b 0a 0c LE_VALUE, ""};..
06c0: 0a 2f 2a 0a 20 2a 20 65 78 69 74 63 6f 64 65 73 ./*. * exitcodes
06d0: 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 : 0 == no, 1 ==
06e0: 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 0a yes, 2 == error.
06f0: 20 2a 2f 0a 0a 69 6e 74 0a 6d 61 69 6e 28 0a 20 */..int.main(.
0700: 20 20 20 69 6e 74 20 61 72 67 63 2c 0a 20 20 20 int argc,.
0710: 20 63 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a 7b char *argv[]).{
0720: 0a 20 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 . char msg[30
0730: 30 5d 3b 0a 20 20 20 20 44 57 4f 52 44 20 64 77 0];. DWORD dw
0740: 57 72 69 74 74 65 6e 3b 0a 20 20 20 20 69 6e 74 Written;. int
0750: 20 63 68 61 72 73 3b 0a 20 20 20 20 63 6f 6e 73 chars;. cons
0760: 74 20 63 68 61 72 20 2a 73 3b 0a 0a 20 20 20 20 t char *s;..
0770: 2f 2a 0a 20 20 20 20 20 2a 20 4d 61 6b 65 20 73 /*. * Make s
0780: 75 72 65 20 63 68 69 6c 64 72 65 6e 20 28 63 6c ure children (cl
0790: 2e 65 78 65 20 61 6e 64 20 6c 69 6e 6b 2e 65 78 .exe and link.ex
07a0: 65 29 20 61 72 65 20 6b 65 70 74 20 71 75 69 65 e) are kept quie
07b0: 74 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 t.. */..
07c0: 53 65 74 45 72 72 6f 72 4d 6f 64 65 28 53 45 4d SetErrorMode(SEM
07d0: 5f 46 41 49 4c 43 52 49 54 49 43 41 4c 45 52 52 _FAILCRITICALERR
07e0: 4f 52 53 20 7c 20 53 45 4d 5f 4e 4f 4f 50 45 4e ORS | SEM_NOOPEN
07f0: 46 49 4c 45 45 52 52 4f 52 42 4f 58 29 3b 0a 0a FILEERRORBOX);..
0800: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4d 61 /*. * Ma
0810: 6b 65 20 73 75 72 65 20 74 68 65 20 63 6f 6d 70 ke sure the comp
0820: 69 6c 65 72 20 61 6e 64 20 6c 69 6e 6b 65 72 20 iler and linker
0830: 61 72 65 6e 27 74 20 65 66 66 65 63 74 65 64 20 aren't effected
0840: 62 79 20 74 68 65 20 6f 75 74 73 69 64 65 20 77 by the outside w
0850: 6f 72 6c 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 orld.. */..
0860: 20 20 20 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e SetEnvironmen
0870: 74 56 61 72 69 61 62 6c 65 28 22 43 4c 22 2c 20 tVariable("CL",
0880: 22 22 29 3b 0a 20 20 20 20 53 65 74 45 6e 76 69 "");. SetEnvi
0890: 72 6f 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 ronmentVariable(
08a0: 22 4c 49 4e 4b 22 2c 20 22 22 29 3b 0a 0a 20 20 "LINK", "");..
08b0: 20 20 69 66 20 28 61 72 67 63 20 3e 20 31 20 26 if (argc > 1 &
08c0: 26 20 2a 61 72 67 76 5b 31 5d 20 3d 3d 20 27 2d & *argv[1] == '-
08d0: 27 29 20 7b 0a 09 73 77 69 74 63 68 20 28 2a 28 ') {..switch (*(
08e0: 61 72 67 76 5b 31 5d 2b 31 29 29 20 7b 0a 09 63 argv[1]+1)) {..c
08f0: 61 73 65 20 27 63 27 3a 0a 09 20 20 20 20 69 66 ase 'c':.. if
0900: 20 28 61 72 67 63 20 21 3d 20 33 29 20 7b 0a 09 (argc != 3) {..
0910: 09 63 68 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 .chars = snprint
0920: 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 f(msg, sizeof(ms
0930: 67 29 20 2d 20 31 2c 0a 09 09 20 20 20 20 20 20 g) - 1,...
0940: 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 63 20 "usage: %s -c
0950: 3c 63 6f 6d 70 69 6c 65 72 20 6f 70 74 69 6f 6e <compiler option
0960: 3e 5c 6e 22 0a 09 09 09 22 54 65 73 74 73 20 66 >\n"...."Tests f
0970: 6f 72 20 77 68 65 74 68 65 72 20 63 6c 2e 65 78 or whether cl.ex
0980: 65 20 73 75 70 70 6f 72 74 73 20 61 6e 20 6f 70 e supports an op
0990: 74 69 6f 6e 5c 6e 22 0a 09 09 09 22 65 78 69 74 tion\n"...."exit
09a0: 63 6f 64 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 codes: 0 == no,
09b0: 31 20 3d 3d 20 79 65 73 2c 20 32 20 3d 3d 20 65 1 == yes, 2 == e
09c0: 72 72 6f 72 5c 6e 22 2c 20 61 72 67 76 5b 30 5d rror\n", argv[0]
09d0: 29 3b 0a 09 09 57 72 69 74 65 46 69 6c 65 28 47 );...WriteFile(G
09e0: 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f etStdHandle(STD_
09f0: 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d ERROR_HANDLE), m
0a00: 73 67 2c 20 63 68 61 72 73 2c 0a 09 09 09 26 64 sg, chars,....&d
0a10: 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b wWritten, NULL);
0a20: 0a 09 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 ...return 2;..
0a30: 20 20 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 }.. return
0a40: 43 68 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 CheckForCompiler
0a50: 46 65 61 74 75 72 65 28 61 72 67 76 5b 32 5d 29 Feature(argv[2])
0a60: 3b 0a 09 63 61 73 65 20 27 6c 27 3a 0a 09 20 20 ;..case 'l':..
0a70: 20 20 69 66 20 28 61 72 67 63 20 3c 20 33 29 20 if (argc < 3)
0a80: 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 {...chars = snpr
0a90: 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 intf(msg, sizeof
0aa0: 28 6d 73 67 29 20 2d 20 31 2c 0a 09 20 20 20 20 (msg) - 1,..
0ab0: 20 20 20 09 09 22 75 73 61 67 65 3a 20 25 73 20 .."usage: %s
0ac0: 2d 6c 20 3c 6c 69 6e 6b 65 72 20 6f 70 74 69 6f -l <linker optio
0ad0: 6e 3e 20 3f 3c 6d 61 6e 64 61 74 6f 72 79 20 6f n> ?<mandatory o
0ae0: 70 74 69 6f 6e 3e 20 2e 2e 2e 3f 5c 6e 22 0a 09 ption> ...?\n"..
0af0: 09 09 22 54 65 73 74 73 20 66 6f 72 20 77 68 65 .."Tests for whe
0b00: 74 68 65 72 20 6c 69 6e 6b 2e 65 78 65 20 73 75 ther link.exe su
0b10: 70 70 6f 72 74 73 20 61 6e 20 6f 70 74 69 6f 6e pports an option
0b20: 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 65 \n"...."exitcode
0b30: 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d s: 0 == no, 1 ==
0b40: 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 yes, 2 == error
0b50: 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 \n", argv[0]);..
0b60: 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 .WriteFile(GetSt
0b70: 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f dHandle(STD_ERRO
0b80: 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 R_HANDLE), msg,
0b90: 63 68 61 72 73 2c 0a 09 09 09 26 64 77 57 72 69 chars,....&dwWri
0ba0: 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 tten, NULL);...r
0bb0: 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a eturn 2;.. }.
0bc0: 09 20 20 20 20 72 65 74 75 72 6e 20 43 68 65 63 . return Chec
0bd0: 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 kForLinkerFeatur
0be0: 65 28 26 61 72 67 76 5b 32 5d 2c 20 61 72 67 63 e(&argv[2], argc
0bf0: 2d 32 29 3b 0a 09 63 61 73 65 20 27 66 27 3a 0a -2);..case 'f':.
0c00: 09 20 20 20 20 69 66 20 28 61 72 67 63 20 3d 3d . if (argc ==
0c10: 20 32 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 2) {...chars =
0c20: 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 snprintf(msg, si
0c30: 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 zeof(msg) - 1,..
0c40: 09 09 22 75 73 61 67 65 3a 20 25 73 20 2d 66 20 .."usage: %s -f
0c50: 3c 73 74 72 69 6e 67 3e 20 3c 73 75 62 73 74 72 <string> <substr
0c60: 69 6e 67 3e 5c 6e 22 0a 09 09 09 22 46 69 6e 64 ing>\n"...."Find
0c70: 20 61 20 73 75 62 73 74 72 69 6e 67 20 77 69 74 a substring wit
0c80: 68 69 6e 20 61 6e 6f 74 68 65 72 5c 6e 22 0a 09 hin another\n"..
0c90: 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 20 .."exitcodes: 0
0ca0: 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c == no, 1 == yes,
0cb0: 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c 20 2 == error\n",
0cc0: 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 argv[0]);...Writ
0cd0: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 eFile(GetStdHand
0ce0: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e le(STD_ERROR_HAN
0cf0: 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 DLE), msg, chars
0d00: 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c ,....&dwWritten,
0d10: 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e NULL);...return
0d20: 20 32 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 2;.. } else
0d30: 69 66 20 28 61 72 67 63 20 3d 3d 20 33 29 20 7b if (argc == 3) {
0d40: 0a 09 09 2f 2a 0a 09 09 20 2a 20 49 66 20 74 68 .../*... * If th
0d50: 65 20 73 74 72 69 6e 67 20 69 73 20 62 6c 61 6e e string is blan
0d60: 6b 2c 20 74 68 65 72 65 20 69 73 20 6e 6f 20 6d k, there is no m
0d70: 61 74 63 68 2e 0a 09 09 20 2a 2f 0a 0a 09 09 72 atch.... */....r
0d80: 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20 eturn 0;.. }
0d90: 65 6c 73 65 20 7b 0a 09 09 72 65 74 75 72 6e 20 else {...return
0da0: 49 73 49 6e 28 61 72 67 76 5b 32 5d 2c 20 61 72 IsIn(argv[2], ar
0db0: 67 76 5b 33 5d 29 3b 0a 09 20 20 20 20 7d 0a 09 gv[3]);.. }..
0dc0: 63 61 73 65 20 27 73 27 3a 0a 09 20 20 20 20 69 case 's':.. i
0dd0: 66 20 28 61 72 67 63 20 3d 3d 20 32 29 20 7b 0a f (argc == 2) {.
0de0: 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 69 6e ..chars = snprin
0df0: 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d tf(msg, sizeof(m
0e00: 73 67 29 20 2d 20 31 2c 0a 09 09 09 22 75 73 61 sg) - 1,...."usa
0e10: 67 65 3a 20 25 73 20 2d 73 20 3c 73 75 62 73 74 ge: %s -s <subst
0e20: 69 74 75 74 69 6f 6e 73 20 66 69 6c 65 3e 20 3c itutions file> <
0e30: 66 69 6c 65 3e 5c 6e 22 0a 09 09 09 22 50 65 72 file>\n"...."Per
0e40: 66 6f 72 6d 20 61 20 73 65 74 20 6f 66 20 73 74 form a set of st
0e50: 72 69 6e 67 20 6d 61 70 20 74 79 70 65 20 73 75 ring map type su
0e60: 62 73 74 75 74 69 74 69 6f 6e 73 20 6f 6e 20 61 bstutitions on a
0e70: 20 66 69 6c 65 5c 6e 22 0a 09 09 09 22 65 78 69 file\n"...."exi
0e80: 74 63 6f 64 65 73 3a 20 30 5c 6e 22 2c 0a 09 09 tcodes: 0\n",...
0e90: 09 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 .argv[0]);...Wri
0ea0: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e teFile(GetStdHan
0eb0: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 dle(STD_ERROR_HA
0ec0: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 NDLE), msg, char
0ed0: 73 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e s,....&dwWritten
0ee0: 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 , NULL);...retur
0ef0: 6e 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 n 2;.. }..
0f00: 20 72 65 74 75 72 6e 20 53 75 62 73 74 69 74 75 return Substitu
0f10: 74 65 46 69 6c 65 28 61 72 67 76 5b 32 5d 2c 20 teFile(argv[2],
0f20: 61 72 67 76 5b 33 5d 29 3b 0a 09 63 61 73 65 20 argv[3]);..case
0f30: 27 56 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 'V':.. if (ar
0f40: 67 63 20 21 3d 20 34 29 20 7b 0a 09 09 63 68 61 gc != 4) {...cha
0f50: 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 rs = snprintf(ms
0f60: 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d g, sizeof(msg) -
0f70: 20 31 2c 0a 09 09 20 20 20 20 22 75 73 61 67 65 1,... "usage
0f80: 3a 20 25 73 20 2d 56 20 66 69 6c 65 6e 61 6d 65 : %s -V filename
0f90: 20 6d 61 74 63 68 73 74 72 69 6e 67 5c 6e 22 0a matchstring\n".
0fa0: 09 09 20 20 20 20 22 45 78 74 72 61 63 74 20 61 .. "Extract a
0fb0: 20 76 65 72 73 69 6f 6e 20 66 72 6f 6d 20 61 20 version from a
0fc0: 66 69 6c 65 3a 5c 6e 22 0a 09 09 20 20 20 20 22 file:\n"... "
0fd0: 65 67 3a 20 70 6b 67 49 6e 64 65 78 2e 74 63 6c eg: pkgIndex.tcl
0fe0: 20 5c 22 70 61 63 6b 61 67 65 20 69 66 6e 65 65 \"package ifnee
0ff0: 64 65 64 20 68 74 74 70 5c 22 22 2c 0a 09 09 20 ded http\"",...
1000: 20 20 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 argv[0]);...W
1010: 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 riteFile(GetStdH
1020: 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f andle(STD_ERROR_
1030: 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 HANDLE), msg, ch
1040: 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57 72 ars,... &dwWr
1050: 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 itten, NULL);...
1060: 72 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d return 0;.. }
1070: 0a 09 20 20 20 20 73 20 3d 20 47 65 74 56 65 72 .. s = GetVer
1080: 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 61 72 67 sionFromFile(arg
1090: 76 5b 32 5d 2c 20 61 72 67 76 5b 33 5d 2c 20 2a v[2], argv[3], *
10a0: 28 61 72 67 76 5b 31 5d 2b 32 29 20 2d 20 27 30 (argv[1]+2) - '0
10b0: 27 29 3b 0a 09 20 20 20 20 69 66 20 28 73 20 26 ');.. if (s &
10c0: 26 20 2a 73 29 20 7b 0a 09 09 70 72 69 6e 74 66 & *s) {...printf
10d0: 28 22 25 73 5c 6e 22 2c 20 73 29 3b 0a 09 09 72 ("%s\n", s);...r
10e0: 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20 eturn 0;.. }
10f0: 65 6c 73 65 0a 09 09 72 65 74 75 72 6e 20 31 3b else...return 1;
1100: 20 2f 2a 20 56 65 72 73 69 6f 6e 20 6e 6f 74 20 /* Version not
1110: 66 6f 75 6e 64 2e 20 52 65 74 75 72 6e 20 6e 6f found. Return no
1120: 6e 2d 30 20 65 78 69 74 20 63 6f 64 65 20 2a 2f n-0 exit code */
1130: 0a 0a 09 63 61 73 65 20 27 51 27 3a 0a 09 20 20 ...case 'Q':..
1140: 20 20 69 66 20 28 61 72 67 63 20 21 3d 20 33 29 if (argc != 3)
1150: 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e 70 {...chars = snp
1160: 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f rintf(msg, sizeo
1170: 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 20 20 f(msg) - 1,...
1180: 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 51 20 "usage: %s -Q
1190: 70 61 74 68 5c 6e 22 0a 09 09 20 20 20 20 22 45 path\n"... "E
11a0: 6d 69 74 20 74 68 65 20 66 75 6c 6c 79 20 71 75 mit the fully qu
11b0: 61 6c 69 66 69 65 64 20 70 61 74 68 5c 6e 22 0a alified path\n".
11c0: 09 09 20 20 20 20 22 65 78 69 74 63 6f 64 65 73 .. "exitcodes
11d0: 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 : 0 == no, 1 ==
11e0: 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 5c yes, 2 == error\
11f0: 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 n", argv[0]);...
1200: 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 WriteFile(GetStd
1210: 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 Handle(STD_ERROR
1220: 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 _HANDLE), msg, c
1230: 68 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57 hars,... &dwW
1240: 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 ritten, NULL);..
1250: 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 .return 2;..
1260: 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 51 75 }.. return Qu
1270: 61 6c 69 66 79 50 61 74 68 28 61 72 67 76 5b 32 alifyPath(argv[2
1280: 5d 29 3b 0a 0a 09 63 61 73 65 20 27 4c 27 3a 0a ]);...case 'L':.
1290: 09 20 20 20 20 69 66 20 28 61 72 67 63 20 21 3d . if (argc !=
12a0: 20 33 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 3) {...chars =
12b0: 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 snprintf(msg, si
12c0: 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 zeof(msg) - 1,..
12d0: 09 20 20 20 20 22 75 73 61 67 65 3a 20 25 73 20 . "usage: %s
12e0: 2d 4c 20 6b 65 79 70 61 74 68 5c 6e 22 0a 09 09 -L keypath\n"...
12f0: 20 20 20 20 22 45 6d 69 74 20 74 68 65 20 66 75 "Emit the fu
1300: 6c 6c 79 20 71 75 61 6c 69 66 69 65 64 20 70 61 lly qualified pa
1310: 74 68 20 6f 66 20 64 69 72 65 63 74 6f 72 79 20 th of directory
1320: 63 6f 6e 74 61 69 6e 69 6e 67 20 6b 65 79 70 61 containing keypa
1330: 74 68 5c 6e 22 0a 09 09 20 20 20 20 22 65 78 69 th\n"... "exi
1340: 74 63 6f 64 65 73 3a 20 30 20 3d 3d 20 73 75 63 tcodes: 0 == suc
1350: 63 65 73 73 2c 20 31 20 3d 3d 20 6e 6f 74 20 66 cess, 1 == not f
1360: 6f 75 6e 64 2c 20 32 20 3d 3d 20 65 72 72 6f 72 ound, 2 == error
1370: 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 \n", argv[0]);..
1380: 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 .WriteFile(GetSt
1390: 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f dHandle(STD_ERRO
13a0: 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 R_HANDLE), msg,
13b0: 63 68 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 chars,... &dw
13c0: 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a Written, NULL);.
13d0: 09 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 ..return 2;..
13e0: 20 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 4c }.. return L
13f0: 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 28 ocateDependency(
1400: 61 72 67 76 5b 32 5d 29 3b 0a 09 7d 0a 20 20 20 argv[2]);..}.
1410: 20 7d 0a 20 20 20 20 63 68 61 72 73 20 3d 20 73 }. chars = s
1420: 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a nprintf(msg, siz
1430: 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 20 eof(msg) - 1,..
1440: 20 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 63 "usage: %s -c
1450: 7c 2d 66 7c 2d 6c 7c 2d 51 7c 2d 73 7c 2d 56 20 |-f|-l|-Q|-s|-V
1460: 2e 2e 2e 5c 6e 22 0a 09 20 20 20 20 22 54 68 69 ...\n".. "Thi
1470: 73 20 69 73 20 61 20 6c 69 74 74 6c 65 20 68 65 s is a little he
1480: 6c 70 65 72 20 61 70 70 20 74 6f 20 65 71 75 61 lper app to equa
1490: 6c 69 7a 65 20 73 68 65 6c 6c 20 64 69 66 66 65 lize shell diffe
14a0: 72 65 6e 63 65 73 20 62 65 74 77 65 65 6e 20 57 rences between W
14b0: 69 6e 4e 54 20 61 6e 64 5c 6e 22 0a 09 20 20 20 inNT and\n"..
14c0: 20 22 57 69 6e 39 78 20 61 6e 64 20 67 65 74 20 "Win9x and get
14d0: 6e 6d 61 6b 65 2e 65 78 65 20 74 6f 20 61 63 63 nmake.exe to acc
14e0: 6f 6d 70 6c 69 73 68 20 69 74 73 20 6a 6f 62 2e omplish its job.
14f0: 5c 6e 22 2c 0a 09 20 20 20 20 61 72 67 76 5b 30 \n",.. argv[0
1500: 5d 29 3b 0a 20 20 20 20 57 72 69 74 65 46 69 6c ]);. WriteFil
1510: 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53 e(GetStdHandle(S
1520: 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 TD_ERROR_HANDLE)
1530: 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 20 26 64 , msg, chars, &d
1540: 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b wWritten, NULL);
1550: 0a 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 7d . return 2;.}
1560: 0a 0c 0a 73 74 61 74 69 63 20 69 6e 74 0a 43 68 ...static int.Ch
1570: 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 eckForCompilerFe
1580: 61 74 75 72 65 28 0a 20 20 20 20 63 6f 6e 73 74 ature(. const
1590: 20 63 68 61 72 20 2a 6f 70 74 69 6f 6e 29 0a 7b char *option).{
15a0: 0a 20 20 20 20 53 54 41 52 54 55 50 49 4e 46 4f . STARTUPINFO
15b0: 20 73 69 3b 0a 20 20 20 20 50 52 4f 43 45 53 53 si;. PROCESS
15c0: 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 70 69 3b _INFORMATION pi;
15d0: 0a 20 20 20 20 53 45 43 55 52 49 54 59 5f 41 54 . SECURITY_AT
15e0: 54 52 49 42 55 54 45 53 20 73 61 3b 0a 20 20 20 TRIBUTES sa;.
15f0: 20 44 57 4f 52 44 20 74 68 72 65 61 64 49 44 3b DWORD threadID;
1600: 0a 20 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 . char msg[30
1610: 30 5d 3b 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0];. BOOL ok;
1620: 0a 20 20 20 20 48 41 4e 44 4c 45 20 68 50 72 6f . HANDLE hPro
1630: 63 65 73 73 2c 20 68 2c 20 70 69 70 65 54 68 72 cess, h, pipeThr
1640: 65 61 64 73 5b 32 5d 3b 0a 20 20 20 20 63 68 61 eads[2];. cha
1650: 72 20 63 6d 64 6c 69 6e 65 5b 31 30 30 5d 3b 0a r cmdline[100];.
1660: 0a 20 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20 . hProcess =
1670: 47 65 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73 GetCurrentProces
1680: 73 28 29 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 s();.. memset
1690: 28 26 70 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 (&pi, 0, sizeof(
16a0: 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 PROCESS_INFORMAT
16b0: 49 4f 4e 29 29 3b 0a 20 20 20 20 6d 65 6d 73 65 ION));. memse
16c0: 74 28 26 73 69 2c 20 30 2c 20 73 69 7a 65 6f 66 t(&si, 0, sizeof
16d0: 28 53 54 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a (STARTUPINFO));.
16e0: 20 20 20 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 si.cb = size
16f0: 6f 66 28 53 54 41 52 54 55 50 49 4e 46 4f 29 3b of(STARTUPINFO);
1700: 0a 20 20 20 20 73 69 2e 64 77 46 6c 61 67 73 20 . si.dwFlags
1710: 20 20 3d 20 53 54 41 52 54 46 5f 55 53 45 53 54 = STARTF_USEST
1720: 44 48 41 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 DHANDLES;. si
1730: 2e 68 53 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 .hStdInput = INV
1740: 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 ALID_HANDLE_VALU
1750: 45 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26 E;.. memset(&
1760: 73 61 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 45 sa, 0, sizeof(SE
1770: 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 CURITY_ATTRIBUTE
1780: 53 29 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e S));. sa.nLen
1790: 67 74 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43 gth = sizeof(SEC
17a0: 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 URITY_ATTRIBUTES
17b0: 29 3b 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75 );. sa.lpSecu
17c0: 72 69 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d rityDescriptor =
17d0: 20 4e 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49 NULL;. sa.bI
17e0: 6e 68 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 46 nheritHandle = F
17f0: 41 4c 53 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 ALSE;.. /*.
1800: 20 20 20 2a 20 43 72 65 61 74 65 20 61 20 6e 6f * Create a no
1810: 6e 2d 69 6e 68 65 72 69 74 61 62 6c 65 20 70 69 n-inheritable pi
1820: 70 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 pe.. */..
1830: 20 43 72 65 61 74 65 50 69 70 65 28 26 4f 75 74 CreatePipe(&Out
1840: 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 .pipe, &h, &sa,
1850: 30 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 0);.. /*.
1860: 20 2a 20 44 75 70 65 20 74 68 65 20 77 72 69 74 * Dupe the writ
1870: 65 20 73 69 64 65 2c 20 6d 61 6b 65 20 69 74 20 e side, make it
1880: 69 6e 68 65 72 69 74 61 62 6c 65 2c 20 61 6e 64 inheritable, and
1890: 20 63 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 69 close the origi
18a0: 6e 61 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 nal.. */..
18b0: 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c DuplicateHandl
18c0: 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 e(hProcess, h, h
18d0: 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 Process, &si.hSt
18e0: 64 4f 75 74 70 75 74 2c 20 30 2c 20 54 52 55 45 dOutput, 0, TRUE
18f0: 2c 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 ,.. DUPLICATE
1900: 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 _SAME_ACCESS | D
1910: 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 UPLICATE_CLOSE_S
1920: 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a OURCE);.. /*.
1930: 20 20 20 20 20 2a 20 53 61 6d 65 20 61 73 20 61 * Same as a
1940: 62 6f 76 65 2c 20 62 75 74 20 66 6f 72 20 74 68 bove, but for th
1950: 65 20 65 72 72 6f 72 20 73 69 64 65 2e 0a 20 20 e error side..
1960: 20 20 20 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 */.. Creat
1970: 65 50 69 70 65 28 26 45 72 72 2e 70 69 70 65 2c ePipe(&Err.pipe,
1980: 20 26 68 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20 &h, &sa, 0);.
1990: 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c DuplicateHandl
19a0: 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 e(hProcess, h, h
19b0: 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 Process, &si.hSt
19c0: 64 45 72 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c dError, 0, TRUE,
19d0: 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f .. DUPLICATE_
19e0: 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 SAME_ACCESS | DU
19f0: 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f PLICATE_CLOSE_SO
1a00: 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 URCE);.. /*.
1a10: 20 20 20 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61 * Base comma
1a20: 6e 64 20 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f nd line.. */
1a30: 0a 0a 20 20 20 20 6c 73 74 72 63 70 79 28 63 6d .. lstrcpy(cm
1a40: 64 6c 69 6e 65 2c 20 22 63 6c 2e 65 78 65 20 2d dline, "cl.exe -
1a50: 6e 6f 6c 6f 67 6f 20 2d 63 20 2d 54 43 20 2d 5a nologo -c -TC -Z
1a60: 73 20 2d 58 20 2d 46 70 2e 5c 5c 5f 6a 75 6e 6b s -X -Fp.\\_junk
1a70: 2e 70 63 68 20 22 29 3b 0a 0a 20 20 20 20 2f 2a .pch ");.. /*
1a80: 0a 20 20 20 20 20 2a 20 41 70 70 65 6e 64 20 6f . * Append o
1a90: 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 65 ur option for te
1aa0: 73 74 69 6e 67 0a 20 20 20 20 20 2a 2f 0a 0a 20 sting. */..
1ab0: 20 20 20 6c 73 74 72 63 61 74 28 63 6d 64 6c 69 lstrcat(cmdli
1ac0: 6e 65 2c 20 6f 70 74 69 6f 6e 29 3b 0a 0a 20 20 ne, option);..
1ad0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 46 69 6c 65 /*. * File
1ae0: 6e 61 6d 65 20 74 6f 20 63 6f 6d 70 69 6c 65 2c name to compile,
1af0: 20 77 68 69 63 68 20 65 78 69 73 74 73 2c 20 62 which exists, b
1b00: 75 74 20 69 73 20 6e 6f 74 68 69 6e 67 20 61 6e ut is nothing an
1b10: 64 20 65 6d 70 74 79 2e 0a 20 20 20 20 20 2a 2f d empty.. */
1b20: 0a 0a 20 20 20 20 6c 73 74 72 63 61 74 28 63 6d .. lstrcat(cm
1b30: 64 6c 69 6e 65 2c 20 22 20 2e 5c 5c 6e 75 6c 22 dline, " .\\nul"
1b40: 29 3b 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 65 );.. ok = Cre
1b50: 61 74 65 50 72 6f 63 65 73 73 28 0a 09 20 20 20 ateProcess(..
1b60: 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d 6f NULL,. /* Mo
1b70: 64 75 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 20 dule name. */..
1b80: 20 20 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 20 cmdline,.
1b90: 2f 2a 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e /* Command line.
1ba0: 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 */.. NULL,.
1bb0: 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 61 /* Process ha
1bc0: 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 74 ndle not inherit
1bd0: 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 able. */.. NU
1be0: 4c 4c 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 61 LL,. /* Threa
1bf0: 64 20 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 d handle not inh
1c00: 65 72 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 eritable. */..
1c10: 20 20 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 79 TRUE,. /* y
1c20: 65 73 2c 20 69 6e 68 65 72 69 74 20 68 61 6e 64 es, inherit hand
1c30: 6c 65 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 54 les. */.. DET
1c40: 41 43 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 2f ACHED_PROCESS, /
1c50: 2a 20 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f 72 * No console for
1c60: 20 79 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 you. */.. NU
1c70: 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 70 LL,. /* Use p
1c80: 61 72 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e 6d arent's environm
1c90: 65 6e 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 20 ent block. */..
1ca0: 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 NULL,. /*
1cb0: 55 73 65 20 70 61 72 65 6e 74 27 73 20 73 74 61 Use parent's sta
1cc0: 72 74 69 6e 67 20 64 69 72 65 63 74 6f 72 79 2e rting directory.
1cd0: 20 2a 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 20 */.. &si,.
1ce0: 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 /* Pointer to
1cf0: 53 54 41 52 54 55 50 49 4e 46 4f 20 73 74 72 75 STARTUPINFO stru
1d00: 63 74 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 26 cture. */.. &
1d10: 70 69 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 6e pi);. /* Poin
1d20: 74 65 72 20 74 6f 20 50 52 4f 43 45 53 53 5f 49 ter to PROCESS_I
1d30: 4e 46 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 63 NFORMATION struc
1d40: 74 75 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 66 ture. */.. if
1d50: 20 28 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 20 (!ok) {..DWORD
1d60: 65 72 72 20 3d 20 47 65 74 4c 61 73 74 45 72 72 err = GetLastErr
1d70: 6f 72 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 73 or();..int chars
1d80: 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c = snprintf(msg,
1d90: 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 sizeof(msg) - 1
1da0: 2c 0a 09 09 22 54 72 69 65 64 20 74 6f 20 6c 61 ,..."Tried to la
1db0: 75 6e 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 75 unch: \"%s\", bu
1dc0: 74 20 67 6f 74 20 65 72 72 6f 72 20 5b 25 75 5d t got error [%u]
1dd0: 3a 20 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65 72 : ", cmdline, er
1de0: 72 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73 73 r);...FormatMess
1df0: 61 67 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53 41 age(FORMAT_MESSA
1e00: 47 45 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c 46 GE_FROM_SYSTEM|F
1e10: 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49 47 ORMAT_MESSAGE_IG
1e20: 4e 4f 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09 09 NORE_INSERTS|...
1e30: 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 4d FORMAT_MESSAGE_M
1e40: 41 58 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20 30 AX_WIDTH_MASK, 0
1e50: 4c 2c 20 65 72 72 2c 20 30 2c 20 28 4c 50 53 54 L, err, 0, (LPST
1e60: 52 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c 0a 09 R)&msg[chars],..
1e70: 09 28 33 30 30 2d 63 68 61 72 73 29 2c 20 30 29 .(300-chars), 0)
1e80: 3b 0a 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 ;..WriteFile(Get
1e90: 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 StdHandle(STD_ER
1ea0: 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 ROR_HANDLE), msg
1eb0: 2c 20 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c 20 , lstrlen(msg),
1ec0: 26 65 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65 74 &err,NULL);..ret
1ed0: 75 72 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 20 urn 2;. }..
1ee0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f 73 /*. * Clos
1ef0: 65 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65 73 e our references
1f00: 20 74 6f 20 74 68 65 20 77 72 69 74 65 20 68 61 to the write ha
1f10: 6e 64 6c 65 73 20 74 68 61 74 20 68 61 76 65 20 ndles that have
1f20: 6e 6f 77 20 62 65 65 6e 20 69 6e 68 65 72 69 74 now been inherit
1f30: 65 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ed.. */..
1f40: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e CloseHandle(si.
1f50: 68 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 20 hStdOutput);.
1f60: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e CloseHandle(si.
1f70: 68 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 20 hStdError);..
1f80: 20 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64 6c WaitForInputIdl
1f90: 65 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 35 e(pi.hProcess, 5
1fa0: 30 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 000);. CloseH
1fb0: 61 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61 64 andle(pi.hThread
1fc0: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
1fd0: 2a 20 53 74 61 72 74 20 74 68 65 20 70 69 70 65 * Start the pipe
1fe0: 20 72 65 61 64 65 72 20 74 68 72 65 61 64 73 2e reader threads.
1ff0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70 69 . */.. pi
2000: 70 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 43 peThreads[0] = C
2010: 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c reateThread(NULL
2020: 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 , 0, ReadFromPip
2030: 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 72 e, &Out, 0, &thr
2040: 65 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70 65 eadID);. pipe
2050: 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 65 Threads[1] = Cre
2060: 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 ateThread(NULL,
2070: 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 2c 0, ReadFromPipe,
2080: 20 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65 61 &Err, 0, &threa
2090: 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 dID);.. /*.
20a0: 20 20 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74 69 * Block waiti
20b0: 6e 67 20 66 6f 72 20 74 68 65 20 70 72 6f 63 65 ng for the proce
20c0: 73 73 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20 20 ss to end..
20d0: 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f 72 53 */.. WaitForS
20e0: 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e 68 ingleObject(pi.h
20f0: 50 72 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49 54 Process, INFINIT
2100: 45 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e E);. CloseHan
2110: 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 29 dle(pi.hProcess)
2120: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
2130: 20 57 61 69 74 20 66 6f 72 20 6f 75 72 20 70 69 Wait for our pi
2140: 70 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 72 pe to get done r
2150: 65 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 69 eading, should i
2160: 74 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73 6c t be a little sl
2170: 6f 77 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ow.. */..
2180: 20 57 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c 65 WaitForMultiple
2190: 4f 62 6a 65 63 74 73 28 32 2c 20 70 69 70 65 54 Objects(2, pipeT
21a0: 68 72 65 61 64 73 2c 20 54 52 55 45 2c 20 35 30 hreads, TRUE, 50
21b0: 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 0);. CloseHan
21c0: 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 5b dle(pipeThreads[
21d0: 30 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 0]);. CloseHa
21e0: 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 ndle(pipeThreads
21f0: 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 [1]);.. /*.
2200: 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74 68 * Look for th
2210: 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77 61 e commandline wa
2220: 72 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 62 6f rning code in bo
2230: 74 68 20 73 74 72 65 61 6d 73 2e 0a 20 20 20 20 th streams..
2240: 20 2a 20 20 2d 20 69 6e 20 4d 53 56 43 20 36 20 * - in MSVC 6
2250: 26 20 37 20 77 65 20 67 65 74 20 44 34 30 30 32 & 7 we get D4002
2260: 2c 20 69 6e 20 4d 53 56 43 20 38 20 77 65 20 67 , in MSVC 8 we g
2270: 65 74 20 44 39 30 30 32 2e 0a 20 20 20 20 20 2a et D9002.. *
2280: 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 21 28 /.. return !(
2290: 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 strstr(Out.buffe
22a0: 72 2c 20 22 44 34 30 30 32 22 29 20 21 3d 20 4e r, "D4002") != N
22b0: 55 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ULL.
22c0: 20 7c 7c 20 73 74 72 73 74 72 28 45 72 72 2e 62 || strstr(Err.b
22d0: 75 66 66 65 72 2c 20 22 44 34 30 30 32 22 29 20 uffer, "D4002")
22e0: 21 3d 20 4e 55 4c 4c 0a 20 20 20 20 20 20 20 20 != NULL.
22f0: 20 20 20 20 20 7c 7c 20 73 74 72 73 74 72 28 4f || strstr(O
2300: 75 74 2e 62 75 66 66 65 72 2c 20 22 44 39 30 30 ut.buffer, "D900
2310: 32 22 29 20 21 3d 20 4e 55 4c 4c 0a 20 20 20 20 2") != NULL.
2320: 20 20 20 20 20 20 20 20 20 7c 7c 20 73 74 72 73 || strs
2330: 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 tr(Err.buffer, "
2340: 44 39 30 30 32 22 29 20 21 3d 20 4e 55 4c 4c 0a D9002") != NULL.
2350: 20 20 20 20 20 20 20 20 20 20 20 20 20 7c 7c 20 ||
2360: 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 strstr(Out.buffe
2370: 72 2c 20 22 44 32 30 32 31 22 29 20 21 3d 20 4e r, "D2021") != N
2380: 55 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 20 20 ULL.
2390: 20 7c 7c 20 73 74 72 73 74 72 28 45 72 72 2e 62 || strstr(Err.b
23a0: 75 66 66 65 72 2c 20 22 44 32 30 32 31 22 29 20 uffer, "D2021")
23b0: 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a 73 74 != NULL);.}...st
23c0: 61 74 69 63 20 69 6e 74 0a 43 68 65 63 6b 46 6f atic int.CheckFo
23d0: 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 0a rLinkerFeature(.
23e0: 20 20 20 20 63 68 61 72 20 2a 2a 6f 70 74 69 6f char **optio
23f0: 6e 73 2c 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e ns,. int coun
2400: 74 29 0a 7b 0a 20 20 20 20 53 54 41 52 54 55 50 t).{. STARTUP
2410: 49 4e 46 4f 20 73 69 3b 0a 20 20 20 20 50 52 4f INFO si;. PRO
2420: 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e CESS_INFORMATION
2430: 20 70 69 3b 0a 20 20 20 20 53 45 43 55 52 49 54 pi;. SECURIT
2440: 59 5f 41 54 54 52 49 42 55 54 45 53 20 73 61 3b Y_ATTRIBUTES sa;
2450: 0a 20 20 20 20 44 57 4f 52 44 20 74 68 72 65 61 . DWORD threa
2460: 64 49 44 3b 0a 20 20 20 20 63 68 61 72 20 6d 73 dID;. char ms
2470: 67 5b 33 30 30 5d 3b 0a 20 20 20 20 42 4f 4f 4c g[300];. BOOL
2480: 20 6f 6b 3b 0a 20 20 20 20 48 41 4e 44 4c 45 20 ok;. HANDLE
2490: 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 70 69 70 hProcess, h, pip
24a0: 65 54 68 72 65 61 64 73 5b 32 5d 3b 0a 20 20 20 eThreads[2];.
24b0: 20 69 6e 74 20 69 3b 0a 20 20 20 20 63 68 61 72 int i;. char
24c0: 20 63 6d 64 6c 69 6e 65 5b 32 35 35 5d 3b 0a 0a cmdline[255];..
24d0: 20 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20 47 hProcess = G
24e0: 65 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73 73 etCurrentProcess
24f0: 28 29 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 ();.. memset(
2500: 26 70 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 50 &pi, 0, sizeof(P
2510: 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 ROCESS_INFORMATI
2520: 4f 4e 29 29 3b 0a 20 20 20 20 6d 65 6d 73 65 74 ON));. memset
2530: 28 26 73 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 (&si, 0, sizeof(
2540: 53 54 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a 20 STARTUPINFO));.
2550: 20 20 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 6f si.cb = sizeo
2560: 66 28 53 54 41 52 54 55 50 49 4e 46 4f 29 3b 0a f(STARTUPINFO);.
2570: 20 20 20 20 73 69 2e 64 77 46 6c 61 67 73 20 20 si.dwFlags
2580: 20 3d 20 53 54 41 52 54 46 5f 55 53 45 53 54 44 = STARTF_USESTD
2590: 48 41 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 2e HANDLES;. si.
25a0: 68 53 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 41 hStdInput = INVA
25b0: 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 LID_HANDLE_VALUE
25c0: 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26 73 ;.. memset(&s
25d0: 61 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 45 43 a, 0, sizeof(SEC
25e0: 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 URITY_ATTRIBUTES
25f0: 29 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e 67 ));. sa.nLeng
2600: 74 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43 55 th = sizeof(SECU
2610: 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 RITY_ATTRIBUTES)
2620: 3b 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75 72 ;. sa.lpSecur
2630: 69 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d 20 ityDescriptor =
2640: 4e 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49 6e NULL;. sa.bIn
2650: 68 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 54 52 heritHandle = TR
2660: 55 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 UE;.. /*.
2670: 20 2a 20 43 72 65 61 74 65 20 61 20 6e 6f 6e 2d * Create a non-
2680: 69 6e 68 65 72 69 74 69 62 6c 65 20 70 69 70 65 inheritible pipe
2690: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 .. */.. C
26a0: 72 65 61 74 65 50 69 70 65 28 26 4f 75 74 2e 70 reatePipe(&Out.p
26b0: 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 ipe, &h, &sa, 0)
26c0: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
26d0: 20 44 75 70 65 20 74 68 65 20 77 72 69 74 65 20 Dupe the write
26e0: 73 69 64 65 2c 20 6d 61 6b 65 20 69 74 20 69 6e side, make it in
26f0: 68 65 72 69 74 61 62 6c 65 2c 20 61 6e 64 20 63 heritable, and c
2700: 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 69 6e 61 lose the origina
2710: 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 l.. */..
2720: 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 DuplicateHandle(
2730: 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 hProcess, h, hPr
2740: 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 4f ocess, &si.hStdO
2750: 75 74 70 75 74 2c 20 30 2c 20 54 52 55 45 2c 0a utput, 0, TRUE,.
2760: 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 . DUPLICATE_S
2770: 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 AME_ACCESS | DUP
2780: 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 LICATE_CLOSE_SOU
2790: 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 RCE);.. /*.
27a0: 20 20 20 2a 20 53 61 6d 65 20 61 73 20 61 62 6f * Same as abo
27b0: 76 65 2c 20 62 75 74 20 66 6f 72 20 74 68 65 20 ve, but for the
27c0: 65 72 72 6f 72 20 73 69 64 65 2e 0a 20 20 20 20 error side..
27d0: 20 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 65 50 */.. CreateP
27e0: 69 70 65 28 26 45 72 72 2e 70 69 70 65 2c 20 26 ipe(&Err.pipe, &
27f0: 68 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20 20 20 h, &sa, 0);.
2800: 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 DuplicateHandle(
2810: 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 hProcess, h, hPr
2820: 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 45 ocess, &si.hStdE
2830: 72 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c 0a 09 rror, 0, TRUE,..
2840: 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 41 DUPLICATE_SA
2850: 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 4c ME_ACCESS | DUPL
2860: 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 52 ICATE_CLOSE_SOUR
2870: 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 CE);.. /*.
2880: 20 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61 6e 64 * Base command
2890: 20 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a line.. */..
28a0: 20 20 20 20 6c 73 74 72 63 70 79 28 63 6d 64 6c lstrcpy(cmdl
28b0: 69 6e 65 2c 20 22 6c 69 6e 6b 2e 65 78 65 20 2d ine, "link.exe -
28c0: 6e 6f 6c 6f 67 6f 20 22 29 3b 0a 0a 20 20 20 20 nologo ");..
28d0: 2f 2a 0a 20 20 20 20 20 2a 20 41 70 70 65 6e 64 /*. * Append
28e0: 20 6f 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 our option for
28f0: 74 65 73 74 69 6e 67 2e 0a 20 20 20 20 20 2a 2f testing.. */
2900: 0a 0a 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 .. for (i = 0
2910: 3b 20 69 20 3c 20 63 6f 75 6e 74 3b 20 69 2b 2b ; i < count; i++
2920: 29 20 7b 0a 09 6c 73 74 72 63 61 74 28 63 6d 64 ) {..lstrcat(cmd
2930: 6c 69 6e 65 2c 20 22 20 5c 22 22 29 3b 0a 09 6c line, " \"");..l
2940: 73 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 strcat(cmdline,
2950: 6f 70 74 69 6f 6e 73 5b 69 5d 29 3b 0a 09 6c 73 options[i]);..ls
2960: 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 22 trcat(cmdline, "
2970: 5c 22 22 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 \"");. }..
2980: 20 6f 6b 20 3d 20 43 72 65 61 74 65 50 72 6f 63 ok = CreateProc
2990: 65 73 73 28 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 ess(.. NULL,.
29a0: 20 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 6e 61 /* Module na
29b0: 6d 65 2e 20 2a 2f 0a 09 20 20 20 20 63 6d 64 6c me. */.. cmdl
29c0: 69 6e 65 2c 09 20 20 20 20 2f 2a 20 43 6f 6d 6d ine,. /* Comm
29d0: 61 6e 64 20 6c 69 6e 65 2e 20 2a 2f 0a 09 20 20 and line. */..
29e0: 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 50 NULL,. /* P
29f0: 72 6f 63 65 73 73 20 68 61 6e 64 6c 65 20 6e 6f rocess handle no
2a00: 74 20 69 6e 68 65 72 69 74 61 62 6c 65 2e 20 2a t inheritable. *
2a10: 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 /.. NULL,.
2a20: 20 2f 2a 20 54 68 72 65 61 64 20 68 61 6e 64 6c /* Thread handl
2a30: 65 20 6e 6f 74 20 69 6e 68 65 72 69 74 61 62 6c e not inheritabl
2a40: 65 2e 20 2a 2f 0a 09 20 20 20 20 54 52 55 45 2c e. */.. TRUE,
2a50: 09 20 20 20 20 2f 2a 20 79 65 73 2c 20 69 6e 68 . /* yes, inh
2a60: 65 72 69 74 20 68 61 6e 64 6c 65 73 2e 20 2a 2f erit handles. */
2a70: 0a 09 20 20 20 20 44 45 54 41 43 48 45 44 5f 50 .. DETACHED_P
2a80: 52 4f 43 45 53 53 2c 20 2f 2a 20 4e 6f 20 63 6f ROCESS, /* No co
2a90: 6e 73 6f 6c 65 20 66 6f 72 20 79 6f 75 2e 20 2a nsole for you. *
2aa0: 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 /.. NULL,.
2ab0: 20 2f 2a 20 55 73 65 20 70 61 72 65 6e 74 27 73 /* Use parent's
2ac0: 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 62 6c 6f environment blo
2ad0: 63 6b 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c ck. */.. NULL
2ae0: 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 70 61 72 ,. /* Use par
2af0: 65 6e 74 27 73 20 73 74 61 72 74 69 6e 67 20 64 ent's starting d
2b00: 69 72 65 63 74 6f 72 79 2e 20 2a 2f 0a 09 20 20 irectory. */..
2b10: 20 20 26 73 69 2c 09 20 20 20 20 2f 2a 20 50 6f &si,. /* Po
2b20: 69 6e 74 65 72 20 74 6f 20 53 54 41 52 54 55 50 inter to STARTUP
2b30: 49 4e 46 4f 20 73 74 72 75 63 74 75 72 65 2e 20 INFO structure.
2b40: 2a 2f 0a 09 20 20 20 20 26 70 69 29 3b 09 20 20 */.. &pi);.
2b50: 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 /* Pointer to
2b60: 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 PROCESS_INFORMAT
2b70: 49 4f 4e 20 73 74 72 75 63 74 75 72 65 2e 20 2a ION structure. *
2b80: 2f 0a 0a 20 20 20 20 69 66 20 28 21 6f 6b 29 20 /.. if (!ok)
2b90: 7b 0a 09 44 57 4f 52 44 20 65 72 72 20 3d 20 47 {..DWORD err = G
2ba0: 65 74 4c 61 73 74 45 72 72 6f 72 28 29 3b 0a 09 etLastError();..
2bb0: 69 6e 74 20 63 68 61 72 73 20 3d 20 73 6e 70 72 int chars = snpr
2bc0: 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 intf(msg, sizeof
2bd0: 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 22 54 72 (msg) - 1,..."Tr
2be0: 69 65 64 20 74 6f 20 6c 61 75 6e 63 68 3a 20 5c ied to launch: \
2bf0: 22 25 73 5c 22 2c 20 62 75 74 20 67 6f 74 20 65 "%s\", but got e
2c00: 72 72 6f 72 20 5b 25 75 5d 3a 20 22 2c 20 63 6d rror [%u]: ", cm
2c10: 64 6c 69 6e 65 2c 20 65 72 72 29 3b 0a 0a 09 46 dline, err);...F
2c20: 6f 72 6d 61 74 4d 65 73 73 61 67 65 28 46 4f 52 ormatMessage(FOR
2c30: 4d 41 54 5f 4d 45 53 53 41 47 45 5f 46 52 4f 4d MAT_MESSAGE_FROM
2c40: 5f 53 59 53 54 45 4d 7c 46 4f 52 4d 41 54 5f 4d _SYSTEM|FORMAT_M
2c50: 45 53 53 41 47 45 5f 49 47 4e 4f 52 45 5f 49 4e ESSAGE_IGNORE_IN
2c60: 53 45 52 54 53 7c 0a 09 09 46 4f 52 4d 41 54 5f SERTS|...FORMAT_
2c70: 4d 45 53 53 41 47 45 5f 4d 41 58 5f 57 49 44 54 MESSAGE_MAX_WIDT
2c80: 48 5f 4d 41 53 4b 2c 20 30 4c 2c 20 65 72 72 2c H_MASK, 0L, err,
2c90: 20 30 2c 20 28 4c 50 53 54 52 29 26 6d 73 67 5b 0, (LPSTR)&msg[
2ca0: 63 68 61 72 73 5d 2c 0a 09 09 28 33 30 30 2d 63 chars],...(300-c
2cb0: 68 61 72 73 29 2c 20 30 29 3b 0a 09 57 72 69 74 hars), 0);..Writ
2cc0: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 eFile(GetStdHand
2cd0: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e le(STD_ERROR_HAN
2ce0: 44 4c 45 29 2c 20 6d 73 67 2c 20 6c 73 74 72 6c DLE), msg, lstrl
2cf0: 65 6e 28 6d 73 67 29 2c 20 26 65 72 72 2c 4e 55 en(msg), &err,NU
2d00: 4c 4c 29 3b 0a 09 72 65 74 75 72 6e 20 32 3b 0a LL);..return 2;.
2d10: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 0a 20 20 }.. /*.
2d20: 20 20 20 2a 20 43 6c 6f 73 65 20 6f 75 72 20 72 * Close our r
2d30: 65 66 65 72 65 6e 63 65 73 20 74 6f 20 74 68 65 eferences to the
2d40: 20 77 72 69 74 65 20 68 61 6e 64 6c 65 73 20 74 write handles t
2d50: 68 61 74 20 68 61 76 65 20 6e 6f 77 20 62 65 65 hat have now bee
2d60: 6e 20 69 6e 68 65 72 69 74 65 64 2e 0a 20 20 20 n inherited..
2d70: 20 20 2a 2f 0a 0a 20 20 20 20 43 6c 6f 73 65 48 */.. CloseH
2d80: 61 6e 64 6c 65 28 73 69 2e 68 53 74 64 4f 75 74 andle(si.hStdOut
2d90: 70 75 74 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 put);. CloseH
2da0: 61 6e 64 6c 65 28 73 69 2e 68 53 74 64 45 72 72 andle(si.hStdErr
2db0: 6f 72 29 3b 0a 0a 20 20 20 20 57 61 69 74 46 6f or);.. WaitFo
2dc0: 72 49 6e 70 75 74 49 64 6c 65 28 70 69 2e 68 50 rInputIdle(pi.hP
2dd0: 72 6f 63 65 73 73 2c 20 35 30 30 30 29 3b 0a 20 rocess, 5000);.
2de0: 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 CloseHandle(p
2df0: 69 2e 68 54 68 72 65 61 64 29 3b 0a 0a 20 20 20 i.hThread);..
2e00: 20 2f 2a 0a 20 20 20 20 20 2a 20 53 74 61 72 74 /*. * Start
2e10: 20 74 68 65 20 70 69 70 65 20 72 65 61 64 65 72 the pipe reader
2e20: 20 74 68 72 65 61 64 73 2e 0a 20 20 20 20 20 2a threads.. *
2e30: 2f 0a 0a 20 20 20 20 70 69 70 65 54 68 72 65 61 /.. pipeThrea
2e40: 64 73 5b 30 5d 20 3d 20 43 72 65 61 74 65 54 68 ds[0] = CreateTh
2e50: 72 65 61 64 28 4e 55 4c 4c 2c 20 30 2c 20 52 65 read(NULL, 0, Re
2e60: 61 64 46 72 6f 6d 50 69 70 65 2c 20 26 4f 75 74 adFromPipe, &Out
2e70: 2c 20 30 2c 20 26 74 68 72 65 61 64 49 44 29 3b , 0, &threadID);
2e80: 0a 20 20 20 20 70 69 70 65 54 68 72 65 61 64 73 . pipeThreads
2e90: 5b 31 5d 20 3d 20 43 72 65 61 74 65 54 68 72 65 [1] = CreateThre
2ea0: 61 64 28 4e 55 4c 4c 2c 20 30 2c 20 52 65 61 64 ad(NULL, 0, Read
2eb0: 46 72 6f 6d 50 69 70 65 2c 20 26 45 72 72 2c 20 FromPipe, &Err,
2ec0: 30 2c 20 26 74 68 72 65 61 64 49 44 29 3b 0a 0a 0, &threadID);..
2ed0: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 42 6c /*. * Bl
2ee0: 6f 63 6b 20 77 61 69 74 69 6e 67 20 66 6f 72 20 ock waiting for
2ef0: 74 68 65 20 70 72 6f 63 65 73 73 20 74 6f 20 65 the process to e
2f00: 6e 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 nd.. */..
2f10: 20 57 61 69 74 46 6f 72 53 69 6e 67 6c 65 4f 62 WaitForSingleOb
2f20: 6a 65 63 74 28 70 69 2e 68 50 72 6f 63 65 73 73 ject(pi.hProcess
2f30: 2c 20 49 4e 46 49 4e 49 54 45 29 3b 0a 20 20 20 , INFINITE);.
2f40: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 2e CloseHandle(pi.
2f50: 68 50 72 6f 63 65 73 73 29 3b 0a 0a 20 20 20 20 hProcess);..
2f60: 2f 2a 0a 20 20 20 20 20 2a 20 57 61 69 74 20 66 /*. * Wait f
2f70: 6f 72 20 6f 75 72 20 70 69 70 65 20 74 6f 20 67 or our pipe to g
2f80: 65 74 20 64 6f 6e 65 20 72 65 61 64 69 6e 67 2c et done reading,
2f90: 20 73 68 6f 75 6c 64 20 69 74 20 62 65 20 61 20 should it be a
2fa0: 6c 69 74 74 6c 65 20 73 6c 6f 77 2e 0a 20 20 20 little slow..
2fb0: 20 20 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f */.. WaitFo
2fc0: 72 4d 75 6c 74 69 70 6c 65 4f 62 6a 65 63 74 73 rMultipleObjects
2fd0: 28 32 2c 20 70 69 70 65 54 68 72 65 61 64 73 2c (2, pipeThreads,
2fe0: 20 54 52 55 45 2c 20 35 30 30 29 3b 0a 20 20 20 TRUE, 500);.
2ff0: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 70 CloseHandle(pip
3000: 65 54 68 72 65 61 64 73 5b 30 5d 29 3b 0a 20 20 eThreads[0]);.
3010: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 CloseHandle(pi
3020: 70 65 54 68 72 65 61 64 73 5b 31 5d 29 3b 0a 0a peThreads[1]);..
3030: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4c 6f /*. * Lo
3040: 6f 6b 20 66 6f 72 20 74 68 65 20 63 6f 6d 6d 61 ok for the comma
3050: 6e 64 6c 69 6e 65 20 77 61 72 6e 69 6e 67 20 63 ndline warning c
3060: 6f 64 65 20 69 6e 20 74 68 65 20 73 74 64 65 72 ode in the stder
3070: 72 20 73 74 72 65 61 6d 2e 0a 20 20 20 20 20 2a r stream.. *
3080: 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 21 28 /.. return !(
3090: 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 strstr(Out.buffe
30a0: 72 2c 20 22 4c 4e 4b 31 31 31 37 22 29 20 21 3d r, "LNK1117") !=
30b0: 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 73 74 NULL ||.. st
30c0: 72 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c rstr(Err.buffer,
30d0: 20 22 4c 4e 4b 31 31 31 37 22 29 20 21 3d 20 4e "LNK1117") != N
30e0: 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 73 74 72 73 ULL ||.. strs
30f0: 74 72 28 4f 75 74 2e 62 75 66 66 65 72 2c 20 22 tr(Out.buffer, "
3100: 4c 4e 4b 34 30 34 34 22 29 20 21 3d 20 4e 55 4c LNK4044") != NUL
3110: 4c 20 7c 7c 0a 09 20 20 20 20 73 74 72 73 74 72 L ||.. strstr
3120: 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 4c 4e (Err.buffer, "LN
3130: 4b 34 30 34 34 22 29 20 21 3d 20 4e 55 4c 4c 20 K4044") != NULL
3140: 7c 7c 0a 09 20 20 20 20 73 74 72 73 74 72 28 4f ||.. strstr(O
3150: 75 74 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 34 ut.buffer, "LNK4
3160: 32 32 34 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 224") != NULL ||
3170: 0a 09 20 20 20 20 73 74 72 73 74 72 28 45 72 72 .. strstr(Err
3180: 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 34 32 32 .buffer, "LNK422
3190: 34 22 29 20 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 4") != NULL);.}.
31a0: 0c 0a 73 74 61 74 69 63 20 44 57 4f 52 44 20 57 ..static DWORD W
31b0: 49 4e 41 50 49 0a 52 65 61 64 46 72 6f 6d 50 69 INAPI.ReadFromPi
31c0: 70 65 28 0a 20 20 20 20 4c 50 56 4f 49 44 20 61 pe(. LPVOID a
31d0: 72 67 73 29 0a 7b 0a 20 20 20 20 70 69 70 65 69 rgs).{. pipei
31e0: 6e 66 6f 20 2a 70 69 20 3d 20 28 70 69 70 65 69 nfo *pi = (pipei
31f0: 6e 66 6f 20 2a 29 20 61 72 67 73 3b 0a 20 20 20 nfo *) args;.
3200: 20 63 68 61 72 20 2a 6c 61 73 74 42 75 66 20 3d char *lastBuf =
3210: 20 70 69 2d 3e 62 75 66 66 65 72 3b 0a 20 20 20 pi->buffer;.
3220: 20 44 57 4f 52 44 20 64 77 52 65 61 64 3b 0a 20 DWORD dwRead;.
3230: 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 0a 20 20 61 BOOL ok;.. a
3240: 67 61 69 6e 3a 0a 20 20 20 20 69 66 20 28 6c 61 gain:. if (la
3250: 73 74 42 75 66 20 2d 20 70 69 2d 3e 62 75 66 66 stBuf - pi->buff
3260: 65 72 20 2b 20 43 48 55 4e 4b 20 3e 20 53 54 41 er + CHUNK > STA
3270: 54 49 43 42 55 46 46 45 52 53 49 5a 45 29 20 7b TICBUFFERSIZE) {
3280: 0a 09 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 ..CloseHandle(pi
3290: 2d 3e 70 69 70 65 29 3b 0a 09 72 65 74 75 72 6e ->pipe);..return
32a0: 20 28 44 57 4f 52 44 29 2d 31 3b 0a 20 20 20 20 (DWORD)-1;.
32b0: 7d 0a 20 20 20 20 6f 6b 20 3d 20 52 65 61 64 46 }. ok = ReadF
32c0: 69 6c 65 28 70 69 2d 3e 70 69 70 65 2c 20 6c 61 ile(pi->pipe, la
32d0: 73 74 42 75 66 2c 20 43 48 55 4e 4b 2c 20 26 64 stBuf, CHUNK, &d
32e0: 77 52 65 61 64 2c 20 30 4c 29 3b 0a 20 20 20 20 wRead, 0L);.
32f0: 69 66 20 28 21 6f 6b 20 7c 7c 20 64 77 52 65 61 if (!ok || dwRea
3300: 64 20 3d 3d 20 30 29 20 7b 0a 09 43 6c 6f 73 65 d == 0) {..Close
3310: 48 61 6e 64 6c 65 28 70 69 2d 3e 70 69 70 65 29 Handle(pi->pipe)
3320: 3b 0a 09 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 ;..return 0;.
3330: 20 7d 0a 20 20 20 20 6c 61 73 74 42 75 66 20 2b }. lastBuf +
3340: 3d 20 64 77 52 65 61 64 3b 0a 20 20 20 20 67 6f = dwRead;. go
3350: 74 6f 20 61 67 61 69 6e 3b 0a 0a 20 20 20 20 72 to again;.. r
3360: 65 74 75 72 6e 20 30 3b 20 20 2f 2a 20 6d 61 6b eturn 0; /* mak
3370: 65 73 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 es the compiler
3380: 68 61 70 70 79 20 2a 2f 0a 7d 0a 0c 0a 73 74 61 happy */.}...sta
3390: 74 69 63 20 69 6e 74 0a 49 73 49 6e 28 0a 20 20 tic int.IsIn(.
33a0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 const char *st
33b0: 72 69 6e 67 2c 0a 20 20 20 20 63 6f 6e 73 74 20 ring,. const
33c0: 63 68 61 72 20 2a 73 75 62 73 74 72 69 6e 67 29 char *substring)
33d0: 0a 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 28 73 .{. return (s
33e0: 74 72 73 74 72 28 73 74 72 69 6e 67 2c 20 73 75 trstr(string, su
33f0: 62 73 74 72 69 6e 67 29 20 21 3d 20 4e 55 4c 4c bstring) != NULL
3400: 29 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74 );.}.../*. * Get
3410: 56 65 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 20 VersionFromFile
3420: 2d 2d 0a 20 2a 20 09 4c 6f 6f 6b 73 20 66 6f 72 --. * .Looks for
3430: 20 61 20 6d 61 74 63 68 20 73 74 72 69 6e 67 20 a match string
3440: 69 6e 20 61 20 66 69 6c 65 20 61 6e 64 20 74 68 in a file and th
3450: 65 6e 20 72 65 74 75 72 6e 73 20 74 68 65 20 76 en returns the v
3460: 65 72 73 69 6f 6e 0a 20 2a 20 09 66 6f 6c 6c 6f ersion. * .follo
3470: 77 69 6e 67 20 74 68 65 20 6d 61 74 63 68 20 77 wing the match w
3480: 68 65 72 65 20 61 20 76 65 72 73 69 6f 6e 20 69 here a version i
3490: 73 20 61 6e 79 74 68 69 6e 67 20 61 63 63 65 70 s anything accep
34a0: 74 61 62 6c 65 20 74 6f 0a 20 2a 20 09 70 61 63 table to. * .pac
34b0: 6b 61 67 65 20 70 72 6f 76 69 64 65 20 6f 72 20 kage provide or
34c0: 70 61 63 6b 61 67 65 20 69 66 6e 65 65 64 65 64 package ifneeded
34d0: 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 63 6f .. */..static co
34e0: 6e 73 74 20 63 68 61 72 20 2a 0a 47 65 74 56 65 nst char *.GetVe
34f0: 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 0a 20 rsionFromFile(.
3500: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 const char *f
3510: 69 6c 65 6e 61 6d 65 2c 0a 20 20 20 20 63 6f 6e ilename,. con
3520: 73 74 20 63 68 61 72 20 2a 6d 61 74 63 68 2c 0a st char *match,.
3530: 20 20 20 20 69 6e 74 20 6e 75 6d 64 6f 74 73 29 int numdots)
3540: 0a 7b 0a 20 20 20 20 73 74 61 74 69 63 20 63 68 .{. static ch
3550: 61 72 20 73 7a 42 75 66 66 65 72 5b 31 30 30 5d ar szBuffer[100]
3560: 3b 0a 20 20 20 20 63 68 61 72 20 2a 73 7a 52 65 ;. char *szRe
3570: 73 75 6c 74 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 sult = NULL;.
3580: 20 46 49 4c 45 20 2a 66 70 20 3d 20 66 6f 70 65 FILE *fp = fope
3590: 6e 28 66 69 6c 65 6e 61 6d 65 2c 20 22 72 74 22 n(filename, "rt"
35a0: 29 3b 0a 0a 20 20 20 20 69 66 20 28 66 70 20 21 );.. if (fp !
35b0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 2f 2a 0a 09 20 = NULL) {../*..
35c0: 2a 20 52 65 61 64 20 64 61 74 61 20 75 6e 74 69 * Read data unti
35d0: 6c 20 77 65 20 73 65 65 20 6f 75 72 20 6d 61 74 l we see our mat
35e0: 63 68 20 73 74 72 69 6e 67 2e 0a 09 20 2a 2f 0a ch string... */.
35f0: 0a 09 77 68 69 6c 65 20 28 66 67 65 74 73 28 73 ..while (fgets(s
3600: 7a 42 75 66 66 65 72 2c 20 73 69 7a 65 6f 66 28 zBuffer, sizeof(
3610: 73 7a 42 75 66 66 65 72 29 2c 20 66 70 29 20 21 szBuffer), fp) !
3620: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 4c = NULL) {.. L
3630: 50 53 54 52 20 70 2c 20 71 3b 0a 0a 09 20 20 20 PSTR p, q;...
3640: 20 70 20 3d 20 73 74 72 73 74 72 28 73 7a 42 75 p = strstr(szBu
3650: 66 66 65 72 2c 20 6d 61 74 63 68 29 3b 0a 09 20 ffer, match);..
3660: 20 20 20 69 66 20 28 70 20 21 3d 20 4e 55 4c 4c if (p != NULL
3670: 29 20 7b 0a 09 09 2f 2a 0a 09 09 20 2a 20 53 6b ) {.../*... * Sk
3680: 69 70 20 74 6f 20 66 69 72 73 74 20 64 69 67 69 ip to first digi
3690: 74 20 61 66 74 65 72 20 74 68 65 20 6d 61 74 63 t after the matc
36a0: 68 2e 0a 09 09 20 2a 2f 0a 0a 09 09 70 20 2b 3d h.... */....p +=
36b0: 20 73 74 72 6c 65 6e 28 6d 61 74 63 68 29 3b 0a strlen(match);.
36c0: 09 09 77 68 69 6c 65 20 28 2a 70 20 26 26 20 21 ..while (*p && !
36d0: 69 73 64 69 67 69 74 28 28 75 6e 73 69 67 6e 65 isdigit((unsigne
36e0: 64 20 63 68 61 72 29 2a 70 29 29 20 7b 0a 09 09 d char)*p)) {...
36f0: 20 20 20 20 2b 2b 70 3b 0a 09 09 7d 0a 0a 09 09 ++p;...}....
3700: 2f 2a 0a 09 09 20 2a 20 46 69 6e 64 20 65 6e 64 /*... * Find end
3710: 69 6e 67 20 77 68 69 74 65 73 70 61 63 65 2e 0a ing whitespace..
3720: 09 09 20 2a 2f 0a 0a 09 09 71 20 3d 20 70 3b 0a .. */....q = p;.
3730: 09 09 77 68 69 6c 65 20 28 2a 71 20 26 26 20 28 ..while (*q && (
3740: 73 74 72 63 68 72 28 22 30 31 32 33 34 35 36 37 strchr("01234567
3750: 38 39 2e 61 62 22 2c 20 2a 71 29 29 20 26 26 20 89.ab", *q)) &&
3760: 28 28 28 21 73 74 72 63 68 72 28 22 2e 61 62 22 (((!strchr(".ab"
3770: 2c 20 2a 71 29 0a 09 09 09 20 20 20 20 26 26 20 , *q).... &&
3780: 21 73 74 72 63 68 72 28 22 61 62 22 2c 20 71 5b !strchr("ab", q[
3790: 2d 31 5d 29 29 20 7c 7c 20 2d 2d 6e 75 6d 64 6f -1])) || --numdo
37a0: 74 73 29 29 29 20 7b 0a 09 09 20 20 20 20 2b 2b ts))) {... ++
37b0: 71 3b 0a 09 09 7d 0a 0a 09 09 2a 71 20 3d 20 30 q;...}....*q = 0
37c0: 3b 0a 09 09 73 7a 52 65 73 75 6c 74 20 3d 20 70 ;...szResult = p
37d0: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 20 20 20 20 ;...break;..
37e0: 7d 0a 09 7d 0a 09 66 63 6c 6f 73 65 28 66 70 29 }..}..fclose(fp)
37f0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 ;. }. retu
3800: 72 6e 20 73 7a 52 65 73 75 6c 74 3b 0a 7d 0a 0c rn szResult;.}..
3810: 0a 2f 2a 0a 20 2a 20 4c 69 73 74 20 68 65 6c 70 ./*. * List help
3820: 65 72 73 20 66 6f 72 20 74 68 65 20 53 75 62 73 ers for the Subs
3830: 74 69 74 75 74 65 46 69 6c 65 20 66 75 6e 63 74 tituteFile funct
3840: 69 6f 6e 0a 20 2a 2f 0a 0a 74 79 70 65 64 65 66 ion. */..typedef
3850: 20 73 74 72 75 63 74 20 6c 69 73 74 5f 69 74 65 struct list_ite
3860: 6d 5f 74 20 7b 0a 20 20 20 20 73 74 72 75 63 74 m_t {. struct
3870: 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 6e 65 list_item_t *ne
3880: 78 74 50 74 72 3b 0a 20 20 20 20 63 68 61 72 20 xtPtr;. char
3890: 2a 20 6b 65 79 3b 0a 20 20 20 20 63 68 61 72 20 * key;. char
38a0: 2a 20 76 61 6c 75 65 3b 0a 7d 20 6c 69 73 74 5f * value;.} list_
38b0: 69 74 65 6d 5f 74 3b 0a 0a 2f 2a 20 69 6e 73 65 item_t;../* inse
38c0: 72 74 20 61 20 6c 69 73 74 20 69 74 65 6d 20 69 rt a list item i
38d0: 6e 74 6f 20 74 68 65 20 6c 69 73 74 20 28 6c 69 nto the list (li
38e0: 73 74 20 6d 61 79 20 62 65 20 6e 75 6c 6c 29 20 st may be null)
38f0: 2a 2f 0a 73 74 61 74 69 63 20 6c 69 73 74 5f 69 */.static list_i
3900: 74 65 6d 5f 74 20 2a 0a 6c 69 73 74 5f 69 6e 73 tem_t *.list_ins
3910: 65 72 74 28 6c 69 73 74 5f 69 74 65 6d 5f 74 20 ert(list_item_t
3920: 2a 2a 6c 69 73 74 50 74 72 50 74 72 2c 20 63 6f **listPtrPtr, co
3930: 6e 73 74 20 63 68 61 72 20 2a 6b 65 79 2c 20 63 nst char *key, c
3940: 6f 6e 73 74 20 63 68 61 72 20 2a 76 61 6c 75 65 onst char *value
3950: 29 0a 7b 0a 20 20 20 20 6c 69 73 74 5f 69 74 65 ).{. list_ite
3960: 6d 5f 74 20 2a 69 74 65 6d 50 74 72 20 3d 20 28 m_t *itemPtr = (
3970: 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 29 6d 61 list_item_t *)ma
3980: 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 6c 69 73 74 lloc(sizeof(list
3990: 5f 69 74 65 6d 5f 74 29 29 3b 0a 20 20 20 20 69 _item_t));. i
39a0: 66 20 28 69 74 65 6d 50 74 72 29 20 7b 0a 09 69 f (itemPtr) {..i
39b0: 74 65 6d 50 74 72 2d 3e 6b 65 79 20 3d 20 73 74 temPtr->key = st
39c0: 72 64 75 70 28 6b 65 79 29 3b 0a 09 69 74 65 6d rdup(key);..item
39d0: 50 74 72 2d 3e 76 61 6c 75 65 20 3d 20 73 74 72 Ptr->value = str
39e0: 64 75 70 28 76 61 6c 75 65 29 3b 0a 09 69 74 65 dup(value);..ite
39f0: 6d 50 74 72 2d 3e 6e 65 78 74 50 74 72 20 3d 20 mPtr->nextPtr =
3a00: 4e 55 4c 4c 3b 0a 0a 09 77 68 69 6c 65 28 2a 6c NULL;...while(*l
3a10: 69 73 74 50 74 72 50 74 72 29 20 7b 0a 09 20 20 istPtrPtr) {..
3a20: 20 20 6c 69 73 74 50 74 72 50 74 72 20 3d 20 26 listPtrPtr = &
3a30: 28 2a 6c 69 73 74 50 74 72 50 74 72 29 2d 3e 6e (*listPtrPtr)->n
3a40: 65 78 74 50 74 72 3b 0a 09 7d 0a 09 2a 6c 69 73 extPtr;..}..*lis
3a50: 74 50 74 72 50 74 72 20 3d 20 69 74 65 6d 50 74 tPtrPtr = itemPt
3a60: 72 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 r;. }. ret
3a70: 75 72 6e 20 69 74 65 6d 50 74 72 3b 0a 7d 0a 0a urn itemPtr;.}..
3a80: 73 74 61 74 69 63 20 76 6f 69 64 0a 6c 69 73 74 static void.list
3a90: 5f 66 72 65 65 28 6c 69 73 74 5f 69 74 65 6d 5f _free(list_item_
3aa0: 74 20 2a 2a 6c 69 73 74 50 74 72 50 74 72 29 0a t **listPtrPtr).
3ab0: 7b 0a 20 20 20 20 6c 69 73 74 5f 69 74 65 6d 5f {. list_item_
3ac0: 74 20 2a 74 6d 70 50 74 72 2c 20 2a 6c 69 73 74 t *tmpPtr, *list
3ad0: 50 74 72 20 3d 20 2a 6c 69 73 74 50 74 72 50 74 Ptr = *listPtrPt
3ae0: 72 3b 0a 20 20 20 20 77 68 69 6c 65 20 28 6c 69 r;. while (li
3af0: 73 74 50 74 72 29 20 7b 0a 09 74 6d 70 50 74 72 stPtr) {..tmpPtr
3b00: 20 3d 20 6c 69 73 74 50 74 72 3b 0a 09 6c 69 73 = listPtr;..lis
3b10: 74 50 74 72 20 3d 20 6c 69 73 74 50 74 72 2d 3e tPtr = listPtr->
3b20: 6e 65 78 74 50 74 72 3b 0a 09 66 72 65 65 28 74 nextPtr;..free(t
3b30: 6d 70 50 74 72 2d 3e 6b 65 79 29 3b 0a 09 66 72 mpPtr->key);..fr
3b40: 65 65 28 74 6d 70 50 74 72 2d 3e 76 61 6c 75 65 ee(tmpPtr->value
3b50: 29 3b 0a 09 66 72 65 65 28 74 6d 70 50 74 72 29 );..free(tmpPtr)
3b60: 3b 0a 20 20 20 20 7d 0a 7d 0a 0c 0a 2f 2a 0a 20 ;. }.}.../*.
3b70: 2a 20 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 * SubstituteFile
3b80: 20 2d 2d 0a 20 2a 09 41 73 20 77 69 6e 64 6f 77 --. *.As window
3b90: 73 20 64 6f 65 73 6e 27 74 20 70 72 6f 76 69 64 s doesn't provid
3ba0: 65 20 61 6e 79 74 68 69 6e 67 20 75 73 65 66 75 e anything usefu
3bb0: 6c 20 6c 69 6b 65 20 73 65 64 20 61 6e 64 20 69 l like sed and i
3bc0: 74 27 73 20 75 6e 72 65 6c 69 61 62 6c 65 0a 20 t's unreliable.
3bd0: 2a 09 74 6f 20 75 73 65 20 74 68 65 20 74 63 6c *.to use the tcl
3be0: 73 68 20 79 6f 75 20 61 72 65 20 62 75 69 6c 64 sh you are build
3bf0: 69 6e 67 20 61 67 61 69 6e 73 74 20 28 63 6f 6e ing against (con
3c00: 73 69 64 65 72 20 78 2d 70 6c 61 74 66 6f 72 6d sider x-platform
3c10: 20 62 75 69 6c 64 73 20 2d 0a 20 2a 09 65 2e 67 builds -. *.e.g
3c20: 2e 20 63 6f 6d 70 69 6c 69 6e 67 20 41 4d 44 36 . compiling AMD6
3c30: 34 20 74 61 72 67 65 74 20 66 72 6f 6d 20 49 58 4 target from IX
3c40: 38 36 29 20 77 65 20 70 72 6f 76 69 64 65 20 61 86) we provide a
3c50: 20 73 69 6d 70 6c 65 20 73 75 62 73 74 69 74 75 simple substitu
3c60: 74 69 6f 6e 0a 20 2a 09 6f 70 74 69 6f 6e 20 68 tion. *.option h
3c70: 65 72 65 20 74 6f 20 68 61 6e 64 6c 65 20 61 75 ere to handle au
3c80: 74 6f 63 6f 6e 66 20 73 74 79 6c 65 20 73 75 62 toconf style sub
3c90: 73 74 69 74 75 74 69 6f 6e 73 2e 0a 20 2a 09 54 stitutions.. *.T
3ca0: 68 65 20 73 75 62 73 74 69 74 75 74 69 6f 6e 20 he substitution
3cb0: 66 69 6c 65 20 69 73 20 77 68 69 74 65 73 70 61 file is whitespa
3cc0: 63 65 20 61 6e 64 20 6c 69 6e 65 20 64 65 6c 69 ce and line deli
3cd0: 6d 69 74 65 64 2e 20 54 68 65 20 66 69 6c 65 20 mited. The file
3ce0: 73 68 6f 75 6c 64 0a 20 2a 09 63 6f 6e 73 69 73 should. *.consis
3cf0: 74 20 6f 66 20 6c 69 6e 65 73 20 6d 61 74 63 68 t of lines match
3d00: 69 6e 67 20 74 68 65 20 72 65 67 75 6c 61 72 20 ing the regular
3d10: 65 78 70 72 65 73 73 69 6f 6e 3a 0a 20 2a 09 20 expression:. *.
3d20: 20 5c 73 2a 5c 53 2b 5c 73 2b 5c 53 2a 24 0a 20 \s*\S+\s+\S*$.
3d30: 2a 0a 20 2a 09 55 73 61 67 65 20 69 73 20 73 6f *. *.Usage is so
3d40: 6d 65 74 68 69 6e 67 20 6c 69 6b 65 3a 0a 20 2a mething like:. *
3d50: 09 20 20 6e 6d 61 6b 65 68 6c 70 20 2d 53 20 3c . nmakehlp -S <
3d60: 3c 20 24 2a 2a 20 3e 20 24 40 0a 20 2a 20 20 20 < $** > $@. *
3d70: 20 20 20 20 20 40 50 41 43 4b 41 47 45 5f 4e 41 @PACKAGE_NA
3d80: 4d 45 40 20 24 28 50 41 43 4b 41 47 45 5f 4e 41 ME@ $(PACKAGE_NA
3d90: 4d 45 29 0a 20 2a 20 20 20 20 20 20 20 20 40 50 ME). * @P
3da0: 41 43 4b 41 47 45 5f 56 45 52 53 49 4f 4e 40 20 ACKAGE_VERSION@
3db0: 24 28 50 41 43 4b 41 47 45 5f 56 45 52 53 49 4f $(PACKAGE_VERSIO
3dc0: 4e 29 0a 20 2a 20 20 20 20 20 20 20 20 3c 3c 0a N). * <<.
3dd0: 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a */..static int.
3de0: 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 28 0a SubstituteFile(.
3df0: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a const char *
3e00: 73 75 62 73 74 69 74 75 74 69 6f 6e 73 2c 0a 20 substitutions,.
3e10: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 const char *f
3e20: 69 6c 65 6e 61 6d 65 29 0a 7b 0a 20 20 20 20 73 ilename).{. s
3e30: 74 61 74 69 63 20 63 68 61 72 20 73 7a 42 75 66 tatic char szBuf
3e40: 66 65 72 5b 31 30 32 34 5d 2c 20 73 7a 43 6f 70 fer[1024], szCop
3e50: 79 5b 31 30 32 34 5d 3b 0a 20 20 20 20 6c 69 73 y[1024];. lis
3e60: 74 5f 69 74 65 6d 5f 74 20 2a 73 75 62 73 74 50 t_item_t *substP
3e70: 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 46 tr = NULL;. F
3e80: 49 4c 45 20 2a 66 70 2c 20 2a 73 70 3b 0a 0a 20 ILE *fp, *sp;..
3e90: 20 20 20 66 70 20 3d 20 66 6f 70 65 6e 28 66 69 fp = fopen(fi
3ea0: 6c 65 6e 61 6d 65 2c 20 22 72 74 22 29 3b 0a 20 lename, "rt");.
3eb0: 20 20 20 69 66 20 28 66 70 20 21 3d 20 4e 55 4c if (fp != NUL
3ec0: 4c 29 20 7b 0a 0a 09 2f 2a 0a 09 20 2a 20 42 75 L) {.../*.. * Bu
3ed0: 69 6c 64 20 61 20 6c 69 73 74 20 6f 66 20 73 75 ild a list of su
3ee0: 62 73 74 69 74 75 74 69 6f 6e 73 20 66 72 6f 6d bstitutions from
3ef0: 20 74 68 65 20 66 69 72 73 74 20 66 69 6c 65 6e the first filen
3f00: 61 6d 65 0a 09 20 2a 2f 0a 0a 09 73 70 20 3d 20 ame.. */...sp =
3f10: 66 6f 70 65 6e 28 73 75 62 73 74 69 74 75 74 69 fopen(substituti
3f20: 6f 6e 73 2c 20 22 72 74 22 29 3b 0a 09 69 66 20 ons, "rt");..if
3f30: 28 73 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 (sp != NULL) {..
3f40: 20 20 20 20 77 68 69 6c 65 20 28 66 67 65 74 73 while (fgets
3f50: 28 73 7a 42 75 66 66 65 72 2c 20 73 69 7a 65 6f (szBuffer, sizeo
3f60: 66 28 73 7a 42 75 66 66 65 72 29 2c 20 73 70 29 f(szBuffer), sp)
3f70: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 75 6e != NULL) {...un
3f80: 73 69 67 6e 65 64 20 63 68 61 72 20 2a 6b 73 2c signed char *ks,
3f90: 20 2a 6b 65 2c 20 2a 76 73 2c 20 2a 76 65 3b 0a *ke, *vs, *ve;.
3fa0: 09 09 6b 73 20 3d 20 28 75 6e 73 69 67 6e 65 64 ..ks = (unsigned
3fb0: 20 63 68 61 72 2a 29 73 7a 42 75 66 66 65 72 3b char*)szBuffer;
3fc0: 0a 09 09 77 68 69 6c 65 20 28 6b 73 20 26 26 20 ...while (ks &&
3fd0: 2a 6b 73 20 26 26 20 69 73 73 70 61 63 65 28 2a *ks && isspace(*
3fe0: 6b 73 29 29 20 2b 2b 6b 73 3b 0a 09 09 6b 65 20 ks)) ++ks;...ke
3ff0: 3d 20 6b 73 3b 0a 09 09 77 68 69 6c 65 20 28 6b = ks;...while (k
4000: 65 20 26 26 20 2a 6b 65 20 26 26 20 21 69 73 73 e && *ke && !iss
4010: 70 61 63 65 28 2a 6b 65 29 29 20 2b 2b 6b 65 3b pace(*ke)) ++ke;
4020: 0a 09 09 76 73 20 3d 20 6b 65 3b 0a 09 09 77 68 ...vs = ke;...wh
4030: 69 6c 65 20 28 76 73 20 26 26 20 2a 76 73 20 26 ile (vs && *vs &
4040: 26 20 69 73 73 70 61 63 65 28 2a 76 73 29 29 20 & isspace(*vs))
4050: 2b 2b 76 73 3b 0a 09 09 76 65 20 3d 20 76 73 3b ++vs;...ve = vs;
4060: 0a 09 09 77 68 69 6c 65 20 28 76 65 20 26 26 20 ...while (ve &&
4070: 2a 76 65 20 26 26 20 21 28 2a 76 65 20 3d 3d 20 *ve && !(*ve ==
4080: 27 5c 72 27 20 7c 7c 20 2a 76 65 20 3d 3d 20 27 '\r' || *ve == '
4090: 5c 6e 27 29 29 20 2b 2b 76 65 3b 0a 09 09 2a 6b \n')) ++ve;...*k
40a0: 65 20 3d 20 30 2c 20 2a 76 65 20 3d 20 30 3b 0a e = 0, *ve = 0;.
40b0: 09 09 6c 69 73 74 5f 69 6e 73 65 72 74 28 26 73 ..list_insert(&s
40c0: 75 62 73 74 50 74 72 2c 20 28 63 68 61 72 2a 29 ubstPtr, (char*)
40d0: 6b 73 2c 20 28 63 68 61 72 2a 29 76 73 29 3b 0a ks, (char*)vs);.
40e0: 09 20 20 20 20 7d 0a 09 20 20 20 20 66 63 6c 6f . }.. fclo
40f0: 73 65 28 73 70 29 3b 0a 09 7d 0a 0a 09 2f 2a 20 se(sp);..}.../*
4100: 64 65 62 75 67 3a 20 64 75 6d 70 20 74 68 65 20 debug: dump the
4110: 6c 69 73 74 20 2a 2f 0a 23 69 66 6e 64 65 66 20 list */.#ifndef
4120: 4e 44 45 42 55 47 0a 09 7b 0a 09 20 20 20 20 69 NDEBUG..{.. i
4130: 6e 74 20 6e 20 3d 20 30 3b 0a 09 20 20 20 20 6c nt n = 0;.. l
4140: 69 73 74 5f 69 74 65 6d 5f 74 20 2a 70 20 3d 20 ist_item_t *p =
4150: 4e 55 4c 4c 3b 0a 09 20 20 20 20 66 6f 72 20 28 NULL;.. for (
4160: 70 20 3d 20 73 75 62 73 74 50 74 72 3b 20 70 20 p = substPtr; p
4170: 21 3d 20 4e 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e != NULL; p = p->
4180: 6e 65 78 74 50 74 72 2c 20 2b 2b 6e 29 20 7b 0a nextPtr, ++n) {.
4190: 09 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 ..fprintf(stderr
41a0: 2c 20 22 25 20 33 64 20 27 25 73 27 20 3d 3e 20 , "% 3d '%s' =>
41b0: 27 25 73 27 5c 6e 22 2c 20 6e 2c 20 70 2d 3e 6b '%s'\n", n, p->k
41c0: 65 79 2c 20 70 2d 3e 76 61 6c 75 65 29 3b 0a 09 ey, p->value);..
41d0: 20 20 20 20 7d 0a 09 7d 0a 23 65 6e 64 69 66 0a }..}.#endif.
41e0: 0a 09 2f 2a 0a 09 20 2a 20 52 75 6e 20 74 68 65 ../*.. * Run the
41f0: 20 73 75 62 73 74 69 74 75 74 69 6f 6e 73 20 6f substitutions o
4200: 76 65 72 20 65 61 63 68 20 6c 69 6e 65 20 6f 66 ver each line of
4210: 20 74 68 65 20 69 6e 70 75 74 0a 09 20 2a 2f 0a the input.. */.
4220: 0a 09 77 68 69 6c 65 20 28 66 67 65 74 73 28 73 ..while (fgets(s
4230: 7a 42 75 66 66 65 72 2c 20 73 69 7a 65 6f 66 28 zBuffer, sizeof(
4240: 73 7a 42 75 66 66 65 72 29 2c 20 66 70 29 20 21 szBuffer), fp) !
4250: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 6c = NULL) {.. l
4260: 69 73 74 5f 69 74 65 6d 5f 74 20 2a 70 20 3d 20 ist_item_t *p =
4270: 4e 55 4c 4c 3b 0a 09 20 20 20 20 66 6f 72 20 28 NULL;.. for (
4280: 70 20 3d 20 73 75 62 73 74 50 74 72 3b 20 70 20 p = substPtr; p
4290: 21 3d 20 4e 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e != NULL; p = p->
42a0: 6e 65 78 74 50 74 72 29 20 7b 0a 09 09 63 68 61 nextPtr) {...cha
42b0: 72 20 2a 6d 20 3d 20 73 74 72 73 74 72 28 73 7a r *m = strstr(sz
42c0: 42 75 66 66 65 72 2c 20 70 2d 3e 6b 65 79 29 3b Buffer, p->key);
42d0: 0a 09 09 69 66 20 28 6d 29 20 7b 0a 09 09 20 20 ...if (m) {...
42e0: 20 20 63 68 61 72 20 2a 63 70 2c 20 2a 6f 70 2c char *cp, *op,
42f0: 20 2a 73 70 3b 0a 09 09 20 20 20 20 63 70 20 3d *sp;... cp =
4300: 20 73 7a 43 6f 70 79 3b 0a 09 09 20 20 20 20 6f szCopy;... o
4310: 70 20 3d 20 73 7a 42 75 66 66 65 72 3b 0a 09 09 p = szBuffer;...
4320: 20 20 20 20 77 68 69 6c 65 20 28 6f 70 20 21 3d while (op !=
4330: 20 6d 29 20 2a 63 70 2b 2b 20 3d 20 2a 6f 70 2b m) *cp++ = *op+
4340: 2b 3b 0a 09 09 20 20 20 20 73 70 20 3d 20 70 2d +;... sp = p-
4350: 3e 76 61 6c 75 65 3b 0a 09 09 20 20 20 20 77 68 >value;... wh
4360: 69 6c 65 20 28 73 70 20 26 26 20 2a 73 70 29 20 ile (sp && *sp)
4370: 2a 63 70 2b 2b 20 3d 20 2a 73 70 2b 2b 3b 0a 09 *cp++ = *sp++;..
4380: 09 20 20 20 20 6f 70 20 2b 3d 20 73 74 72 6c 65 . op += strle
4390: 6e 28 70 2d 3e 6b 65 79 29 3b 0a 09 09 20 20 20 n(p->key);...
43a0: 20 77 68 69 6c 65 20 28 2a 6f 70 29 20 2a 63 70 while (*op) *cp
43b0: 2b 2b 20 3d 20 2a 6f 70 2b 2b 3b 0a 09 09 20 20 ++ = *op++;...
43c0: 20 20 2a 63 70 20 3d 20 30 3b 0a 09 09 20 20 20 *cp = 0;...
43d0: 20 6d 65 6d 63 70 79 28 73 7a 42 75 66 66 65 72 memcpy(szBuffer
43e0: 2c 20 73 7a 43 6f 70 79 2c 20 73 69 7a 65 6f 66 , szCopy, sizeof
43f0: 28 73 7a 43 6f 70 79 29 29 3b 0a 09 09 7d 0a 09 (szCopy));...}..
4400: 20 20 20 20 7d 0a 09 20 20 20 20 70 72 69 6e 74 }.. print
4410: 66 28 22 25 73 22 2c 20 73 7a 42 75 66 66 65 72 f("%s", szBuffer
4420: 29 3b 0a 09 7d 0a 0a 09 6c 69 73 74 5f 66 72 65 );..}...list_fre
4430: 65 28 26 73 75 62 73 74 50 74 72 29 3b 0a 20 20 e(&substPtr);.
4440: 20 20 7d 0a 20 20 20 20 66 63 6c 6f 73 65 28 66 }. fclose(f
4450: 70 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 p);. return 0
4460: 3b 0a 7d 0a 0c 0a 42 4f 4f 4c 20 46 69 6c 65 45 ;.}...BOOL FileE
4470: 78 69 73 74 73 28 4c 50 43 54 53 54 52 20 73 7a xists(LPCTSTR sz
4480: 50 61 74 68 29 0a 7b 0a 23 69 66 6e 64 65 66 20 Path).{.#ifndef
4490: 49 4e 56 41 4c 49 44 5f 46 49 4c 45 5f 41 54 54 INVALID_FILE_ATT
44a0: 52 49 42 55 54 45 53 0a 20 20 20 20 23 64 65 66 RIBUTES. #def
44b0: 69 6e 65 20 49 4e 56 41 4c 49 44 5f 46 49 4c 45 ine INVALID_FILE
44c0: 5f 41 54 54 52 49 42 55 54 45 53 20 28 28 44 57 _ATTRIBUTES ((DW
44d0: 4f 52 44 29 2d 31 29 0a 23 65 6e 64 69 66 0a 20 ORD)-1).#endif.
44e0: 20 20 20 44 57 4f 52 44 20 70 61 74 68 41 74 74 DWORD pathAtt
44f0: 72 20 3d 20 47 65 74 46 69 6c 65 41 74 74 72 69 r = GetFileAttri
4500: 62 75 74 65 73 28 73 7a 50 61 74 68 29 3b 0a 20 butes(szPath);.
4510: 20 20 20 72 65 74 75 72 6e 20 28 70 61 74 68 41 return (pathA
4520: 74 74 72 20 21 3d 20 49 4e 56 41 4c 49 44 5f 46 ttr != INVALID_F
4530: 49 4c 45 5f 41 54 54 52 49 42 55 54 45 53 20 26 ILE_ATTRIBUTES &
4540: 26 0a 09 20 20 20 20 21 28 70 61 74 68 41 74 74 &.. !(pathAtt
4550: 72 20 26 20 46 49 4c 45 5f 41 54 54 52 49 42 55 r & FILE_ATTRIBU
4560: 54 45 5f 44 49 52 45 43 54 4f 52 59 29 29 3b 0a TE_DIRECTORY));.
4570: 7d 0a 0c 0a 0a 2f 2a 0a 20 2a 20 51 75 61 6c 69 }..../*. * Quali
4580: 66 79 50 61 74 68 20 2d 2d 0a 20 2a 0a 20 2a 09 fyPath --. *. *.
4590: 54 68 69 73 20 63 6f 6d 70 6f 73 65 73 20 74 68 This composes th
45a0: 65 20 63 75 72 72 65 6e 74 20 77 6f 72 6b 69 6e e current workin
45b0: 67 20 64 69 72 65 63 74 6f 72 79 20 77 69 74 68 g directory with
45c0: 20 61 20 70 72 6f 76 69 64 65 64 20 70 61 74 68 a provided path
45d0: 0a 20 2a 09 61 6e 64 20 72 65 74 75 72 6e 73 20 . *.and returns
45e0: 74 68 65 20 66 75 6c 6c 79 20 71 75 61 6c 69 66 the fully qualif
45f0: 69 65 64 20 61 6e 64 20 6e 6f 72 6d 61 6c 69 7a ied and normaliz
4600: 65 64 20 70 61 74 68 2e 0a 20 2a 09 4d 6f 73 74 ed path.. *.Most
4610: 6c 79 20 6e 65 65 64 65 64 20 74 6f 20 73 65 74 ly needed to set
4620: 75 70 20 70 61 74 68 73 20 66 6f 72 20 74 65 73 up paths for tes
4630: 74 69 6e 67 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 ting.. */..stati
4640: 63 20 69 6e 74 0a 51 75 61 6c 69 66 79 50 61 74 c int.QualifyPat
4650: 68 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 h(. const cha
4660: 72 20 2a 73 7a 50 61 74 68 29 0a 7b 0a 20 20 20 r *szPath).{.
4670: 20 63 68 61 72 20 73 7a 43 77 64 5b 4d 41 58 5f char szCwd[MAX_
4680: 50 41 54 48 20 2b 20 31 5d 3b 0a 0a 20 20 20 20 PATH + 1];..
4690: 47 65 74 46 75 6c 6c 50 61 74 68 4e 61 6d 65 28 GetFullPathName(
46a0: 73 7a 50 61 74 68 2c 20 73 69 7a 65 6f 66 28 73 szPath, sizeof(s
46b0: 7a 43 77 64 29 2d 31 2c 20 73 7a 43 77 64 2c 20 zCwd)-1, szCwd,
46c0: 4e 55 4c 4c 29 3b 0a 20 20 20 20 70 72 69 6e 74 NULL);. print
46d0: 66 28 22 25 73 5c 6e 22 2c 20 73 7a 43 77 64 29 f("%s\n", szCwd)
46e0: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a ;. return 0;.
46f0: 7d 0a 0a 2f 2a 0a 20 2a 20 49 6d 70 6c 65 6d 65 }../*. * Impleme
4700: 6e 74 73 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 nts LocateDepend
4710: 65 6e 63 79 20 66 6f 72 20 61 20 73 69 6e 67 6c ency for a singl
4720: 65 20 64 69 72 65 63 74 6f 72 79 2e 20 53 65 65 e directory. See
4730: 20 74 68 61 74 20 63 6f 6d 6d 61 6e 64 0a 20 2a that command. *
4740: 20 66 6f 72 20 61 6e 20 65 78 70 6c 61 6e 61 74 for an explanat
4750: 69 6f 6e 2e 0a 20 2a 20 52 65 74 75 72 6e 73 20 ion.. * Returns
4760: 30 20 69 66 20 66 6f 75 6e 64 20 61 66 74 65 72 0 if found after
4770: 20 70 72 69 6e 74 69 6e 67 20 74 68 65 20 64 69 printing the di
4780: 72 65 63 74 6f 72 79 2e 0a 20 2a 20 52 65 74 75 rectory.. * Retu
4790: 72 6e 73 20 31 20 69 66 20 6e 6f 74 20 66 6f 75 rns 1 if not fou
47a0: 6e 64 20 62 75 74 20 6e 6f 20 65 72 72 6f 72 73 nd but no errors
47b0: 2e 0a 20 2a 20 52 65 74 75 72 6e 73 20 32 20 6f .. * Returns 2 o
47c0: 6e 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20 65 72 n any kind of er
47d0: 72 6f 72 0a 20 2a 20 42 61 73 69 63 61 6c 6c 79 ror. * Basically
47e0: 2c 20 74 68 65 73 65 20 61 72 65 20 75 73 65 64 , these are used
47f0: 20 61 73 20 65 78 69 74 20 63 6f 64 65 73 20 66 as exit codes f
4800: 6f 72 20 74 68 65 20 70 72 6f 63 65 73 73 2e 0a or the process..
4810: 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 4c */.static int L
4820: 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 48 ocateDependencyH
4830: 65 6c 70 65 72 28 63 6f 6e 73 74 20 63 68 61 72 elper(const char
4840: 20 2a 64 69 72 2c 20 63 6f 6e 73 74 20 63 68 61 *dir, const cha
4850: 72 20 2a 6b 65 79 70 61 74 68 29 0a 7b 0a 20 20 r *keypath).{.
4860: 20 20 48 41 4e 44 4c 45 20 68 53 65 61 72 63 68 HANDLE hSearch
4870: 3b 0a 20 20 20 20 63 68 61 72 20 70 61 74 68 5b ;. char path[
4880: 4d 41 58 5f 50 41 54 48 2b 31 5d 3b 0a 20 20 20 MAX_PATH+1];.
4890: 20 73 69 7a 65 5f 74 20 64 69 72 6c 65 6e 3b 0a size_t dirlen;.
48a0: 20 20 20 20 69 6e 74 20 6b 65 79 6c 65 6e 2c 20 int keylen,
48b0: 72 65 74 3b 0a 20 20 20 20 57 49 4e 33 32 5f 46 ret;. WIN32_F
48c0: 49 4e 44 5f 44 41 54 41 20 66 69 6e 66 6f 3b 0a IND_DATA finfo;.
48d0: 0a 20 20 20 20 69 66 20 28 64 69 72 20 3d 3d 20 . if (dir ==
48e0: 4e 55 4c 4c 20 7c 7c 20 6b 65 79 70 61 74 68 20 NULL || keypath
48f0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 == NULL) {..retu
4900: 72 6e 20 32 3b 20 2f 2a 20 48 61 76 65 20 6e 6f rn 2; /* Have no
4910: 20 72 65 61 6c 20 65 72 72 6f 72 20 72 65 70 6f real error repo
4920: 72 74 69 6e 67 20 6d 65 63 68 61 6e 69 73 6d 20 rting mechanism
4930: 69 6e 74 6f 20 6e 6d 61 6b 65 20 2a 2f 0a 20 20 into nmake */.
4940: 20 20 7d 0a 20 20 20 20 64 69 72 6c 65 6e 20 3d }. dirlen =
4950: 20 73 74 72 6c 65 6e 28 64 69 72 29 3b 0a 20 20 strlen(dir);.
4960: 20 20 69 66 20 28 64 69 72 6c 65 6e 20 3e 20 73 if (dirlen > s
4970: 69 7a 65 6f 66 28 70 61 74 68 29 20 2d 20 33 29 izeof(path) - 3)
4980: 20 7b 0a 09 72 65 74 75 72 6e 20 32 3b 0a 20 20 {..return 2;.
4990: 20 20 7d 0a 20 20 20 20 73 74 72 6e 63 70 79 28 }. strncpy(
49a0: 70 61 74 68 2c 20 64 69 72 2c 20 64 69 72 6c 65 path, dir, dirle
49b0: 6e 29 3b 0a 20 20 20 20 73 74 72 6e 63 70 79 28 n);. strncpy(
49c0: 70 61 74 68 2b 64 69 72 6c 65 6e 2c 20 22 5c 5c path+dirlen, "\\
49d0: 2a 22 2c 20 33 29 3b 09 2f 2a 20 49 6e 63 6c 75 *", 3);./* Inclu
49e0: 64 69 6e 67 20 74 65 72 6d 69 6e 61 74 69 6e 67 ding terminating
49f0: 20 5c 30 20 2a 2f 0a 20 20 20 20 6b 65 79 6c 65 \0 */. keyle
4a00: 6e 20 3d 20 73 74 72 6c 65 6e 28 6b 65 79 70 61 n = strlen(keypa
4a10: 74 68 29 3b 0a 0a 23 69 66 20 30 20 2f 2a 20 54 th);..#if 0 /* T
4a20: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 his function is
4a30: 6e 6f 74 20 61 76 61 69 6c 61 62 6c 65 20 69 6e not available in
4a40: 20 56 69 73 75 61 6c 20 43 2b 2b 20 36 20 2a 2f Visual C++ 6 */
4a50: 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 55 . /*. * U
4a60: 73 65 20 6e 75 6d 65 72 69 63 73 20 30 20 2d 3e se numerics 0 ->
4a70: 20 46 69 6e 64 45 78 49 6e 66 6f 53 74 61 6e 64 FindExInfoStand
4a80: 61 72 64 2c 0a 20 20 20 20 20 2a 20 31 20 2d 3e ard,. * 1 ->
4a90: 20 46 69 6e 64 45 78 53 65 61 72 63 68 4c 69 6d FindExSearchLim
4aa0: 69 74 54 6f 44 69 72 65 63 74 6f 72 69 65 73 2c itToDirectories,
4ab0: 0a 20 20 20 20 20 2a 20 61 73 20 74 68 65 73 65 . * as these
4ac0: 20 61 72 65 20 6e 6f 74 20 64 65 66 69 6e 65 64 are not defined
4ad0: 20 69 6e 20 56 69 73 75 61 6c 20 43 2b 2b 20 36 in Visual C++ 6
4ae0: 0a 20 20 20 20 20 2a 2f 0a 20 20 20 20 68 53 65 . */. hSe
4af0: 61 72 63 68 20 3d 20 46 69 6e 64 46 69 72 73 74 arch = FindFirst
4b00: 46 69 6c 65 45 78 28 70 61 74 68 2c 20 30 2c 20 FileEx(path, 0,
4b10: 26 66 69 6e 66 6f 2c 20 31 2c 20 4e 55 4c 4c 2c &finfo, 1, NULL,
4b20: 20 30 29 3b 0a 23 65 6c 73 65 0a 20 20 20 20 68 0);.#else. h
4b30: 53 65 61 72 63 68 20 3d 20 46 69 6e 64 46 69 72 Search = FindFir
4b40: 73 74 46 69 6c 65 28 70 61 74 68 2c 20 26 66 69 stFile(path, &fi
4b50: 6e 66 6f 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 nfo);.#endif.
4b60: 20 69 66 20 28 68 53 65 61 72 63 68 20 3d 3d 20 if (hSearch ==
4b70: 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 INVALID_HANDLE_V
4b80: 41 4c 55 45 29 0a 09 72 65 74 75 72 6e 20 31 3b ALUE)..return 1;
4b90: 20 2f 2a 20 4e 6f 74 20 66 6f 75 6e 64 20 2a 2f /* Not found */
4ba0: 0a 0a 20 20 20 20 2f 2a 20 4c 6f 6f 70 20 74 68 .. /* Loop th
4bb0: 72 6f 75 67 68 20 61 6c 6c 20 73 75 62 64 69 72 rough all subdir
4bc0: 73 20 63 68 65 63 6b 69 6e 67 20 69 66 20 74 68 s checking if th
4bd0: 65 20 6b 65 79 70 61 74 68 20 69 73 20 75 6e 64 e keypath is und
4be0: 65 72 20 74 68 65 72 65 20 2a 2f 0a 20 20 20 20 er there */.
4bf0: 72 65 74 20 3d 20 31 3b 20 2f 2a 20 41 73 73 75 ret = 1; /* Assu
4c00: 6d 65 20 6e 6f 74 20 66 6f 75 6e 64 20 2a 2f 0a me not found */.
4c10: 20 20 20 20 64 6f 20 7b 0a 09 69 6e 74 20 73 75 do {..int su
4c20: 62 6c 65 6e 3b 0a 09 2f 2a 0a 09 20 2a 20 57 65 blen;../*.. * We
4c30: 20 6e 65 65 64 20 74 6f 20 63 68 65 63 6b 20 69 need to check i
4c40: 74 20 69 73 20 61 20 64 69 72 65 63 74 6f 72 79 t is a directory
4c50: 20 64 65 73 70 69 74 65 20 74 68 65 0a 09 20 2a despite the.. *
4c60: 20 46 69 6e 64 45 78 53 65 61 72 63 68 4c 69 6d FindExSearchLim
4c70: 69 74 54 6f 44 69 72 65 63 74 6f 72 69 65 73 20 itToDirectories
4c80: 69 6e 20 74 68 65 20 61 62 6f 76 65 20 63 61 6c in the above cal
4c90: 6c 2e 20 53 65 65 20 53 44 4b 20 64 6f 63 73 0a l. See SDK docs.
4ca0: 09 20 2a 2f 0a 09 69 66 20 28 28 66 69 6e 66 6f . */..if ((finfo
4cb0: 2e 64 77 46 69 6c 65 41 74 74 72 69 62 75 74 65 .dwFileAttribute
4cc0: 73 20 26 20 46 49 4c 45 5f 41 54 54 52 49 42 55 s & FILE_ATTRIBU
4cd0: 54 45 5f 44 49 52 45 43 54 4f 52 59 29 20 3d 3d TE_DIRECTORY) ==
4ce0: 20 30 29 0a 09 20 20 20 20 63 6f 6e 74 69 6e 75 0).. continu
4cf0: 65 3b 0a 09 73 75 62 6c 65 6e 20 3d 20 73 74 72 e;..sublen = str
4d00: 6c 65 6e 28 66 69 6e 66 6f 2e 63 46 69 6c 65 4e len(finfo.cFileN
4d10: 61 6d 65 29 3b 0a 09 69 66 20 28 28 64 69 72 6c ame);..if ((dirl
4d20: 65 6e 2b 31 2b 73 75 62 6c 65 6e 2b 31 2b 6b 65 en+1+sublen+1+ke
4d30: 79 6c 65 6e 2b 31 29 20 3e 20 73 69 7a 65 6f 66 ylen+1) > sizeof
4d40: 28 70 61 74 68 29 29 0a 09 20 20 20 20 63 6f 6e (path)).. con
4d50: 74 69 6e 75 65 3b 09 09 2f 2a 20 50 61 74 68 20 tinue;../* Path
4d60: 64 6f 65 73 20 6e 6f 74 20 66 69 74 2c 20 61 73 does not fit, as
4d70: 73 75 6d 65 20 6e 6f 74 20 6d 61 74 63 68 65 64 sume not matched
4d80: 20 2a 2f 0a 09 73 74 72 6e 63 70 79 28 70 61 74 */..strncpy(pat
4d90: 68 2b 64 69 72 6c 65 6e 2b 31 2c 20 66 69 6e 66 h+dirlen+1, finf
4da0: 6f 2e 63 46 69 6c 65 4e 61 6d 65 2c 20 73 75 62 o.cFileName, sub
4db0: 6c 65 6e 29 3b 0a 09 70 61 74 68 5b 64 69 72 6c len);..path[dirl
4dc0: 65 6e 2b 31 2b 73 75 62 6c 65 6e 5d 20 3d 20 27 en+1+sublen] = '
4dd0: 5c 5c 27 3b 0a 09 73 74 72 6e 63 70 79 28 70 61 \\';..strncpy(pa
4de0: 74 68 2b 64 69 72 6c 65 6e 2b 31 2b 73 75 62 6c th+dirlen+1+subl
4df0: 65 6e 2b 31 2c 20 6b 65 79 70 61 74 68 2c 20 6b en+1, keypath, k
4e00: 65 79 6c 65 6e 2b 31 29 3b 0a 09 69 66 20 28 46 eylen+1);..if (F
4e10: 69 6c 65 45 78 69 73 74 73 28 70 61 74 68 29 29 ileExists(path))
4e20: 20 7b 0a 09 20 20 20 20 2f 2a 20 46 6f 75 6e 64 {.. /* Found
4e30: 20 61 20 6d 61 74 63 68 2c 20 70 72 69 6e 74 20 a match, print
4e40: 74 6f 20 73 74 64 6f 75 74 20 2a 2f 0a 09 20 20 to stdout */..
4e50: 20 20 70 61 74 68 5b 64 69 72 6c 65 6e 2b 31 2b path[dirlen+1+
4e60: 73 75 62 6c 65 6e 5d 20 3d 20 27 5c 30 27 3b 0a sublen] = '\0';.
4e70: 09 20 20 20 20 51 75 61 6c 69 66 79 50 61 74 68 . QualifyPath
4e80: 28 70 61 74 68 29 3b 0a 09 20 20 20 20 72 65 74 (path);.. ret
4e90: 20 3d 20 30 3b 0a 09 20 20 20 20 62 72 65 61 6b = 0;.. break
4ea0: 3b 0a 09 7d 0a 20 20 20 20 7d 20 77 68 69 6c 65 ;..}. } while
4eb0: 20 28 46 69 6e 64 4e 65 78 74 46 69 6c 65 28 68 (FindNextFile(h
4ec0: 53 65 61 72 63 68 2c 20 26 66 69 6e 66 6f 29 29 Search, &finfo))
4ed0: 3b 0a 20 20 20 20 46 69 6e 64 43 6c 6f 73 65 28 ;. FindClose(
4ee0: 68 53 65 61 72 63 68 29 3b 0a 20 20 20 20 72 65 hSearch);. re
4ef0: 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 2f 2a 0a turn ret;.}../*.
4f00: 20 2a 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 * LocateDepende
4f10: 6e 63 79 20 2d 2d 0a 20 2a 0a 20 2a 09 4c 6f 63 ncy --. *. *.Loc
4f20: 61 74 65 73 20 61 20 64 65 70 65 6e 64 65 6e 63 ates a dependenc
4f30: 79 20 66 6f 72 20 61 20 70 61 63 6b 61 67 65 2e y for a package.
4f40: 0a 20 2a 20 20 20 20 20 20 20 20 6b 65 79 70 61 . * keypa
4f50: 74 68 20 2d 20 61 20 72 65 6c 61 74 69 76 65 20 th - a relative
4f60: 70 61 74 68 20 77 69 74 68 69 6e 20 74 68 65 20 path within the
4f70: 70 61 63 6b 61 67 65 20 64 69 72 65 63 74 6f 72 package director
4f80: 79 0a 20 2a 20 20 20 20 20 20 20 20 20 20 74 68 y. * th
4f90: 61 74 20 69 73 20 75 73 65 64 20 74 6f 20 63 6f at is used to co
4fa0: 6e 66 69 72 6d 20 69 74 20 69 73 20 74 68 65 20 nfirm it is the
4fb0: 63 6f 72 72 65 63 74 20 64 69 72 65 63 74 6f 72 correct director
4fc0: 79 2e 0a 20 2a 09 54 68 65 20 73 65 61 72 63 68 y.. *.The search
4fd0: 20 70 61 74 68 20 66 6f 72 20 74 68 65 20 70 61 path for the pa
4fe0: 63 6b 61 67 65 20 64 69 72 65 63 74 6f 72 79 20 ckage directory
4ff0: 69 73 20 63 75 72 72 65 6e 74 6c 79 20 6f 6e 6c is currently onl
5000: 79 0a 20 2a 20 20 20 20 20 20 74 68 65 20 70 61 y. * the pa
5010: 72 65 6e 74 20 61 6e 64 20 67 72 61 6e 64 70 61 rent and grandpa
5020: 72 65 6e 74 20 6f 66 20 74 68 65 20 63 75 72 72 rent of the curr
5030: 65 6e 74 20 77 6f 72 6b 69 6e 67 20 64 69 72 65 ent working dire
5040: 63 74 6f 72 79 2e 0a 20 2a 20 20 20 20 20 20 49 ctory.. * I
5050: 66 20 66 6f 75 6e 64 2c 20 74 68 65 20 63 6f 6d f found, the com
5060: 6d 61 6e 64 20 70 72 69 6e 74 73 0a 20 2a 20 20 mand prints. *
5070: 20 20 20 20 20 20 20 6e 61 6d 65 5f 44 49 52 50 name_DIRP
5080: 41 54 48 3d 3c 66 75 6c 6c 20 70 61 74 68 20 6f ATH=<full path o
5090: 66 20 6c 6f 63 61 74 65 64 20 64 69 72 65 63 74 f located direct
50a0: 6f 72 79 3e 0a 20 2a 20 20 20 20 20 20 61 6e 64 ory>. * and
50b0: 20 72 65 74 75 72 6e 73 20 30 2e 20 49 66 20 6e returns 0. If n
50c0: 6f 74 20 66 6f 75 6e 64 2c 20 64 6f 65 73 20 6e ot found, does n
50d0: 6f 74 20 70 72 69 6e 74 20 61 6e 79 74 68 69 6e ot print anythin
50e0: 67 20 61 6e 64 20 72 65 74 75 72 6e 73 20 31 2e g and returns 1.
50f0: 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 . */.static int
5100: 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 LocateDependency
5110: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b 65 79 (const char *key
5120: 70 61 74 68 29 0a 7b 0a 20 20 20 20 73 69 7a 65 path).{. size
5130: 5f 74 20 69 3b 0a 20 20 20 20 69 6e 74 20 72 65 _t i;. int re
5140: 74 3b 0a 20 20 20 20 73 74 61 74 69 63 20 63 6f t;. static co
5150: 6e 73 74 20 63 68 61 72 20 2a 70 61 74 68 73 5b nst char *paths[
5160: 5d 20 3d 20 7b 22 2e 2e 22 2c 20 22 2e 2e 5c 5c ] = {"..", "..\\
5170: 2e 2e 22 2c 20 22 2e 2e 5c 5c 2e 2e 5c 5c 2e 2e ..", "..\\..\\..
5180: 22 7d 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69 20 "};.. for (i
5190: 3d 20 30 3b 20 69 20 3c 20 28 73 69 7a 65 6f 66 = 0; i < (sizeof
51a0: 28 70 61 74 68 73 29 2f 73 69 7a 65 6f 66 28 70 (paths)/sizeof(p
51b0: 61 74 68 73 5b 30 5d 29 29 3b 20 2b 2b 69 29 20 aths[0])); ++i)
51c0: 7b 0a 09 72 65 74 20 3d 20 4c 6f 63 61 74 65 44 {..ret = LocateD
51d0: 65 70 65 6e 64 65 6e 63 79 48 65 6c 70 65 72 28 ependencyHelper(
51e0: 70 61 74 68 73 5b 69 5d 2c 20 6b 65 79 70 61 74 paths[i], keypat
51f0: 68 29 3b 0a 09 69 66 20 28 72 65 74 20 3d 3d 20 h);..if (ret ==
5200: 30 29 20 7b 0a 09 20 20 20 20 72 65 74 75 72 6e 0) {.. return
5210: 20 72 65 74 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 ret;..}. }.
5220: 20 20 20 72 65 74 75 72 6e 20 72 65 74 3b 0a 7d return ret;.}
5230: 0a 0a 0a 2f 2a 0a 20 2a 20 4c 6f 63 61 6c 20 76 .../*. * Local v
5240: 61 72 69 61 62 6c 65 73 3a 0a 20 2a 20 20 20 6d ariables:. * m
5250: 6f 64 65 3a 20 63 0a 20 2a 20 20 20 63 2d 62 61 ode: c. * c-ba
5260: 73 69 63 2d 6f 66 66 73 65 74 3a 20 34 0a 20 2a sic-offset: 4. *
5270: 20 20 20 66 69 6c 6c 2d 63 6f 6c 75 6d 6e 3a 20 fill-column:
5280: 37 38 0a 20 2a 20 20 20 69 6e 64 65 6e 74 2d 74 78. * indent-t
5290: 61 62 73 2d 6d 6f 64 65 3a 20 74 0a 20 2a 20 20 abs-mode: t. *
52a0: 20 74 61 62 2d 77 69 64 74 68 3a 20 38 0a 20 2a tab-width: 8. *
52b0: 20 45 6e 64 3a 0a 20 2a 2f 0a End:. */.