0000: 2f 2a 0a 20 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d /*. * ----------
0010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0050: 2d 2d 0a 20 2a 20 6e 6d 61 6b 65 68 6c 70 2e 63 --. * nmakehlp.c
0060: 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 69 --. *. *.This i
0070: 73 20 75 73 65 64 20 74 6f 20 66 69 78 20 6c 69 s used to fix li
0080: 6d 69 74 61 74 69 6f 6e 73 20 77 69 74 68 69 6e mitations within
0090: 20 6e 6d 61 6b 65 20 61 6e 64 20 74 68 65 20 65 nmake and the e
00a0: 6e 76 69 72 6f 6e 6d 65 6e 74 2e 0a 20 2a 0a 20 nvironment.. *.
00b0: 2a 20 43 6f 70 79 72 69 67 68 74 20 28 63 29 20 * Copyright (c)
00c0: 32 30 30 32 20 44 61 76 69 64 20 47 72 61 76 65 2002 David Grave
00d0: 72 65 61 75 78 2e 0a 20 2a 20 43 6f 70 79 72 69 reaux.. * Copyri
00e0: 67 68 74 20 28 63 29 20 32 30 30 36 20 50 61 74 ght (c) 2006 Pat
00f0: 20 54 68 6f 79 74 73 0a 20 2a 0a 20 2a 20 53 65 Thoyts. *. * Se
0100: 65 20 74 68 65 20 66 69 6c 65 20 22 6c 69 63 65 e the file "lice
0110: 6e 73 65 2e 74 65 72 6d 73 22 20 66 6f 72 20 69 nse.terms" for i
0120: 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 75 73 nformation on us
0130: 61 67 65 20 61 6e 64 20 72 65 64 69 73 74 72 69 age and redistri
0140: 62 75 74 69 6f 6e 20 6f 66 0a 20 2a 20 74 68 69 bution of. * thi
0150: 73 20 66 69 6c 65 2c 20 61 6e 64 20 66 6f 72 20 s file, and for
0160: 61 20 44 49 53 43 4c 41 49 4d 45 52 20 4f 46 20 a DISCLAIMER OF
0170: 41 4c 4c 20 57 41 52 52 41 4e 54 49 45 53 2e 0a ALL WARRANTIES..
0180: 20 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d * -------------
0190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
01a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
01b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
01c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
01d0: 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 5f 43 52 */..#define _CR
01e0: 54 5f 53 45 43 55 52 45 5f 4e 4f 5f 44 45 50 52 T_SECURE_NO_DEPR
01f0: 45 43 41 54 45 0a 23 69 6e 63 6c 75 64 65 20 3c ECATE.#include <
0200: 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 69 66 64 65 windows.h>.#ifde
0210: 66 20 5f 4d 53 43 5f 56 45 52 0a 23 70 72 61 67 f _MSC_VER.#prag
0220: 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 6c 69 62 2c ma comment (lib,
0230: 20 22 75 73 65 72 33 32 2e 6c 69 62 22 29 0a 23 "user32.lib").#
0240: 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 pragma comment (
0250: 6c 69 62 2c 20 22 6b 65 72 6e 65 6c 33 32 2e 6c lib, "kernel32.l
0260: 69 62 22 29 0a 23 65 6e 64 69 66 0a 23 69 6e 63 ib").#endif.#inc
0270: 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 0a lude <stdio.h>..
0280: 2f 2a 0a 20 2a 20 54 68 69 73 20 6c 69 62 72 61 /*. * This libra
0290: 72 79 20 69 73 20 72 65 71 75 69 72 65 64 20 66 ry is required f
02a0: 6f 72 20 78 36 34 20 62 75 69 6c 64 73 20 77 69 or x64 builds wi
02b0: 74 68 20 5f 73 6f 6d 65 5f 20 76 65 72 73 69 6f th _some_ versio
02c0: 6e 73 20 6f 66 20 4d 53 56 43 0a 20 2a 2f 0a 23 ns of MSVC. */.#
02d0: 69 66 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 41 if defined(_M_IA
02e0: 36 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 64) || defined(_
02f0: 4d 5f 41 4d 44 36 34 29 0a 23 69 66 20 5f 4d 53 M_AMD64).#if _MS
0300: 43 5f 56 45 52 20 3e 3d 20 31 34 30 30 20 26 26 C_VER >= 1400 &&
0310: 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 35 30 30 _MSC_VER < 1500
0320: 0a 23 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 .#pragma comment
0330: 28 6c 69 62 2c 20 22 62 75 66 66 65 72 6f 76 65 (lib, "bufferove
0340: 72 66 6c 6f 77 55 22 29 0a 23 65 6e 64 69 66 0a rflowU").#endif.
0350: 23 65 6e 64 69 66 0a 0a 2f 2a 20 49 53 4f 20 68 #endif../* ISO h
0360: 61 63 6b 20 66 6f 72 20 64 75 6d 62 20 56 43 2b ack for dumb VC+
0370: 2b 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64 + */.#if defined
0380: 28 5f 57 49 4e 33 32 29 20 26 26 20 64 65 66 69 (_WIN32) && defi
0390: 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 20 26 26 ned(_MSC_VER) &&
03a0: 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 39 30 30 _MSC_VER < 1900
03b0: 0a 23 64 65 66 69 6e 65 20 20 20 73 6e 70 72 69 .#define snpri
03c0: 6e 74 66 09 5f 73 6e 70 72 69 6e 74 66 0a 23 65 ntf._snprintf.#e
03d0: 6e 64 69 66 0a 0a 0a 2f 2a 20 70 72 6f 74 6f 73 ndif.../* protos
03e0: 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 20 */..static int
03f0: 43 68 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 CheckForCompiler
0400: 46 65 61 74 75 72 65 28 63 6f 6e 73 74 20 63 68 Feature(const ch
0410: 61 72 20 2a 6f 70 74 69 6f 6e 29 3b 0a 73 74 61 ar *option);.sta
0420: 74 69 63 20 69 6e 74 20 43 68 65 63 6b 46 6f 72 tic int CheckFor
0430: 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 63 68 LinkerFeature(ch
0440: 61 72 20 2a 2a 6f 70 74 69 6f 6e 73 2c 20 69 6e ar **options, in
0450: 74 20 63 6f 75 6e 74 29 3b 0a 73 74 61 74 69 63 t count);.static
0460: 20 69 6e 74 20 49 73 49 6e 28 63 6f 6e 73 74 20 int IsIn(const
0470: 63 68 61 72 20 2a 73 74 72 69 6e 67 2c 20 63 6f char *string, co
0480: 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73 74 72 nst char *substr
0490: 69 6e 67 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 ing);.static int
04a0: 20 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 28 SubstituteFile(
04b0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73 const char *subs
04c0: 74 73 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a ts, const char *
04d0: 66 69 6c 65 6e 61 6d 65 29 3b 0a 73 74 61 74 69 filename);.stati
04e0: 63 20 69 6e 74 20 51 75 61 6c 69 66 79 50 61 74 c int QualifyPat
04f0: 68 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 h(const char *pa
0500: 74 68 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20 th);.static int
0510: 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 LocateDependency
0520: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b 65 79 (const char *key
0530: 66 69 6c 65 29 3b 0a 73 74 61 74 69 63 20 63 6f file);.static co
0540: 6e 73 74 20 63 68 61 72 20 2a 47 65 74 56 65 72 nst char *GetVer
0550: 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 63 6f 6e sionFromFile(con
0560: 73 74 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d st char *filenam
0570: 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6d e, const char *m
0580: 61 74 63 68 2c 20 69 6e 74 20 6e 75 6d 64 6f 74 atch, int numdot
0590: 73 29 3b 0a 73 74 61 74 69 63 20 44 57 4f 52 44 s);.static DWORD
05a0: 20 57 49 4e 41 50 49 20 52 65 61 64 46 72 6f 6d WINAPI ReadFrom
05b0: 50 69 70 65 28 4c 50 56 4f 49 44 20 61 72 67 73 Pipe(LPVOID args
05c0: 29 3b 0a 0a 2f 2a 20 67 6c 6f 62 61 6c 73 20 2a );../* globals *
05d0: 2f 0a 0a 23 64 65 66 69 6e 65 20 43 48 55 4e 4b /..#define CHUNK
05e0: 09 32 35 0a 23 64 65 66 69 6e 65 20 53 54 41 54 .25.#define STAT
05f0: 49 43 42 55 46 46 45 52 53 49 5a 45 20 20 20 20 ICBUFFERSIZE
0600: 31 30 30 30 0a 74 79 70 65 64 65 66 20 73 74 72 1000.typedef str
0610: 75 63 74 20 7b 0a 20 20 20 20 48 41 4e 44 4c 45 uct {. HANDLE
0620: 20 70 69 70 65 3b 0a 20 20 20 20 63 68 61 72 20 pipe;. char
0630: 62 75 66 66 65 72 5b 53 54 41 54 49 43 42 55 46 buffer[STATICBUF
0640: 46 45 52 53 49 5a 45 5d 3b 0a 7d 20 70 69 70 65 FERSIZE];.} pipe
0650: 69 6e 66 6f 3b 0a 0a 70 69 70 65 69 6e 66 6f 20 info;..pipeinfo
0660: 4f 75 74 20 3d 20 7b 49 4e 56 41 4c 49 44 5f 48 Out = {INVALID_H
0670: 41 4e 44 4c 45 5f 56 41 4c 55 45 2c 20 22 22 7d ANDLE_VALUE, ""}
0680: 3b 0a 70 69 70 65 69 6e 66 6f 20 45 72 72 20 3d ;.pipeinfo Err =
0690: 20 7b 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 {INVALID_HANDLE
06a0: 5f 56 41 4c 55 45 2c 20 22 22 7d 3b 0a 0c 0a 2f _VALUE, ""};.../
06b0: 2a 0a 20 2a 20 65 78 69 74 63 6f 64 65 73 3a 20 *. * exitcodes:
06c0: 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 0 == no, 1 == ye
06d0: 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 0a 20 2a s, 2 == error. *
06e0: 2f 0a 0a 69 6e 74 0a 6d 61 69 6e 28 0a 20 20 20 /..int.main(.
06f0: 20 69 6e 74 20 61 72 67 63 2c 0a 20 20 20 20 63 int argc,. c
0700: 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a 7b 0a 20 har *argv[]).{.
0710: 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 30 5d char msg[300]
0720: 3b 0a 20 20 20 20 44 57 4f 52 44 20 64 77 57 72 ;. DWORD dwWr
0730: 69 74 74 65 6e 3b 0a 20 20 20 20 69 6e 74 20 63 itten;. int c
0740: 68 61 72 73 3b 0a 20 20 20 20 63 6f 6e 73 74 20 hars;. const
0750: 63 68 61 72 20 2a 73 3b 0a 0a 20 20 20 20 2f 2a char *s;.. /*
0760: 0a 20 20 20 20 20 2a 20 4d 61 6b 65 20 73 75 72 . * Make sur
0770: 65 20 63 68 69 6c 64 72 65 6e 20 28 63 6c 2e 65 e children (cl.e
0780: 78 65 20 61 6e 64 20 6c 69 6e 6b 2e 65 78 65 29 xe and link.exe)
0790: 20 61 72 65 20 6b 65 70 74 20 71 75 69 65 74 2e are kept quiet.
07a0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 53 65 . */.. Se
07b0: 74 45 72 72 6f 72 4d 6f 64 65 28 53 45 4d 5f 46 tErrorMode(SEM_F
07c0: 41 49 4c 43 52 49 54 49 43 41 4c 45 52 52 4f 52 AILCRITICALERROR
07d0: 53 20 7c 20 53 45 4d 5f 4e 4f 4f 50 45 4e 46 49 S | SEM_NOOPENFI
07e0: 4c 45 45 52 52 4f 52 42 4f 58 29 3b 0a 0a 20 20 LEERRORBOX);..
07f0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4d 61 6b 65 /*. * Make
0800: 20 73 75 72 65 20 74 68 65 20 63 6f 6d 70 69 6c sure the compil
0810: 65 72 20 61 6e 64 20 6c 69 6e 6b 65 72 20 61 72 er and linker ar
0820: 65 6e 27 74 20 65 66 66 65 63 74 65 64 20 62 79 en't effected by
0830: 20 74 68 65 20 6f 75 74 73 69 64 65 20 77 6f 72 the outside wor
0840: 6c 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ld.. */..
0850: 20 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56 SetEnvironmentV
0860: 61 72 69 61 62 6c 65 28 22 43 4c 22 2c 20 22 22 ariable("CL", ""
0870: 29 3b 0a 20 20 20 20 53 65 74 45 6e 76 69 72 6f );. SetEnviro
0880: 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 22 4c nmentVariable("L
0890: 49 4e 4b 22 2c 20 22 22 29 3b 0a 0a 20 20 20 20 INK", "");..
08a0: 69 66 20 28 61 72 67 63 20 3e 20 31 20 26 26 20 if (argc > 1 &&
08b0: 2a 61 72 67 76 5b 31 5d 20 3d 3d 20 27 2d 27 29 *argv[1] == '-')
08c0: 20 7b 0a 09 73 77 69 74 63 68 20 28 2a 28 61 72 {..switch (*(ar
08d0: 67 76 5b 31 5d 2b 31 29 29 20 7b 0a 09 63 61 73 gv[1]+1)) {..cas
08e0: 65 20 27 63 27 3a 0a 09 20 20 20 20 69 66 20 28 e 'c':.. if (
08f0: 61 72 67 63 20 21 3d 20 33 29 20 7b 0a 09 09 63 argc != 3) {...c
0900: 68 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 hars = snprintf(
0910: 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 msg, sizeof(msg)
0920: 20 2d 20 31 2c 0a 09 09 09 22 75 73 61 67 65 3a - 1,...."usage:
0930: 20 25 73 20 2d 63 20 3c 63 6f 6d 70 69 6c 65 72 %s -c <compiler
0940: 20 6f 70 74 69 6f 6e 3e 5c 6e 22 0a 09 09 09 22 option>\n"...."
0950: 54 65 73 74 73 20 66 6f 72 20 77 68 65 74 68 65 Tests for whethe
0960: 72 20 63 6c 2e 65 78 65 20 73 75 70 70 6f 72 74 r cl.exe support
0970: 73 20 61 6e 20 6f 70 74 69 6f 6e 5c 6e 22 0a 09 s an option\n"..
0980: 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 20 .."exitcodes: 0
0990: 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c == no, 1 == yes,
09a0: 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c 20 2 == error\n",
09b0: 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 argv[0]);...Writ
09c0: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 eFile(GetStdHand
09d0: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e le(STD_ERROR_HAN
09e0: 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 DLE), msg, chars
09f0: 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c ,....&dwWritten,
0a00: 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e NULL);...return
0a10: 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 2;.. }..
0a20: 72 65 74 75 72 6e 20 43 68 65 63 6b 46 6f 72 43 return CheckForC
0a30: 6f 6d 70 69 6c 65 72 46 65 61 74 75 72 65 28 61 ompilerFeature(a
0a40: 72 67 76 5b 32 5d 29 3b 0a 09 63 61 73 65 20 27 rgv[2]);..case '
0a50: 6c 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 67 l':.. if (arg
0a60: 63 20 3c 20 33 29 20 7b 0a 09 09 63 68 61 72 73 c < 3) {...chars
0a70: 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c = snprintf(msg,
0a80: 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 sizeof(msg) - 1
0a90: 2c 0a 09 09 09 22 75 73 61 67 65 3a 20 25 73 20 ,...."usage: %s
0aa0: 2d 6c 20 3c 6c 69 6e 6b 65 72 20 6f 70 74 69 6f -l <linker optio
0ab0: 6e 3e 20 3f 3c 6d 61 6e 64 61 74 6f 72 79 20 6f n> ?<mandatory o
0ac0: 70 74 69 6f 6e 3e 20 2e 2e 2e 3f 5c 6e 22 0a 09 ption> ...?\n"..
0ad0: 09 09 22 54 65 73 74 73 20 66 6f 72 20 77 68 65 .."Tests for whe
0ae0: 74 68 65 72 20 6c 69 6e 6b 2e 65 78 65 20 73 75 ther link.exe su
0af0: 70 70 6f 72 74 73 20 61 6e 20 6f 70 74 69 6f 6e pports an option
0b00: 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 65 \n"...."exitcode
0b10: 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d s: 0 == no, 1 ==
0b20: 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 yes, 2 == error
0b30: 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 \n", argv[0]);..
0b40: 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 .WriteFile(GetSt
0b50: 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f dHandle(STD_ERRO
0b60: 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 R_HANDLE), msg,
0b70: 63 68 61 72 73 2c 0a 09 09 09 26 64 77 57 72 69 chars,....&dwWri
0b80: 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 tten, NULL);...r
0b90: 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a eturn 2;.. }.
0ba0: 09 20 20 20 20 72 65 74 75 72 6e 20 43 68 65 63 . return Chec
0bb0: 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 kForLinkerFeatur
0bc0: 65 28 26 61 72 67 76 5b 32 5d 2c 20 61 72 67 63 e(&argv[2], argc
0bd0: 2d 32 29 3b 0a 09 63 61 73 65 20 27 66 27 3a 0a -2);..case 'f':.
0be0: 09 20 20 20 20 69 66 20 28 61 72 67 63 20 3d 3d . if (argc ==
0bf0: 20 32 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 2) {...chars =
0c00: 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 snprintf(msg, si
0c10: 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 zeof(msg) - 1,..
0c20: 09 09 22 75 73 61 67 65 3a 20 25 73 20 2d 66 20 .."usage: %s -f
0c30: 3c 73 74 72 69 6e 67 3e 20 3c 73 75 62 73 74 72 <string> <substr
0c40: 69 6e 67 3e 5c 6e 22 0a 09 09 09 22 46 69 6e 64 ing>\n"...."Find
0c50: 20 61 20 73 75 62 73 74 72 69 6e 67 20 77 69 74 a substring wit
0c60: 68 69 6e 20 61 6e 6f 74 68 65 72 5c 6e 22 0a 09 hin another\n"..
0c70: 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 20 .."exitcodes: 0
0c80: 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c == no, 1 == yes,
0c90: 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c 20 2 == error\n",
0ca0: 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 argv[0]);...Writ
0cb0: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 eFile(GetStdHand
0cc0: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e le(STD_ERROR_HAN
0cd0: 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 DLE), msg, chars
0ce0: 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c ,....&dwWritten,
0cf0: 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e NULL);...return
0d00: 20 32 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 2;.. } else
0d10: 69 66 20 28 61 72 67 63 20 3d 3d 20 33 29 20 7b if (argc == 3) {
0d20: 0a 09 09 2f 2a 0a 09 09 20 2a 20 49 66 20 74 68 .../*... * If th
0d30: 65 20 73 74 72 69 6e 67 20 69 73 20 62 6c 61 6e e string is blan
0d40: 6b 2c 20 74 68 65 72 65 20 69 73 20 6e 6f 20 6d k, there is no m
0d50: 61 74 63 68 2e 0a 09 09 20 2a 2f 0a 0a 09 09 72 atch.... */....r
0d60: 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20 eturn 0;.. }
0d70: 65 6c 73 65 20 7b 0a 09 09 72 65 74 75 72 6e 20 else {...return
0d80: 49 73 49 6e 28 61 72 67 76 5b 32 5d 2c 20 61 72 IsIn(argv[2], ar
0d90: 67 76 5b 33 5d 29 3b 0a 09 20 20 20 20 7d 0a 09 gv[3]);.. }..
0da0: 63 61 73 65 20 27 73 27 3a 0a 09 20 20 20 20 69 case 's':.. i
0db0: 66 20 28 61 72 67 63 20 3d 3d 20 32 29 20 7b 0a f (argc == 2) {.
0dc0: 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 69 6e ..chars = snprin
0dd0: 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d tf(msg, sizeof(m
0de0: 73 67 29 20 2d 20 31 2c 0a 09 09 09 22 75 73 61 sg) - 1,...."usa
0df0: 67 65 3a 20 25 73 20 2d 73 20 3c 73 75 62 73 74 ge: %s -s <subst
0e00: 69 74 75 74 69 6f 6e 73 20 66 69 6c 65 3e 20 3c itutions file> <
0e10: 66 69 6c 65 3e 5c 6e 22 0a 09 09 09 22 50 65 72 file>\n"...."Per
0e20: 66 6f 72 6d 20 61 20 73 65 74 20 6f 66 20 73 74 form a set of st
0e30: 72 69 6e 67 20 6d 61 70 20 74 79 70 65 20 73 75 ring map type su
0e40: 62 73 74 75 74 69 74 69 6f 6e 73 20 6f 6e 20 61 bstutitions on a
0e50: 20 66 69 6c 65 5c 6e 22 0a 09 09 09 22 65 78 69 file\n"...."exi
0e60: 74 63 6f 64 65 73 3a 20 30 5c 6e 22 2c 0a 09 09 tcodes: 0\n",...
0e70: 09 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 .argv[0]);...Wri
0e80: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e teFile(GetStdHan
0e90: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 dle(STD_ERROR_HA
0ea0: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 NDLE), msg, char
0eb0: 73 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e s,....&dwWritten
0ec0: 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 , NULL);...retur
0ed0: 6e 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 n 2;.. }..
0ee0: 20 72 65 74 75 72 6e 20 53 75 62 73 74 69 74 75 return Substitu
0ef0: 74 65 46 69 6c 65 28 61 72 67 76 5b 32 5d 2c 20 teFile(argv[2],
0f00: 61 72 67 76 5b 33 5d 29 3b 0a 09 63 61 73 65 20 argv[3]);..case
0f10: 27 56 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 'V':.. if (ar
0f20: 67 63 20 21 3d 20 34 29 20 7b 0a 09 09 63 68 61 gc != 4) {...cha
0f30: 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 rs = snprintf(ms
0f40: 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d g, sizeof(msg) -
0f50: 20 31 2c 0a 09 09 20 20 20 20 22 75 73 61 67 65 1,... "usage
0f60: 3a 20 25 73 20 2d 56 20 66 69 6c 65 6e 61 6d 65 : %s -V filename
0f70: 20 6d 61 74 63 68 73 74 72 69 6e 67 5c 6e 22 0a matchstring\n".
0f80: 09 09 20 20 20 20 22 45 78 74 72 61 63 74 20 61 .. "Extract a
0f90: 20 76 65 72 73 69 6f 6e 20 66 72 6f 6d 20 61 20 version from a
0fa0: 66 69 6c 65 3a 5c 6e 22 0a 09 09 20 20 20 20 22 file:\n"... "
0fb0: 65 67 3a 20 70 6b 67 49 6e 64 65 78 2e 74 63 6c eg: pkgIndex.tcl
0fc0: 20 5c 22 70 61 63 6b 61 67 65 20 69 66 6e 65 65 \"package ifnee
0fd0: 64 65 64 20 68 74 74 70 5c 22 22 2c 0a 09 09 20 ded http\"",...
0fe0: 20 20 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 argv[0]);...W
0ff0: 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 riteFile(GetStdH
1000: 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f andle(STD_ERROR_
1010: 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 HANDLE), msg, ch
1020: 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57 72 ars,... &dwWr
1030: 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 itten, NULL);...
1040: 72 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d return 0;.. }
1050: 0a 09 20 20 20 20 73 20 3d 20 47 65 74 56 65 72 .. s = GetVer
1060: 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 61 72 67 sionFromFile(arg
1070: 76 5b 32 5d 2c 20 61 72 67 76 5b 33 5d 2c 20 2a v[2], argv[3], *
1080: 28 61 72 67 76 5b 31 5d 2b 32 29 20 2d 20 27 30 (argv[1]+2) - '0
1090: 27 29 3b 0a 09 20 20 20 20 69 66 20 28 73 20 26 ');.. if (s &
10a0: 26 20 2a 73 29 20 7b 0a 09 09 70 72 69 6e 74 66 & *s) {...printf
10b0: 28 22 25 73 5c 6e 22 2c 20 73 29 3b 0a 09 09 72 ("%s\n", s);...r
10c0: 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20 eturn 0;.. }
10d0: 65 6c 73 65 0a 09 09 72 65 74 75 72 6e 20 31 3b else...return 1;
10e0: 20 2f 2a 20 56 65 72 73 69 6f 6e 20 6e 6f 74 20 /* Version not
10f0: 66 6f 75 6e 64 2e 20 52 65 74 75 72 6e 20 6e 6f found. Return no
1100: 6e 2d 30 20 65 78 69 74 20 63 6f 64 65 20 2a 2f n-0 exit code */
1110: 0a 0a 09 63 61 73 65 20 27 51 27 3a 0a 09 20 20 ...case 'Q':..
1120: 20 20 69 66 20 28 61 72 67 63 20 21 3d 20 33 29 if (argc != 3)
1130: 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e 70 {...chars = snp
1140: 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f rintf(msg, sizeo
1150: 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 20 20 f(msg) - 1,...
1160: 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 51 20 "usage: %s -Q
1170: 70 61 74 68 5c 6e 22 0a 09 09 20 20 20 20 22 45 path\n"... "E
1180: 6d 69 74 20 74 68 65 20 66 75 6c 6c 79 20 71 75 mit the fully qu
1190: 61 6c 69 66 69 65 64 20 70 61 74 68 5c 6e 22 0a alified path\n".
11a0: 09 09 20 20 20 20 22 65 78 69 74 63 6f 64 65 73 .. "exitcodes
11b0: 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 : 0 == no, 1 ==
11c0: 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 5c yes, 2 == error\
11d0: 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 n", argv[0]);...
11e0: 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 WriteFile(GetStd
11f0: 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 Handle(STD_ERROR
1200: 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 _HANDLE), msg, c
1210: 68 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57 hars,... &dwW
1220: 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 ritten, NULL);..
1230: 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 .return 2;..
1240: 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 51 75 }.. return Qu
1250: 61 6c 69 66 79 50 61 74 68 28 61 72 67 76 5b 32 alifyPath(argv[2
1260: 5d 29 3b 0a 0a 09 63 61 73 65 20 27 4c 27 3a 0a ]);...case 'L':.
1270: 09 20 20 20 20 69 66 20 28 61 72 67 63 20 21 3d . if (argc !=
1280: 20 33 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 3) {...chars =
1290: 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 snprintf(msg, si
12a0: 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 zeof(msg) - 1,..
12b0: 09 20 20 20 20 22 75 73 61 67 65 3a 20 25 73 20 . "usage: %s
12c0: 2d 4c 20 6b 65 79 70 61 74 68 5c 6e 22 0a 09 09 -L keypath\n"...
12d0: 20 20 20 20 22 45 6d 69 74 20 74 68 65 20 66 75 "Emit the fu
12e0: 6c 6c 79 20 71 75 61 6c 69 66 69 65 64 20 70 61 lly qualified pa
12f0: 74 68 20 6f 66 20 64 69 72 65 63 74 6f 72 79 20 th of directory
1300: 63 6f 6e 74 61 69 6e 69 6e 67 20 6b 65 79 70 61 containing keypa
1310: 74 68 5c 6e 22 0a 09 09 20 20 20 20 22 65 78 69 th\n"... "exi
1320: 74 63 6f 64 65 73 3a 20 30 20 3d 3d 20 73 75 63 tcodes: 0 == suc
1330: 63 65 73 73 2c 20 31 20 3d 3d 20 6e 6f 74 20 66 cess, 1 == not f
1340: 6f 75 6e 64 2c 20 32 20 3d 3d 20 65 72 72 6f 72 ound, 2 == error
1350: 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 \n", argv[0]);..
1360: 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 .WriteFile(GetSt
1370: 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f dHandle(STD_ERRO
1380: 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 R_HANDLE), msg,
1390: 63 68 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 chars,... &dw
13a0: 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a Written, NULL);.
13b0: 09 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 ..return 2;..
13c0: 20 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 4c }.. return L
13d0: 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 28 ocateDependency(
13e0: 61 72 67 76 5b 32 5d 29 3b 0a 09 7d 0a 20 20 20 argv[2]);..}.
13f0: 20 7d 0a 20 20 20 20 63 68 61 72 73 20 3d 20 73 }. chars = s
1400: 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a nprintf(msg, siz
1410: 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 20 eof(msg) - 1,..
1420: 20 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 63 "usage: %s -c
1430: 7c 2d 66 7c 2d 6c 7c 2d 51 7c 2d 73 7c 2d 56 20 |-f|-l|-Q|-s|-V
1440: 2e 2e 2e 5c 6e 22 0a 09 20 20 20 20 22 54 68 69 ...\n".. "Thi
1450: 73 20 69 73 20 61 20 6c 69 74 74 6c 65 20 68 65 s is a little he
1460: 6c 70 65 72 20 61 70 70 20 74 6f 20 65 71 75 61 lper app to equa
1470: 6c 69 7a 65 20 73 68 65 6c 6c 20 64 69 66 66 65 lize shell diffe
1480: 72 65 6e 63 65 73 20 62 65 74 77 65 65 6e 20 57 rences between W
1490: 69 6e 4e 54 20 61 6e 64 5c 6e 22 0a 09 20 20 20 inNT and\n"..
14a0: 20 22 57 69 6e 39 78 20 61 6e 64 20 67 65 74 20 "Win9x and get
14b0: 6e 6d 61 6b 65 2e 65 78 65 20 74 6f 20 61 63 63 nmake.exe to acc
14c0: 6f 6d 70 6c 69 73 68 20 69 74 73 20 6a 6f 62 2e omplish its job.
14d0: 5c 6e 22 2c 0a 09 20 20 20 20 61 72 67 76 5b 30 \n",.. argv[0
14e0: 5d 29 3b 0a 20 20 20 20 57 72 69 74 65 46 69 6c ]);. WriteFil
14f0: 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53 e(GetStdHandle(S
1500: 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 TD_ERROR_HANDLE)
1510: 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 20 26 64 , msg, chars, &d
1520: 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b wWritten, NULL);
1530: 0a 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 7d . return 2;.}
1540: 0a 0c 0a 73 74 61 74 69 63 20 69 6e 74 0a 43 68 ...static int.Ch
1550: 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 eckForCompilerFe
1560: 61 74 75 72 65 28 0a 20 20 20 20 63 6f 6e 73 74 ature(. const
1570: 20 63 68 61 72 20 2a 6f 70 74 69 6f 6e 29 0a 7b char *option).{
1580: 0a 20 20 20 20 53 54 41 52 54 55 50 49 4e 46 4f . STARTUPINFO
1590: 20 73 69 3b 0a 20 20 20 20 50 52 4f 43 45 53 53 si;. PROCESS
15a0: 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 70 69 3b _INFORMATION pi;
15b0: 0a 20 20 20 20 53 45 43 55 52 49 54 59 5f 41 54 . SECURITY_AT
15c0: 54 52 49 42 55 54 45 53 20 73 61 3b 0a 20 20 20 TRIBUTES sa;.
15d0: 20 44 57 4f 52 44 20 74 68 72 65 61 64 49 44 3b DWORD threadID;
15e0: 0a 20 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 . char msg[30
15f0: 30 5d 3b 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0];. BOOL ok;
1600: 0a 20 20 20 20 48 41 4e 44 4c 45 20 68 50 72 6f . HANDLE hPro
1610: 63 65 73 73 2c 20 68 2c 20 70 69 70 65 54 68 72 cess, h, pipeThr
1620: 65 61 64 73 5b 32 5d 3b 0a 20 20 20 20 63 68 61 eads[2];. cha
1630: 72 20 63 6d 64 6c 69 6e 65 5b 31 30 30 5d 3b 0a r cmdline[100];.
1640: 0a 20 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20 . hProcess =
1650: 47 65 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73 GetCurrentProces
1660: 73 28 29 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 s();.. memset
1670: 28 26 70 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28 (&pi, 0, sizeof(
1680: 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 PROCESS_INFORMAT
1690: 49 4f 4e 29 29 3b 0a 20 20 20 20 6d 65 6d 73 65 ION));. memse
16a0: 74 28 26 73 69 2c 20 30 2c 20 73 69 7a 65 6f 66 t(&si, 0, sizeof
16b0: 28 53 54 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a (STARTUPINFO));.
16c0: 20 20 20 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 si.cb = size
16d0: 6f 66 28 53 54 41 52 54 55 50 49 4e 46 4f 29 3b of(STARTUPINFO);
16e0: 0a 20 20 20 20 73 69 2e 64 77 46 6c 61 67 73 20 . si.dwFlags
16f0: 20 20 3d 20 53 54 41 52 54 46 5f 55 53 45 53 54 = STARTF_USEST
1700: 44 48 41 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 DHANDLES;. si
1710: 2e 68 53 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 .hStdInput = INV
1720: 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 ALID_HANDLE_VALU
1730: 45 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26 E;.. memset(&
1740: 73 61 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 45 sa, 0, sizeof(SE
1750: 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 CURITY_ATTRIBUTE
1760: 53 29 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e S));. sa.nLen
1770: 67 74 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43 gth = sizeof(SEC
1780: 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 URITY_ATTRIBUTES
1790: 29 3b 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75 );. sa.lpSecu
17a0: 72 69 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d rityDescriptor =
17b0: 20 4e 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49 NULL;. sa.bI
17c0: 6e 68 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 46 nheritHandle = F
17d0: 41 4c 53 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 ALSE;.. /*.
17e0: 20 20 20 2a 20 43 72 65 61 74 65 20 61 20 6e 6f * Create a no
17f0: 6e 2d 69 6e 68 65 72 69 74 61 62 6c 65 20 70 69 n-inheritable pi
1800: 70 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 pe.. */..
1810: 20 43 72 65 61 74 65 50 69 70 65 28 26 4f 75 74 CreatePipe(&Out
1820: 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 .pipe, &h, &sa,
1830: 30 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 0);.. /*.
1840: 20 2a 20 44 75 70 65 20 74 68 65 20 77 72 69 74 * Dupe the writ
1850: 65 20 73 69 64 65 2c 20 6d 61 6b 65 20 69 74 20 e side, make it
1860: 69 6e 68 65 72 69 74 61 62 6c 65 2c 20 61 6e 64 inheritable, and
1870: 20 63 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 69 close the origi
1880: 6e 61 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 nal.. */..
1890: 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c DuplicateHandl
18a0: 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 e(hProcess, h, h
18b0: 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 Process, &si.hSt
18c0: 64 4f 75 74 70 75 74 2c 20 30 2c 20 54 52 55 45 dOutput, 0, TRUE
18d0: 2c 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 ,.. DUPLICATE
18e0: 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 _SAME_ACCESS | D
18f0: 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 UPLICATE_CLOSE_S
1900: 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a OURCE);.. /*.
1910: 20 20 20 20 20 2a 20 53 61 6d 65 20 61 73 20 61 * Same as a
1920: 62 6f 76 65 2c 20 62 75 74 20 66 6f 72 20 74 68 bove, but for th
1930: 65 20 65 72 72 6f 72 20 73 69 64 65 2e 0a 20 20 e error side..
1940: 20 20 20 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 */.. Creat
1950: 65 50 69 70 65 28 26 45 72 72 2e 70 69 70 65 2c ePipe(&Err.pipe,
1960: 20 26 68 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20 &h, &sa, 0);.
1970: 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c DuplicateHandl
1980: 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 e(hProcess, h, h
1990: 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 Process, &si.hSt
19a0: 64 45 72 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c dError, 0, TRUE,
19b0: 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f .. DUPLICATE_
19c0: 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 SAME_ACCESS | DU
19d0: 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f PLICATE_CLOSE_SO
19e0: 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 URCE);.. /*.
19f0: 20 20 20 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61 * Base comma
1a00: 6e 64 20 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f nd line.. */
1a10: 0a 0a 20 20 20 20 6c 73 74 72 63 70 79 28 63 6d .. lstrcpy(cm
1a20: 64 6c 69 6e 65 2c 20 22 63 6c 2e 65 78 65 20 2d dline, "cl.exe -
1a30: 6e 6f 6c 6f 67 6f 20 2d 63 20 2d 54 43 20 2d 5a nologo -c -TC -Z
1a40: 73 20 2d 58 20 2d 46 70 2e 5c 5c 5f 6a 75 6e 6b s -X -Fp.\\_junk
1a50: 2e 70 63 68 20 22 29 3b 0a 0a 20 20 20 20 2f 2a .pch ");.. /*
1a60: 0a 20 20 20 20 20 2a 20 41 70 70 65 6e 64 20 6f . * Append o
1a70: 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 65 ur option for te
1a80: 73 74 69 6e 67 0a 20 20 20 20 20 2a 2f 0a 0a 20 sting. */..
1a90: 20 20 20 6c 73 74 72 63 61 74 28 63 6d 64 6c 69 lstrcat(cmdli
1aa0: 6e 65 2c 20 6f 70 74 69 6f 6e 29 3b 0a 0a 20 20 ne, option);..
1ab0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 46 69 6c 65 /*. * File
1ac0: 6e 61 6d 65 20 74 6f 20 63 6f 6d 70 69 6c 65 2c name to compile,
1ad0: 20 77 68 69 63 68 20 65 78 69 73 74 73 2c 20 62 which exists, b
1ae0: 75 74 20 69 73 20 6e 6f 74 68 69 6e 67 20 61 6e ut is nothing an
1af0: 64 20 65 6d 70 74 79 2e 0a 20 20 20 20 20 2a 2f d empty.. */
1b00: 0a 0a 20 20 20 20 6c 73 74 72 63 61 74 28 63 6d .. lstrcat(cm
1b10: 64 6c 69 6e 65 2c 20 22 20 2e 5c 5c 6e 75 6c 22 dline, " .\\nul"
1b20: 29 3b 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 65 );.. ok = Cre
1b30: 61 74 65 50 72 6f 63 65 73 73 28 0a 09 20 20 20 ateProcess(..
1b40: 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d 6f NULL,. /* Mo
1b50: 64 75 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 20 dule name. */..
1b60: 20 20 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 20 cmdline,.
1b70: 2f 2a 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e /* Command line.
1b80: 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 */.. NULL,.
1b90: 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 61 /* Process ha
1ba0: 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 74 ndle not inherit
1bb0: 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 able. */.. NU
1bc0: 4c 4c 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 61 LL,. /* Threa
1bd0: 64 20 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 d handle not inh
1be0: 65 72 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 eritable. */..
1bf0: 20 20 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 79 TRUE,. /* y
1c00: 65 73 2c 20 69 6e 68 65 72 69 74 20 68 61 6e 64 es, inherit hand
1c10: 6c 65 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 54 les. */.. DET
1c20: 41 43 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 2f ACHED_PROCESS, /
1c30: 2a 20 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f 72 * No console for
1c40: 20 79 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 you. */.. NU
1c50: 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 70 LL,. /* Use p
1c60: 61 72 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e 6d arent's environm
1c70: 65 6e 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 20 ent block. */..
1c80: 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 NULL,. /*
1c90: 55 73 65 20 70 61 72 65 6e 74 27 73 20 73 74 61 Use parent's sta
1ca0: 72 74 69 6e 67 20 64 69 72 65 63 74 6f 72 79 2e rting directory.
1cb0: 20 2a 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 20 */.. &si,.
1cc0: 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 /* Pointer to
1cd0: 53 54 41 52 54 55 50 49 4e 46 4f 20 73 74 72 75 STARTUPINFO stru
1ce0: 63 74 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 26 cture. */.. &
1cf0: 70 69 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 6e pi);. /* Poin
1d00: 74 65 72 20 74 6f 20 50 52 4f 43 45 53 53 5f 49 ter to PROCESS_I
1d10: 4e 46 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 63 NFORMATION struc
1d20: 74 75 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 66 ture. */.. if
1d30: 20 28 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 20 (!ok) {..DWORD
1d40: 65 72 72 20 3d 20 47 65 74 4c 61 73 74 45 72 72 err = GetLastErr
1d50: 6f 72 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 73 or();..int chars
1d60: 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c = snprintf(msg,
1d70: 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 sizeof(msg) - 1
1d80: 2c 0a 09 09 22 54 72 69 65 64 20 74 6f 20 6c 61 ,..."Tried to la
1d90: 75 6e 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 75 unch: \"%s\", bu
1da0: 74 20 67 6f 74 20 65 72 72 6f 72 20 5b 25 75 5d t got error [%u]
1db0: 3a 20 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65 72 : ", cmdline, er
1dc0: 72 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73 73 r);...FormatMess
1dd0: 61 67 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53 41 age(FORMAT_MESSA
1de0: 47 45 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c 46 GE_FROM_SYSTEM|F
1df0: 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49 47 ORMAT_MESSAGE_IG
1e00: 4e 4f 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09 09 NORE_INSERTS|...
1e10: 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 4d FORMAT_MESSAGE_M
1e20: 41 58 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20 30 AX_WIDTH_MASK, 0
1e30: 4c 2c 20 65 72 72 2c 20 30 2c 20 28 4c 50 53 54 L, err, 0, (LPST
1e40: 52 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c 0a 09 R)&msg[chars],..
1e50: 09 28 33 30 30 2d 63 68 61 72 73 29 2c 20 30 29 .(300-chars), 0)
1e60: 3b 0a 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 ;..WriteFile(Get
1e70: 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 StdHandle(STD_ER
1e80: 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 ROR_HANDLE), msg
1e90: 2c 20 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c 20 , lstrlen(msg),
1ea0: 26 65 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65 74 &err,NULL);..ret
1eb0: 75 72 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 20 urn 2;. }..
1ec0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f 73 /*. * Clos
1ed0: 65 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65 73 e our references
1ee0: 20 74 6f 20 74 68 65 20 77 72 69 74 65 20 68 61 to the write ha
1ef0: 6e 64 6c 65 73 20 74 68 61 74 20 68 61 76 65 20 ndles that have
1f00: 6e 6f 77 20 62 65 65 6e 20 69 6e 68 65 72 69 74 now been inherit
1f10: 65 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ed.. */..
1f20: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e CloseHandle(si.
1f30: 68 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 20 hStdOutput);.
1f40: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e CloseHandle(si.
1f50: 68 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 20 hStdError);..
1f60: 20 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64 6c WaitForInputIdl
1f70: 65 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 35 e(pi.hProcess, 5
1f80: 30 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 000);. CloseH
1f90: 61 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61 64 andle(pi.hThread
1fa0: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
1fb0: 2a 20 53 74 61 72 74 20 74 68 65 20 70 69 70 65 * Start the pipe
1fc0: 20 72 65 61 64 65 72 20 74 68 72 65 61 64 73 2e reader threads.
1fd0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70 69 . */.. pi
1fe0: 70 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 43 peThreads[0] = C
1ff0: 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c reateThread(NULL
2000: 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 , 0, ReadFromPip
2010: 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 72 e, &Out, 0, &thr
2020: 65 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70 65 eadID);. pipe
2030: 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 65 Threads[1] = Cre
2040: 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 ateThread(NULL,
2050: 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 2c 0, ReadFromPipe,
2060: 20 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65 61 &Err, 0, &threa
2070: 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 dID);.. /*.
2080: 20 20 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74 69 * Block waiti
2090: 6e 67 20 66 6f 72 20 74 68 65 20 70 72 6f 63 65 ng for the proce
20a0: 73 73 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20 20 ss to end..
20b0: 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f 72 53 */.. WaitForS
20c0: 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e 68 ingleObject(pi.h
20d0: 50 72 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49 54 Process, INFINIT
20e0: 45 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e E);. CloseHan
20f0: 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 29 dle(pi.hProcess)
2100: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
2110: 20 57 61 69 74 20 66 6f 72 20 6f 75 72 20 70 69 Wait for our pi
2120: 70 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 72 pe to get done r
2130: 65 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 69 eading, should i
2140: 74 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73 6c t be a little sl
2150: 6f 77 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ow.. */..
2160: 20 57 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c 65 WaitForMultiple
2170: 4f 62 6a 65 63 74 73 28 32 2c 20 70 69 70 65 54 Objects(2, pipeT
2180: 68 72 65 61 64 73 2c 20 54 52 55 45 2c 20 35 30 hreads, TRUE, 50
2190: 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 0);. CloseHan
21a0: 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 5b dle(pipeThreads[
21b0: 30 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 0]);. CloseHa
21c0: 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 ndle(pipeThreads
21d0: 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 [1]);.. /*.
21e0: 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74 68 * Look for th
21f0: 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77 61 e commandline wa
2200: 72 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 62 6f rning code in bo
2210: 74 68 20 73 74 72 65 61 6d 73 2e 0a 20 20 20 20 th streams..
2220: 20 2a 20 20 2d 20 69 6e 20 4d 53 56 43 20 36 20 * - in MSVC 6
2230: 26 20 37 20 77 65 20 67 65 74 20 44 34 30 30 32 & 7 we get D4002
2240: 2c 20 69 6e 20 4d 53 56 43 20 38 20 77 65 20 67 , in MSVC 8 we g
2250: 65 74 20 44 39 30 30 32 2e 0a 20 20 20 20 20 2a et D9002.. *
2260: 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 21 28 /.. return !(
2270: 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 strstr(Out.buffe
2280: 72 2c 20 22 44 34 30 30 32 22 29 20 21 3d 20 4e r, "D4002") != N
2290: 55 4c 4c 0a 09 20 20 20 20 7c 7c 20 73 74 72 73 ULL.. || strs
22a0: 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 tr(Err.buffer, "
22b0: 44 34 30 30 32 22 29 20 21 3d 20 4e 55 4c 4c 0a D4002") != NULL.
22c0: 09 20 20 20 20 7c 7c 20 73 74 72 73 74 72 28 4f . || strstr(O
22d0: 75 74 2e 62 75 66 66 65 72 2c 20 22 44 39 30 30 ut.buffer, "D900
22e0: 32 22 29 20 21 3d 20 4e 55 4c 4c 0a 09 20 20 20 2") != NULL..
22f0: 20 7c 7c 20 73 74 72 73 74 72 28 45 72 72 2e 62 || strstr(Err.b
2300: 75 66 66 65 72 2c 20 22 44 39 30 30 32 22 29 20 uffer, "D9002")
2310: 21 3d 20 4e 55 4c 4c 0a 09 20 20 20 20 7c 7c 20 != NULL.. ||
2320: 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 strstr(Out.buffe
2330: 72 2c 20 22 44 32 30 32 31 22 29 20 21 3d 20 4e r, "D2021") != N
2340: 55 4c 4c 0a 09 20 20 20 20 7c 7c 20 73 74 72 73 ULL.. || strs
2350: 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 tr(Err.buffer, "
2360: 44 32 30 32 31 22 29 20 21 3d 20 4e 55 4c 4c 29 D2021") != NULL)
2370: 3b 0a 7d 0a 0c 0a 73 74 61 74 69 63 20 69 6e 74 ;.}...static int
2380: 0a 43 68 65 63 6b 46 6f 72 4c 69 6e 6b 65 72 46 .CheckForLinkerF
2390: 65 61 74 75 72 65 28 0a 20 20 20 20 63 68 61 72 eature(. char
23a0: 20 2a 2a 6f 70 74 69 6f 6e 73 2c 0a 20 20 20 20 **options,.
23b0: 69 6e 74 20 63 6f 75 6e 74 29 0a 7b 0a 20 20 20 int count).{.
23c0: 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 69 3b STARTUPINFO si;
23d0: 0a 20 20 20 20 50 52 4f 43 45 53 53 5f 49 4e 46 . PROCESS_INF
23e0: 4f 52 4d 41 54 49 4f 4e 20 70 69 3b 0a 20 20 20 ORMATION pi;.
23f0: 20 53 45 43 55 52 49 54 59 5f 41 54 54 52 49 42 SECURITY_ATTRIB
2400: 55 54 45 53 20 73 61 3b 0a 20 20 20 20 44 57 4f UTES sa;. DWO
2410: 52 44 20 74 68 72 65 61 64 49 44 3b 0a 20 20 20 RD threadID;.
2420: 20 63 68 61 72 20 6d 73 67 5b 33 30 30 5d 3b 0a char msg[300];.
2430: 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 20 20 20 BOOL ok;.
2440: 20 48 41 4e 44 4c 45 20 68 50 72 6f 63 65 73 73 HANDLE hProcess
2450: 2c 20 68 2c 20 70 69 70 65 54 68 72 65 61 64 73 , h, pipeThreads
2460: 5b 32 5d 3b 0a 20 20 20 20 69 6e 74 20 69 3b 0a [2];. int i;.
2470: 20 20 20 20 63 68 61 72 20 63 6d 64 6c 69 6e 65 char cmdline
2480: 5b 32 35 35 5d 3b 0a 0a 20 20 20 20 68 50 72 6f [255];.. hPro
2490: 63 65 73 73 20 3d 20 47 65 74 43 75 72 72 65 6e cess = GetCurren
24a0: 74 50 72 6f 63 65 73 73 28 29 3b 0a 0a 20 20 20 tProcess();..
24b0: 20 6d 65 6d 73 65 74 28 26 70 69 2c 20 30 2c 20 memset(&pi, 0,
24c0: 73 69 7a 65 6f 66 28 50 52 4f 43 45 53 53 5f 49 sizeof(PROCESS_I
24d0: 4e 46 4f 52 4d 41 54 49 4f 4e 29 29 3b 0a 20 20 NFORMATION));.
24e0: 20 20 6d 65 6d 73 65 74 28 26 73 69 2c 20 30 2c memset(&si, 0,
24f0: 20 73 69 7a 65 6f 66 28 53 54 41 52 54 55 50 49 sizeof(STARTUPI
2500: 4e 46 4f 29 29 3b 0a 20 20 20 20 73 69 2e 63 62 NFO));. si.cb
2510: 20 3d 20 73 69 7a 65 6f 66 28 53 54 41 52 54 55 = sizeof(STARTU
2520: 50 49 4e 46 4f 29 3b 0a 20 20 20 20 73 69 2e 64 PINFO);. si.d
2530: 77 46 6c 61 67 73 20 20 20 3d 20 53 54 41 52 54 wFlags = START
2540: 46 5f 55 53 45 53 54 44 48 41 4e 44 4c 45 53 3b F_USESTDHANDLES;
2550: 0a 20 20 20 20 73 69 2e 68 53 74 64 49 6e 70 75 . si.hStdInpu
2560: 74 20 3d 20 49 4e 56 41 4c 49 44 5f 48 41 4e 44 t = INVALID_HAND
2570: 4c 45 5f 56 41 4c 55 45 3b 0a 0a 20 20 20 20 6d LE_VALUE;.. m
2580: 65 6d 73 65 74 28 26 73 61 2c 20 30 2c 20 73 69 emset(&sa, 0, si
2590: 7a 65 6f 66 28 53 45 43 55 52 49 54 59 5f 41 54 zeof(SECURITY_AT
25a0: 54 52 49 42 55 54 45 53 29 29 3b 0a 20 20 20 20 TRIBUTES));.
25b0: 73 61 2e 6e 4c 65 6e 67 74 68 20 3d 20 73 69 7a sa.nLength = siz
25c0: 65 6f 66 28 53 45 43 55 52 49 54 59 5f 41 54 54 eof(SECURITY_ATT
25d0: 52 49 42 55 54 45 53 29 3b 0a 20 20 20 20 73 61 RIBUTES);. sa
25e0: 2e 6c 70 53 65 63 75 72 69 74 79 44 65 73 63 72 .lpSecurityDescr
25f0: 69 70 74 6f 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 iptor = NULL;.
2600: 20 20 73 61 2e 62 49 6e 68 65 72 69 74 48 61 6e sa.bInheritHan
2610: 64 6c 65 20 3d 20 54 52 55 45 3b 0a 0a 20 20 20 dle = TRUE;..
2620: 20 2f 2a 0a 20 20 20 20 20 2a 20 43 72 65 61 74 /*. * Creat
2630: 65 20 61 20 6e 6f 6e 2d 69 6e 68 65 72 69 74 69 e a non-inheriti
2640: 62 6c 65 20 70 69 70 65 2e 0a 20 20 20 20 20 2a ble pipe.. *
2650: 2f 0a 0a 20 20 20 20 43 72 65 61 74 65 50 69 70 /.. CreatePip
2660: 65 28 26 4f 75 74 2e 70 69 70 65 2c 20 26 68 2c e(&Out.pipe, &h,
2670: 20 26 73 61 2c 20 30 29 3b 0a 0a 20 20 20 20 2f &sa, 0);.. /
2680: 2a 0a 20 20 20 20 20 2a 20 44 75 70 65 20 74 68 *. * Dupe th
2690: 65 20 77 72 69 74 65 20 73 69 64 65 2c 20 6d 61 e write side, ma
26a0: 6b 65 20 69 74 20 69 6e 68 65 72 69 74 61 62 6c ke it inheritabl
26b0: 65 2c 20 61 6e 64 20 63 6c 6f 73 65 20 74 68 65 e, and close the
26c0: 20 6f 72 69 67 69 6e 61 6c 2e 0a 20 20 20 20 20 original..
26d0: 2a 2f 0a 0a 20 20 20 20 44 75 70 6c 69 63 61 74 */.. Duplicat
26e0: 65 48 61 6e 64 6c 65 28 68 50 72 6f 63 65 73 73 eHandle(hProcess
26f0: 2c 20 68 2c 20 68 50 72 6f 63 65 73 73 2c 20 26 , h, hProcess, &
2700: 73 69 2e 68 53 74 64 4f 75 74 70 75 74 2c 20 30 si.hStdOutput, 0
2710: 2c 20 54 52 55 45 2c 0a 09 20 20 20 20 44 55 50 , TRUE,.. DUP
2720: 4c 49 43 41 54 45 5f 53 41 4d 45 5f 41 43 43 45 LICATE_SAME_ACCE
2730: 53 53 20 7c 20 44 55 50 4c 49 43 41 54 45 5f 43 SS | DUPLICATE_C
2740: 4c 4f 53 45 5f 53 4f 55 52 43 45 29 3b 0a 0a 20 LOSE_SOURCE);..
2750: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 53 61 6d /*. * Sam
2760: 65 20 61 73 20 61 62 6f 76 65 2c 20 62 75 74 20 e as above, but
2770: 66 6f 72 20 74 68 65 20 65 72 72 6f 72 20 73 69 for the error si
2780: 64 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 de.. */..
2790: 20 43 72 65 61 74 65 50 69 70 65 28 26 45 72 72 CreatePipe(&Err
27a0: 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 .pipe, &h, &sa,
27b0: 30 29 3b 0a 20 20 20 20 44 75 70 6c 69 63 61 74 0);. Duplicat
27c0: 65 48 61 6e 64 6c 65 28 68 50 72 6f 63 65 73 73 eHandle(hProcess
27d0: 2c 20 68 2c 20 68 50 72 6f 63 65 73 73 2c 20 26 , h, hProcess, &
27e0: 73 69 2e 68 53 74 64 45 72 72 6f 72 2c 20 30 2c si.hStdError, 0,
27f0: 20 54 52 55 45 2c 0a 09 20 20 20 20 44 55 50 4c TRUE,.. DUPL
2800: 49 43 41 54 45 5f 53 41 4d 45 5f 41 43 43 45 53 ICATE_SAME_ACCES
2810: 53 20 7c 20 44 55 50 4c 49 43 41 54 45 5f 43 4c S | DUPLICATE_CL
2820: 4f 53 45 5f 53 4f 55 52 43 45 29 3b 0a 0a 20 20 OSE_SOURCE);..
2830: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 42 61 73 65 /*. * Base
2840: 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 0a 20 command line..
2850: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 6c 73 74 72 */.. lstr
2860: 63 70 79 28 63 6d 64 6c 69 6e 65 2c 20 22 6c 69 cpy(cmdline, "li
2870: 6e 6b 2e 65 78 65 20 2d 6e 6f 6c 6f 67 6f 20 22 nk.exe -nologo "
2880: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
2890: 2a 20 41 70 70 65 6e 64 20 6f 75 72 20 6f 70 74 * Append our opt
28a0: 69 6f 6e 20 66 6f 72 20 74 65 73 74 69 6e 67 2e ion for testing.
28b0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 66 6f . */.. fo
28c0: 72 20 28 69 20 3d 20 30 3b 20 69 20 3c 20 63 6f r (i = 0; i < co
28d0: 75 6e 74 3b 20 69 2b 2b 29 20 7b 0a 09 6c 73 74 unt; i++) {..lst
28e0: 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 22 20 rcat(cmdline, "
28f0: 5c 22 22 29 3b 0a 09 6c 73 74 72 63 61 74 28 63 \"");..lstrcat(c
2900: 6d 64 6c 69 6e 65 2c 20 6f 70 74 69 6f 6e 73 5b mdline, options[
2910: 69 5d 29 3b 0a 09 6c 73 74 72 63 61 74 28 63 6d i]);..lstrcat(cm
2920: 64 6c 69 6e 65 2c 20 22 5c 22 22 29 3b 0a 20 20 dline, "\"");.
2930: 20 20 7d 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 }.. ok = Cr
2940: 65 61 74 65 50 72 6f 63 65 73 73 28 0a 09 20 20 eateProcess(..
2950: 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d NULL,. /* M
2960: 6f 64 75 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 odule name. */..
2970: 20 20 20 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 cmdline,.
2980: 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 /* Command line
2990: 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 . */.. NULL,.
29a0: 20 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 /* Process h
29b0: 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 andle not inheri
29c0: 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e table. */.. N
29d0: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 ULL,. /* Thre
29e0: 61 64 20 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e ad handle not in
29f0: 68 65 72 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 heritable. */..
2a00: 20 20 20 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 TRUE,. /*
2a10: 79 65 73 2c 20 69 6e 68 65 72 69 74 20 68 61 6e yes, inherit han
2a20: 64 6c 65 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 dles. */.. DE
2a30: 54 41 43 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 TACHED_PROCESS,
2a40: 2f 2a 20 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f /* No console fo
2a50: 72 20 79 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e r you. */.. N
2a60: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 ULL,. /* Use
2a70: 70 61 72 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e parent's environ
2a80: 6d 65 6e 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 ment block. */..
2a90: 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a NULL,. /*
2aa0: 20 55 73 65 20 70 61 72 65 6e 74 27 73 20 73 74 Use parent's st
2ab0: 61 72 74 69 6e 67 20 64 69 72 65 63 74 6f 72 79 arting directory
2ac0: 2e 20 2a 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 . */.. &si,.
2ad0: 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f /* Pointer to
2ae0: 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 74 72 STARTUPINFO str
2af0: 75 63 74 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 ucture. */..
2b00: 26 70 69 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 &pi);. /* Poi
2b10: 6e 74 65 72 20 74 6f 20 50 52 4f 43 45 53 53 5f nter to PROCESS_
2b20: 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 INFORMATION stru
2b30: 63 74 75 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 cture. */.. i
2b40: 66 20 28 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 f (!ok) {..DWORD
2b50: 20 65 72 72 20 3d 20 47 65 74 4c 61 73 74 45 72 err = GetLastEr
2b60: 72 6f 72 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 ror();..int char
2b70: 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 s = snprintf(msg
2b80: 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 , sizeof(msg) -
2b90: 31 2c 0a 09 09 22 54 72 69 65 64 20 74 6f 20 6c 1,..."Tried to l
2ba0: 61 75 6e 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 aunch: \"%s\", b
2bb0: 75 74 20 67 6f 74 20 65 72 72 6f 72 20 5b 25 75 ut got error [%u
2bc0: 5d 3a 20 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65 ]: ", cmdline, e
2bd0: 72 72 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73 rr);...FormatMes
2be0: 73 61 67 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53 sage(FORMAT_MESS
2bf0: 41 47 45 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c AGE_FROM_SYSTEM|
2c00: 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49 FORMAT_MESSAGE_I
2c10: 47 4e 4f 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09 GNORE_INSERTS|..
2c20: 09 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f .FORMAT_MESSAGE_
2c30: 4d 41 58 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20 MAX_WIDTH_MASK,
2c40: 30 4c 2c 20 65 72 72 2c 20 30 2c 20 28 4c 50 53 0L, err, 0, (LPS
2c50: 54 52 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c 0a TR)&msg[chars],.
2c60: 09 09 28 33 30 30 2d 63 68 61 72 73 29 2c 20 30 ..(300-chars), 0
2c70: 29 3b 0a 09 57 72 69 74 65 46 69 6c 65 28 47 65 );..WriteFile(Ge
2c80: 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 tStdHandle(STD_E
2c90: 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 RROR_HANDLE), ms
2ca0: 67 2c 20 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c g, lstrlen(msg),
2cb0: 20 26 65 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65 &err,NULL);..re
2cc0: 74 75 72 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 turn 2;. }..
2cd0: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f /*. * Clo
2ce0: 73 65 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65 se our reference
2cf0: 73 20 74 6f 20 74 68 65 20 77 72 69 74 65 20 68 s to the write h
2d00: 61 6e 64 6c 65 73 20 74 68 61 74 20 68 61 76 65 andles that have
2d10: 20 6e 6f 77 20 62 65 65 6e 20 69 6e 68 65 72 69 now been inheri
2d20: 74 65 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 ted.. */..
2d30: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 CloseHandle(si
2d40: 2e 68 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 .hStdOutput);.
2d50: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 CloseHandle(si
2d60: 2e 68 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 .hStdError);..
2d70: 20 20 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64 WaitForInputId
2d80: 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 le(pi.hProcess,
2d90: 35 30 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 5000);. Close
2da0: 48 61 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61 Handle(pi.hThrea
2db0: 64 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 d);.. /*.
2dc0: 20 2a 20 53 74 61 72 74 20 74 68 65 20 70 69 70 * Start the pip
2dd0: 65 20 72 65 61 64 65 72 20 74 68 72 65 61 64 73 e reader threads
2de0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70 .. */.. p
2df0: 69 70 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 ipeThreads[0] =
2e00: 43 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c CreateThread(NUL
2e10: 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 L, 0, ReadFromPi
2e20: 70 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 pe, &Out, 0, &th
2e30: 72 65 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70 readID);. pip
2e40: 65 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 eThreads[1] = Cr
2e50: 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c eateThread(NULL,
2e60: 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 0, ReadFromPipe
2e70: 2c 20 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65 , &Err, 0, &thre
2e80: 61 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 adID);.. /*.
2e90: 20 20 20 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74 * Block wait
2ea0: 69 6e 67 20 66 6f 72 20 74 68 65 20 70 72 6f 63 ing for the proc
2eb0: 65 73 73 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20 ess to end..
2ec0: 20 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f 72 */.. WaitFor
2ed0: 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e SingleObject(pi.
2ee0: 68 50 72 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49 hProcess, INFINI
2ef0: 54 45 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 TE);. CloseHa
2f00: 6e 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 ndle(pi.hProcess
2f10: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
2f20: 2a 20 57 61 69 74 20 66 6f 72 20 6f 75 72 20 70 * Wait for our p
2f30: 69 70 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 ipe to get done
2f40: 72 65 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 reading, should
2f50: 69 74 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73 it be a little s
2f60: 6c 6f 77 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 low.. */..
2f70: 20 20 57 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c WaitForMultipl
2f80: 65 4f 62 6a 65 63 74 73 28 32 2c 20 70 69 70 65 eObjects(2, pipe
2f90: 54 68 72 65 61 64 73 2c 20 54 52 55 45 2c 20 35 Threads, TRUE, 5
2fa0: 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 00);. CloseHa
2fb0: 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 ndle(pipeThreads
2fc0: 5b 30 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 [0]);. CloseH
2fd0: 61 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 andle(pipeThread
2fe0: 73 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 s[1]);.. /*.
2ff0: 20 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74 * Look for t
3000: 68 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77 he commandline w
3010: 61 72 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 74 arning code in t
3020: 68 65 20 73 74 64 65 72 72 20 73 74 72 65 61 6d he stderr stream
3030: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 72 .. */.. r
3040: 65 74 75 72 6e 20 21 28 73 74 72 73 74 72 28 4f eturn !(strstr(O
3050: 75 74 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 31 ut.buffer, "LNK1
3060: 31 31 37 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 117") != NULL ||
3070: 0a 09 20 20 20 20 73 74 72 73 74 72 28 45 72 72 .. strstr(Err
3080: 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 31 31 31 .buffer, "LNK111
3090: 37 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 7") != NULL ||..
30a0: 20 20 20 20 73 74 72 73 74 72 28 4f 75 74 2e 62 strstr(Out.b
30b0: 75 66 66 65 72 2c 20 22 4c 4e 4b 34 30 34 34 22 uffer, "LNK4044"
30c0: 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 ) != NULL ||..
30d0: 20 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 66 strstr(Err.buf
30e0: 66 65 72 2c 20 22 4c 4e 4b 34 30 34 34 22 29 20 fer, "LNK4044")
30f0: 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 != NULL ||..
3100: 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 strstr(Out.buffe
3110: 72 2c 20 22 4c 4e 4b 34 32 32 34 22 29 20 21 3d r, "LNK4224") !=
3120: 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 73 74 NULL ||.. st
3130: 72 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c rstr(Err.buffer,
3140: 20 22 4c 4e 4b 34 32 32 34 22 29 20 21 3d 20 4e "LNK4224") != N
3150: 55 4c 4c 29 3b 0a 7d 0a 0c 0a 73 74 61 74 69 63 ULL);.}...static
3160: 20 44 57 4f 52 44 20 57 49 4e 41 50 49 0a 52 65 DWORD WINAPI.Re
3170: 61 64 46 72 6f 6d 50 69 70 65 28 0a 20 20 20 20 adFromPipe(.
3180: 4c 50 56 4f 49 44 20 61 72 67 73 29 0a 7b 0a 20 LPVOID args).{.
3190: 20 20 20 70 69 70 65 69 6e 66 6f 20 2a 70 69 20 pipeinfo *pi
31a0: 3d 20 28 70 69 70 65 69 6e 66 6f 20 2a 29 20 61 = (pipeinfo *) a
31b0: 72 67 73 3b 0a 20 20 20 20 63 68 61 72 20 2a 6c rgs;. char *l
31c0: 61 73 74 42 75 66 20 3d 20 70 69 2d 3e 62 75 66 astBuf = pi->buf
31d0: 66 65 72 3b 0a 20 20 20 20 44 57 4f 52 44 20 64 fer;. DWORD d
31e0: 77 52 65 61 64 3b 0a 20 20 20 20 42 4f 4f 4c 20 wRead;. BOOL
31f0: 6f 6b 3b 0a 0a 20 20 61 67 61 69 6e 3a 0a 20 20 ok;.. again:.
3200: 20 20 69 66 20 28 6c 61 73 74 42 75 66 20 2d 20 if (lastBuf -
3210: 70 69 2d 3e 62 75 66 66 65 72 20 2b 20 43 48 55 pi->buffer + CHU
3220: 4e 4b 20 3e 20 53 54 41 54 49 43 42 55 46 46 45 NK > STATICBUFFE
3230: 52 53 49 5a 45 29 20 7b 0a 09 43 6c 6f 73 65 48 RSIZE) {..CloseH
3240: 61 6e 64 6c 65 28 70 69 2d 3e 70 69 70 65 29 3b andle(pi->pipe);
3250: 0a 09 72 65 74 75 72 6e 20 28 44 57 4f 52 44 29 ..return (DWORD)
3260: 2d 31 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6f 6b -1;. }. ok
3270: 20 3d 20 52 65 61 64 46 69 6c 65 28 70 69 2d 3e = ReadFile(pi->
3280: 70 69 70 65 2c 20 6c 61 73 74 42 75 66 2c 20 43 pipe, lastBuf, C
3290: 48 55 4e 4b 2c 20 26 64 77 52 65 61 64 2c 20 30 HUNK, &dwRead, 0
32a0: 4c 29 3b 0a 20 20 20 20 69 66 20 28 21 6f 6b 20 L);. if (!ok
32b0: 7c 7c 20 64 77 52 65 61 64 20 3d 3d 20 30 29 20 || dwRead == 0)
32c0: 7b 0a 09 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 {..CloseHandle(p
32d0: 69 2d 3e 70 69 70 65 29 3b 0a 09 72 65 74 75 72 i->pipe);..retur
32e0: 6e 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6c n 0;. }. l
32f0: 61 73 74 42 75 66 20 2b 3d 20 64 77 52 65 61 64 astBuf += dwRead
3300: 3b 0a 20 20 20 20 67 6f 74 6f 20 61 67 61 69 6e ;. goto again
3310: 3b 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b ;.. return 0;
3320: 20 20 2f 2a 20 6d 61 6b 65 73 20 74 68 65 20 63 /* makes the c
3330: 6f 6d 70 69 6c 65 72 20 68 61 70 70 79 20 2a 2f ompiler happy */
3340: 0a 7d 0a 0c 0a 73 74 61 74 69 63 20 69 6e 74 0a .}...static int.
3350: 49 73 49 6e 28 0a 20 20 20 20 63 6f 6e 73 74 20 IsIn(. const
3360: 63 68 61 72 20 2a 73 74 72 69 6e 67 2c 0a 20 20 char *string,.
3370: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 75 const char *su
3380: 62 73 74 72 69 6e 67 29 0a 7b 0a 20 20 20 20 72 bstring).{. r
3390: 65 74 75 72 6e 20 28 73 74 72 73 74 72 28 73 74 eturn (strstr(st
33a0: 72 69 6e 67 2c 20 73 75 62 73 74 72 69 6e 67 29 ring, substring)
33b0: 20 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a 2f != NULL);.}.../
33c0: 2a 0a 20 2a 20 47 65 74 56 65 72 73 69 6f 6e 46 *. * GetVersionF
33d0: 72 6f 6d 46 69 6c 65 20 2d 2d 0a 20 2a 09 4c 6f romFile --. *.Lo
33e0: 6f 6b 73 20 66 6f 72 20 61 20 6d 61 74 63 68 20 oks for a match
33f0: 73 74 72 69 6e 67 20 69 6e 20 61 20 66 69 6c 65 string in a file
3400: 20 61 6e 64 20 74 68 65 6e 20 72 65 74 75 72 6e and then return
3410: 73 20 74 68 65 20 76 65 72 73 69 6f 6e 0a 20 2a s the version. *
3420: 09 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 6d .following the m
3430: 61 74 63 68 20 77 68 65 72 65 20 61 20 76 65 72 atch where a ver
3440: 73 69 6f 6e 20 69 73 20 61 6e 79 74 68 69 6e 67 sion is anything
3450: 20 61 63 63 65 70 74 61 62 6c 65 20 74 6f 0a 20 acceptable to.
3460: 2a 09 70 61 63 6b 61 67 65 20 70 72 6f 76 69 64 *.package provid
3470: 65 20 6f 72 20 70 61 63 6b 61 67 65 20 69 66 6e e or package ifn
3480: 65 65 64 65 64 2e 0a 20 2a 2f 0a 0a 73 74 61 74 eeded.. */..stat
3490: 69 63 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 0a ic const char *.
34a0: 47 65 74 56 65 72 73 69 6f 6e 46 72 6f 6d 46 69 GetVersionFromFi
34b0: 6c 65 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 le(. const ch
34c0: 61 72 20 2a 66 69 6c 65 6e 61 6d 65 2c 0a 20 20 ar *filename,.
34d0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6d 61 const char *ma
34e0: 74 63 68 2c 0a 20 20 20 20 69 6e 74 20 6e 75 6d tch,. int num
34f0: 64 6f 74 73 29 0a 7b 0a 20 20 20 20 73 74 61 74 dots).{. stat
3500: 69 63 20 63 68 61 72 20 73 7a 42 75 66 66 65 72 ic char szBuffer
3510: 5b 31 30 30 5d 3b 0a 20 20 20 20 63 68 61 72 20 [100];. char
3520: 2a 73 7a 52 65 73 75 6c 74 20 3d 20 4e 55 4c 4c *szResult = NULL
3530: 3b 0a 20 20 20 20 46 49 4c 45 20 2a 66 70 20 3d ;. FILE *fp =
3540: 20 66 6f 70 65 6e 28 66 69 6c 65 6e 61 6d 65 2c fopen(filename,
3550: 20 22 72 74 22 29 3b 0a 0a 20 20 20 20 69 66 20 "rt");.. if
3560: 28 66 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 (fp != NULL) {..
3570: 2f 2a 0a 09 20 2a 20 52 65 61 64 20 64 61 74 61 /*.. * Read data
3580: 20 75 6e 74 69 6c 20 77 65 20 73 65 65 20 6f 75 until we see ou
3590: 72 20 6d 61 74 63 68 20 73 74 72 69 6e 67 2e 0a r match string..
35a0: 09 20 2a 2f 0a 0a 09 77 68 69 6c 65 20 28 66 67 . */...while (fg
35b0: 65 74 73 28 73 7a 42 75 66 66 65 72 2c 20 73 69 ets(szBuffer, si
35c0: 7a 65 6f 66 28 73 7a 42 75 66 66 65 72 29 2c 20 zeof(szBuffer),
35d0: 66 70 29 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 fp) != NULL) {..
35e0: 20 20 20 20 4c 50 53 54 52 20 70 2c 20 71 3b 0a LPSTR p, q;.
35f0: 0a 09 20 20 20 20 70 20 3d 20 73 74 72 73 74 72 .. p = strstr
3600: 28 73 7a 42 75 66 66 65 72 2c 20 6d 61 74 63 68 (szBuffer, match
3610: 29 3b 0a 09 20 20 20 20 69 66 20 28 70 20 21 3d );.. if (p !=
3620: 20 4e 55 4c 4c 29 20 7b 0a 09 09 2f 2a 0a 09 09 NULL) {.../*...
3630: 20 2a 20 53 6b 69 70 20 74 6f 20 66 69 72 73 74 * Skip to first
3640: 20 64 69 67 69 74 20 61 66 74 65 72 20 74 68 65 digit after the
3650: 20 6d 61 74 63 68 2e 0a 09 09 20 2a 2f 0a 0a 09 match.... */...
3660: 09 70 20 2b 3d 20 73 74 72 6c 65 6e 28 6d 61 74 .p += strlen(mat
3670: 63 68 29 3b 0a 09 09 77 68 69 6c 65 20 28 2a 70 ch);...while (*p
3680: 20 26 26 20 21 69 73 64 69 67 69 74 28 28 75 6e && !isdigit((un
3690: 73 69 67 6e 65 64 20 63 68 61 72 29 2a 70 29 29 signed char)*p))
36a0: 20 7b 0a 09 09 20 20 20 20 2b 2b 70 3b 0a 09 09 {... ++p;...
36b0: 7d 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20 46 69 6e }..../*... * Fin
36c0: 64 20 65 6e 64 69 6e 67 20 77 68 69 74 65 73 70 d ending whitesp
36d0: 61 63 65 2e 0a 09 09 20 2a 2f 0a 0a 09 09 71 20 ace.... */....q
36e0: 3d 20 70 3b 0a 09 09 77 68 69 6c 65 20 28 2a 71 = p;...while (*q
36f0: 20 26 26 20 28 73 74 72 63 68 72 28 22 30 31 32 && (strchr("012
3700: 33 34 35 36 37 38 39 2e 61 62 22 2c 20 2a 71 29 3456789.ab", *q)
3710: 29 20 26 26 20 28 28 28 21 73 74 72 63 68 72 28 ) && (((!strchr(
3720: 22 2e 61 62 22 2c 20 2a 71 29 0a 09 09 09 20 20 ".ab", *q)....
3730: 20 20 26 26 20 21 73 74 72 63 68 72 28 22 61 62 && !strchr("ab
3740: 22 2c 20 71 5b 2d 31 5d 29 29 20 7c 7c 20 2d 2d ", q[-1])) || --
3750: 6e 75 6d 64 6f 74 73 29 29 29 20 7b 0a 09 09 20 numdots))) {...
3760: 20 20 20 2b 2b 71 3b 0a 09 09 7d 0a 0a 09 09 2a ++q;...}....*
3770: 71 20 3d 20 30 3b 0a 09 09 73 7a 52 65 73 75 6c q = 0;...szResul
3780: 74 20 3d 20 70 3b 0a 09 09 62 72 65 61 6b 3b 0a t = p;...break;.
3790: 09 20 20 20 20 7d 0a 09 7d 0a 09 66 63 6c 6f 73 . }..}..fclos
37a0: 65 28 66 70 29 3b 0a 20 20 20 20 7d 0a 20 20 20 e(fp);. }.
37b0: 20 72 65 74 75 72 6e 20 73 7a 52 65 73 75 6c 74 return szResult
37c0: 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 4c 69 73 74 ;.}.../*. * List
37d0: 20 68 65 6c 70 65 72 73 20 66 6f 72 20 74 68 65 helpers for the
37e0: 20 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 20 SubstituteFile
37f0: 66 75 6e 63 74 69 6f 6e 0a 20 2a 2f 0a 0a 74 79 function. */..ty
3800: 70 65 64 65 66 20 73 74 72 75 63 74 20 6c 69 73 pedef struct lis
3810: 74 5f 69 74 65 6d 5f 74 20 7b 0a 20 20 20 20 73 t_item_t {. s
3820: 74 72 75 63 74 20 6c 69 73 74 5f 69 74 65 6d 5f truct list_item_
3830: 74 20 2a 6e 65 78 74 50 74 72 3b 0a 20 20 20 20 t *nextPtr;.
3840: 63 68 61 72 20 2a 20 6b 65 79 3b 0a 20 20 20 20 char * key;.
3850: 63 68 61 72 20 2a 20 76 61 6c 75 65 3b 0a 7d 20 char * value;.}
3860: 6c 69 73 74 5f 69 74 65 6d 5f 74 3b 0a 0a 2f 2a list_item_t;../*
3870: 20 69 6e 73 65 72 74 20 61 20 6c 69 73 74 20 69 insert a list i
3880: 74 65 6d 20 69 6e 74 6f 20 74 68 65 20 6c 69 73 tem into the lis
3890: 74 20 28 6c 69 73 74 20 6d 61 79 20 62 65 20 6e t (list may be n
38a0: 75 6c 6c 29 20 2a 2f 0a 73 74 61 74 69 63 20 6c ull) */.static l
38b0: 69 73 74 5f 69 74 65 6d 5f 74 20 2a 0a 6c 69 73 ist_item_t *.lis
38c0: 74 5f 69 6e 73 65 72 74 28 6c 69 73 74 5f 69 74 t_insert(list_it
38d0: 65 6d 5f 74 20 2a 2a 6c 69 73 74 50 74 72 50 74 em_t **listPtrPt
38e0: 72 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b r, const char *k
38f0: 65 79 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a ey, const char *
3900: 76 61 6c 75 65 29 0a 7b 0a 20 20 20 20 6c 69 73 value).{. lis
3910: 74 5f 69 74 65 6d 5f 74 20 2a 69 74 65 6d 50 74 t_item_t *itemPt
3920: 72 20 3d 20 28 6c 69 73 74 5f 69 74 65 6d 5f 74 r = (list_item_t
3930: 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 *)malloc(sizeof
3940: 28 6c 69 73 74 5f 69 74 65 6d 5f 74 29 29 3b 0a (list_item_t));.
3950: 20 20 20 20 69 66 20 28 69 74 65 6d 50 74 72 29 if (itemPtr)
3960: 20 7b 0a 09 69 74 65 6d 50 74 72 2d 3e 6b 65 79 {..itemPtr->key
3970: 20 3d 20 73 74 72 64 75 70 28 6b 65 79 29 3b 0a = strdup(key);.
3980: 09 69 74 65 6d 50 74 72 2d 3e 76 61 6c 75 65 20 .itemPtr->value
3990: 3d 20 73 74 72 64 75 70 28 76 61 6c 75 65 29 3b = strdup(value);
39a0: 0a 09 69 74 65 6d 50 74 72 2d 3e 6e 65 78 74 50 ..itemPtr->nextP
39b0: 74 72 20 3d 20 4e 55 4c 4c 3b 0a 0a 09 77 68 69 tr = NULL;...whi
39c0: 6c 65 28 2a 6c 69 73 74 50 74 72 50 74 72 29 20 le(*listPtrPtr)
39d0: 7b 0a 09 20 20 20 20 6c 69 73 74 50 74 72 50 74 {.. listPtrPt
39e0: 72 20 3d 20 26 28 2a 6c 69 73 74 50 74 72 50 74 r = &(*listPtrPt
39f0: 72 29 2d 3e 6e 65 78 74 50 74 72 3b 0a 09 7d 0a r)->nextPtr;..}.
3a00: 09 2a 6c 69 73 74 50 74 72 50 74 72 20 3d 20 69 .*listPtrPtr = i
3a10: 74 65 6d 50 74 72 3b 0a 20 20 20 20 7d 0a 20 20 temPtr;. }.
3a20: 20 20 72 65 74 75 72 6e 20 69 74 65 6d 50 74 72 return itemPtr
3a30: 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 76 6f 69 64 ;.}..static void
3a40: 0a 6c 69 73 74 5f 66 72 65 65 28 6c 69 73 74 5f .list_free(list_
3a50: 69 74 65 6d 5f 74 20 2a 2a 6c 69 73 74 50 74 72 item_t **listPtr
3a60: 50 74 72 29 0a 7b 0a 20 20 20 20 6c 69 73 74 5f Ptr).{. list_
3a70: 69 74 65 6d 5f 74 20 2a 74 6d 70 50 74 72 2c 20 item_t *tmpPtr,
3a80: 2a 6c 69 73 74 50 74 72 20 3d 20 2a 6c 69 73 74 *listPtr = *list
3a90: 50 74 72 50 74 72 3b 0a 20 20 20 20 77 68 69 6c PtrPtr;. whil
3aa0: 65 20 28 6c 69 73 74 50 74 72 29 20 7b 0a 09 74 e (listPtr) {..t
3ab0: 6d 70 50 74 72 20 3d 20 6c 69 73 74 50 74 72 3b mpPtr = listPtr;
3ac0: 0a 09 6c 69 73 74 50 74 72 20 3d 20 6c 69 73 74 ..listPtr = list
3ad0: 50 74 72 2d 3e 6e 65 78 74 50 74 72 3b 0a 09 66 Ptr->nextPtr;..f
3ae0: 72 65 65 28 74 6d 70 50 74 72 2d 3e 6b 65 79 29 ree(tmpPtr->key)
3af0: 3b 0a 09 66 72 65 65 28 74 6d 70 50 74 72 2d 3e ;..free(tmpPtr->
3b00: 76 61 6c 75 65 29 3b 0a 09 66 72 65 65 28 74 6d value);..free(tm
3b10: 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 7d 0a 0c pPtr);. }.}..
3b20: 0a 2f 2a 0a 20 2a 20 53 75 62 73 74 69 74 75 74 ./*. * Substitut
3b30: 65 46 69 6c 65 20 2d 2d 0a 20 2a 09 41 73 20 77 eFile --. *.As w
3b40: 69 6e 64 6f 77 73 20 64 6f 65 73 6e 27 74 20 70 indows doesn't p
3b50: 72 6f 76 69 64 65 20 61 6e 79 74 68 69 6e 67 20 rovide anything
3b60: 75 73 65 66 75 6c 20 6c 69 6b 65 20 73 65 64 20 useful like sed
3b70: 61 6e 64 20 69 74 27 73 20 75 6e 72 65 6c 69 61 and it's unrelia
3b80: 62 6c 65 0a 20 2a 09 74 6f 20 75 73 65 20 74 68 ble. *.to use th
3b90: 65 20 74 63 6c 73 68 20 79 6f 75 20 61 72 65 20 e tclsh you are
3ba0: 62 75 69 6c 64 69 6e 67 20 61 67 61 69 6e 73 74 building against
3bb0: 20 28 63 6f 6e 73 69 64 65 72 20 78 2d 70 6c 61 (consider x-pla
3bc0: 74 66 6f 72 6d 20 62 75 69 6c 64 73 20 2d 0a 20 tform builds -.
3bd0: 2a 09 65 2e 67 2e 20 63 6f 6d 70 69 6c 69 6e 67 *.e.g. compiling
3be0: 20 41 4d 44 36 34 20 74 61 72 67 65 74 20 66 72 AMD64 target fr
3bf0: 6f 6d 20 49 58 38 36 29 20 77 65 20 70 72 6f 76 om IX86) we prov
3c00: 69 64 65 20 61 20 73 69 6d 70 6c 65 20 73 75 62 ide a simple sub
3c10: 73 74 69 74 75 74 69 6f 6e 0a 20 2a 09 6f 70 74 stitution. *.opt
3c20: 69 6f 6e 20 68 65 72 65 20 74 6f 20 68 61 6e 64 ion here to hand
3c30: 6c 65 20 61 75 74 6f 63 6f 6e 66 20 73 74 79 6c le autoconf styl
3c40: 65 20 73 75 62 73 74 69 74 75 74 69 6f 6e 73 2e e substitutions.
3c50: 0a 20 2a 09 54 68 65 20 73 75 62 73 74 69 74 75 . *.The substitu
3c60: 74 69 6f 6e 20 66 69 6c 65 20 69 73 20 77 68 69 tion file is whi
3c70: 74 65 73 70 61 63 65 20 61 6e 64 20 6c 69 6e 65 tespace and line
3c80: 20 64 65 6c 69 6d 69 74 65 64 2e 20 54 68 65 20 delimited. The
3c90: 66 69 6c 65 20 73 68 6f 75 6c 64 0a 20 2a 09 63 file should. *.c
3ca0: 6f 6e 73 69 73 74 20 6f 66 20 6c 69 6e 65 73 20 onsist of lines
3cb0: 6d 61 74 63 68 69 6e 67 20 74 68 65 20 72 65 67 matching the reg
3cc0: 75 6c 61 72 20 65 78 70 72 65 73 73 69 6f 6e 3a ular expression:
3cd0: 0a 20 2a 09 20 20 5c 73 2a 5c 53 2b 5c 73 2b 5c . *. \s*\S+\s+\
3ce0: 53 2a 24 0a 20 2a 0a 20 2a 09 55 73 61 67 65 20 S*$. *. *.Usage
3cf0: 69 73 20 73 6f 6d 65 74 68 69 6e 67 20 6c 69 6b is something lik
3d00: 65 3a 0a 20 2a 09 20 20 6e 6d 61 6b 65 68 6c 70 e:. *. nmakehlp
3d10: 20 2d 53 20 3c 3c 20 24 2a 2a 20 3e 20 24 40 0a -S << $** > $@.
3d20: 20 2a 09 20 20 20 20 40 50 41 43 4b 41 47 45 5f *. @PACKAGE_
3d30: 4e 41 4d 45 40 20 24 28 50 41 43 4b 41 47 45 5f NAME@ $(PACKAGE_
3d40: 4e 41 4d 45 29 0a 20 2a 09 20 20 20 20 40 50 41 NAME). *. @PA
3d50: 43 4b 41 47 45 5f 56 45 52 53 49 4f 4e 40 20 24 CKAGE_VERSION@ $
3d60: 28 50 41 43 4b 41 47 45 5f 56 45 52 53 49 4f 4e (PACKAGE_VERSION
3d70: 29 0a 20 2a 09 20 20 20 20 3c 3c 0a 20 2a 2f 0a ). *. <<. */.
3d80: 0a 73 74 61 74 69 63 20 69 6e 74 0a 53 75 62 73 .static int.Subs
3d90: 74 69 74 75 74 65 46 69 6c 65 28 0a 20 20 20 20 tituteFile(.
3da0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73 const char *subs
3db0: 74 69 74 75 74 69 6f 6e 73 2c 0a 20 20 20 20 63 titutions,. c
3dc0: 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c 65 6e onst char *filen
3dd0: 61 6d 65 29 0a 7b 0a 20 20 20 20 73 74 61 74 69 ame).{. stati
3de0: 63 20 63 68 61 72 20 73 7a 42 75 66 66 65 72 5b c char szBuffer[
3df0: 31 30 32 34 5d 2c 20 73 7a 43 6f 70 79 5b 31 30 1024], szCopy[10
3e00: 32 34 5d 3b 0a 20 20 20 20 6c 69 73 74 5f 69 74 24];. list_it
3e10: 65 6d 5f 74 20 2a 73 75 62 73 74 50 74 72 20 3d em_t *substPtr =
3e20: 20 4e 55 4c 4c 3b 0a 20 20 20 20 46 49 4c 45 20 NULL;. FILE
3e30: 2a 66 70 2c 20 2a 73 70 3b 0a 0a 20 20 20 20 66 *fp, *sp;.. f
3e40: 70 20 3d 20 66 6f 70 65 6e 28 66 69 6c 65 6e 61 p = fopen(filena
3e50: 6d 65 2c 20 22 72 74 22 29 3b 0a 20 20 20 20 69 me, "rt");. i
3e60: 66 20 28 66 70 20 21 3d 20 4e 55 4c 4c 29 20 7b f (fp != NULL) {
3e70: 0a 0a 09 2f 2a 0a 09 20 2a 20 42 75 69 6c 64 20 .../*.. * Build
3e80: 61 20 6c 69 73 74 20 6f 66 20 73 75 62 73 74 69 a list of substi
3e90: 74 75 74 69 6f 6e 73 20 66 72 6f 6d 20 74 68 65 tutions from the
3ea0: 20 66 69 72 73 74 20 66 69 6c 65 6e 61 6d 65 0a first filename.
3eb0: 09 20 2a 2f 0a 0a 09 73 70 20 3d 20 66 6f 70 65 . */...sp = fope
3ec0: 6e 28 73 75 62 73 74 69 74 75 74 69 6f 6e 73 2c n(substitutions,
3ed0: 20 22 72 74 22 29 3b 0a 09 69 66 20 28 73 70 20 "rt");..if (sp
3ee0: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 != NULL) {..
3ef0: 77 68 69 6c 65 20 28 66 67 65 74 73 28 73 7a 42 while (fgets(szB
3f00: 75 66 66 65 72 2c 20 73 69 7a 65 6f 66 28 73 7a uffer, sizeof(sz
3f10: 42 75 66 66 65 72 29 2c 20 73 70 29 20 21 3d 20 Buffer), sp) !=
3f20: 4e 55 4c 4c 29 20 7b 0a 09 09 75 6e 73 69 67 6e NULL) {...unsign
3f30: 65 64 20 63 68 61 72 20 2a 6b 73 2c 20 2a 6b 65 ed char *ks, *ke
3f40: 2c 20 2a 76 73 2c 20 2a 76 65 3b 0a 09 09 6b 73 , *vs, *ve;...ks
3f50: 20 3d 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 = (unsigned cha
3f60: 72 2a 29 73 7a 42 75 66 66 65 72 3b 0a 09 09 77 r*)szBuffer;...w
3f70: 68 69 6c 65 20 28 6b 73 20 26 26 20 2a 6b 73 20 hile (ks && *ks
3f80: 26 26 20 69 73 73 70 61 63 65 28 2a 6b 73 29 29 && isspace(*ks))
3f90: 20 2b 2b 6b 73 3b 0a 09 09 6b 65 20 3d 20 6b 73 ++ks;...ke = ks
3fa0: 3b 0a 09 09 77 68 69 6c 65 20 28 6b 65 20 26 26 ;...while (ke &&
3fb0: 20 2a 6b 65 20 26 26 20 21 69 73 73 70 61 63 65 *ke && !isspace
3fc0: 28 2a 6b 65 29 29 20 2b 2b 6b 65 3b 0a 09 09 76 (*ke)) ++ke;...v
3fd0: 73 20 3d 20 6b 65 3b 0a 09 09 77 68 69 6c 65 20 s = ke;...while
3fe0: 28 76 73 20 26 26 20 2a 76 73 20 26 26 20 69 73 (vs && *vs && is
3ff0: 73 70 61 63 65 28 2a 76 73 29 29 20 2b 2b 76 73 space(*vs)) ++vs
4000: 3b 0a 09 09 76 65 20 3d 20 76 73 3b 0a 09 09 77 ;...ve = vs;...w
4010: 68 69 6c 65 20 28 76 65 20 26 26 20 2a 76 65 20 hile (ve && *ve
4020: 26 26 20 21 28 2a 76 65 20 3d 3d 20 27 5c 72 27 && !(*ve == '\r'
4030: 20 7c 7c 20 2a 76 65 20 3d 3d 20 27 5c 6e 27 29 || *ve == '\n')
4040: 29 20 2b 2b 76 65 3b 0a 09 09 2a 6b 65 20 3d 20 ) ++ve;...*ke =
4050: 30 2c 20 2a 76 65 20 3d 20 30 3b 0a 09 09 6c 69 0, *ve = 0;...li
4060: 73 74 5f 69 6e 73 65 72 74 28 26 73 75 62 73 74 st_insert(&subst
4070: 50 74 72 2c 20 28 63 68 61 72 2a 29 6b 73 2c 20 Ptr, (char*)ks,
4080: 28 63 68 61 72 2a 29 76 73 29 3b 0a 09 20 20 20 (char*)vs);..
4090: 20 7d 0a 09 20 20 20 20 66 63 6c 6f 73 65 28 73 }.. fclose(s
40a0: 70 29 3b 0a 09 7d 0a 0a 09 2f 2a 20 64 65 62 75 p);..}.../* debu
40b0: 67 3a 20 64 75 6d 70 20 74 68 65 20 6c 69 73 74 g: dump the list
40c0: 20 2a 2f 0a 23 69 66 6e 64 65 66 20 4e 44 45 42 */.#ifndef NDEB
40d0: 55 47 0a 09 7b 0a 09 20 20 20 20 69 6e 74 20 6e UG..{.. int n
40e0: 20 3d 20 30 3b 0a 09 20 20 20 20 6c 69 73 74 5f = 0;.. list_
40f0: 69 74 65 6d 5f 74 20 2a 70 20 3d 20 4e 55 4c 4c item_t *p = NULL
4100: 3b 0a 09 20 20 20 20 66 6f 72 20 28 70 20 3d 20 ;.. for (p =
4110: 73 75 62 73 74 50 74 72 3b 20 70 20 21 3d 20 4e substPtr; p != N
4120: 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e 6e 65 78 74 ULL; p = p->next
4130: 50 74 72 2c 20 2b 2b 6e 29 20 7b 0a 09 09 66 70 Ptr, ++n) {...fp
4140: 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 rintf(stderr, "%
4150: 20 33 64 20 27 25 73 27 20 3d 3e 20 27 25 73 27 3d '%s' => '%s'
4160: 5c 6e 22 2c 20 6e 2c 20 70 2d 3e 6b 65 79 2c 20 \n", n, p->key,
4170: 70 2d 3e 76 61 6c 75 65 29 3b 0a 09 20 20 20 20 p->value);..
4180: 7d 0a 09 7d 0a 23 65 6e 64 69 66 0a 0a 09 2f 2a }..}.#endif.../*
4190: 0a 09 20 2a 20 52 75 6e 20 74 68 65 20 73 75 62 .. * Run the sub
41a0: 73 74 69 74 75 74 69 6f 6e 73 20 6f 76 65 72 20 stitutions over
41b0: 65 61 63 68 20 6c 69 6e 65 20 6f 66 20 74 68 65 each line of the
41c0: 20 69 6e 70 75 74 0a 09 20 2a 2f 0a 0a 09 77 68 input.. */...wh
41d0: 69 6c 65 20 28 66 67 65 74 73 28 73 7a 42 75 66 ile (fgets(szBuf
41e0: 66 65 72 2c 20 73 69 7a 65 6f 66 28 73 7a 42 75 fer, sizeof(szBu
41f0: 66 66 65 72 29 2c 20 66 70 29 20 21 3d 20 4e 55 ffer), fp) != NU
4200: 4c 4c 29 20 7b 0a 09 20 20 20 20 6c 69 73 74 5f LL) {.. list_
4210: 69 74 65 6d 5f 74 20 2a 70 20 3d 20 4e 55 4c 4c item_t *p = NULL
4220: 3b 0a 09 20 20 20 20 66 6f 72 20 28 70 20 3d 20 ;.. for (p =
4230: 73 75 62 73 74 50 74 72 3b 20 70 20 21 3d 20 4e substPtr; p != N
4240: 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e 6e 65 78 74 ULL; p = p->next
4250: 50 74 72 29 20 7b 0a 09 09 63 68 61 72 20 2a 6d Ptr) {...char *m
4260: 20 3d 20 73 74 72 73 74 72 28 73 7a 42 75 66 66 = strstr(szBuff
4270: 65 72 2c 20 70 2d 3e 6b 65 79 29 3b 0a 09 09 69 er, p->key);...i
4280: 66 20 28 6d 29 20 7b 0a 09 09 20 20 20 20 63 68 f (m) {... ch
4290: 61 72 20 2a 63 70 2c 20 2a 6f 70 2c 20 2a 73 70 ar *cp, *op, *sp
42a0: 3b 0a 09 09 20 20 20 20 63 70 20 3d 20 73 7a 43 ;... cp = szC
42b0: 6f 70 79 3b 0a 09 09 20 20 20 20 6f 70 20 3d 20 opy;... op =
42c0: 73 7a 42 75 66 66 65 72 3b 0a 09 09 20 20 20 20 szBuffer;...
42d0: 77 68 69 6c 65 20 28 6f 70 20 21 3d 20 6d 29 20 while (op != m)
42e0: 2a 63 70 2b 2b 20 3d 20 2a 6f 70 2b 2b 3b 0a 09 *cp++ = *op++;..
42f0: 09 20 20 20 20 73 70 20 3d 20 70 2d 3e 76 61 6c . sp = p->val
4300: 75 65 3b 0a 09 09 20 20 20 20 77 68 69 6c 65 20 ue;... while
4310: 28 73 70 20 26 26 20 2a 73 70 29 20 2a 63 70 2b (sp && *sp) *cp+
4320: 2b 20 3d 20 2a 73 70 2b 2b 3b 0a 09 09 20 20 20 + = *sp++;...
4330: 20 6f 70 20 2b 3d 20 73 74 72 6c 65 6e 28 70 2d op += strlen(p-
4340: 3e 6b 65 79 29 3b 0a 09 09 20 20 20 20 77 68 69 >key);... whi
4350: 6c 65 20 28 2a 6f 70 29 20 2a 63 70 2b 2b 20 3d le (*op) *cp++ =
4360: 20 2a 6f 70 2b 2b 3b 0a 09 09 20 20 20 20 2a 63 *op++;... *c
4370: 70 20 3d 20 30 3b 0a 09 09 20 20 20 20 6d 65 6d p = 0;... mem
4380: 63 70 79 28 73 7a 42 75 66 66 65 72 2c 20 73 7a cpy(szBuffer, sz
4390: 43 6f 70 79 2c 20 73 69 7a 65 6f 66 28 73 7a 43 Copy, sizeof(szC
43a0: 6f 70 79 29 29 3b 0a 09 09 7d 0a 09 20 20 20 20 opy));...}..
43b0: 7d 0a 09 20 20 20 20 70 72 69 6e 74 66 28 22 25 }.. printf("%
43c0: 73 22 2c 20 73 7a 42 75 66 66 65 72 29 3b 0a 09 s", szBuffer);..
43d0: 7d 0a 0a 09 6c 69 73 74 5f 66 72 65 65 28 26 73 }...list_free(&s
43e0: 75 62 73 74 50 74 72 29 3b 0a 20 20 20 20 7d 0a ubstPtr);. }.
43f0: 20 20 20 20 66 63 6c 6f 73 65 28 66 70 29 3b 0a fclose(fp);.
4400: 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a return 0;.}.
4410: 0c 0a 42 4f 4f 4c 20 46 69 6c 65 45 78 69 73 74 ..BOOL FileExist
4420: 73 28 4c 50 43 54 53 54 52 20 73 7a 50 61 74 68 s(LPCTSTR szPath
4430: 29 0a 7b 0a 23 69 66 6e 64 65 66 20 49 4e 56 41 ).{.#ifndef INVA
4440: 4c 49 44 5f 46 49 4c 45 5f 41 54 54 52 49 42 55 LID_FILE_ATTRIBU
4450: 54 45 53 0a 20 20 20 20 23 64 65 66 69 6e 65 20 TES. #define
4460: 49 4e 56 41 4c 49 44 5f 46 49 4c 45 5f 41 54 54 INVALID_FILE_ATT
4470: 52 49 42 55 54 45 53 20 28 28 44 57 4f 52 44 29 RIBUTES ((DWORD)
4480: 2d 31 29 0a 23 65 6e 64 69 66 0a 20 20 20 20 44 -1).#endif. D
4490: 57 4f 52 44 20 70 61 74 68 41 74 74 72 20 3d 20 WORD pathAttr =
44a0: 47 65 74 46 69 6c 65 41 74 74 72 69 62 75 74 65 GetFileAttribute
44b0: 73 28 73 7a 50 61 74 68 29 3b 0a 20 20 20 20 72 s(szPath);. r
44c0: 65 74 75 72 6e 20 28 70 61 74 68 41 74 74 72 20 eturn (pathAttr
44d0: 21 3d 20 49 4e 56 41 4c 49 44 5f 46 49 4c 45 5f != INVALID_FILE_
44e0: 41 54 54 52 49 42 55 54 45 53 20 26 26 0a 09 20 ATTRIBUTES &&..
44f0: 20 20 20 21 28 70 61 74 68 41 74 74 72 20 26 20 !(pathAttr &
4500: 46 49 4c 45 5f 41 54 54 52 49 42 55 54 45 5f 44 FILE_ATTRIBUTE_D
4510: 49 52 45 43 54 4f 52 59 29 29 3b 0a 7d 0a 0c 0a IRECTORY));.}...
4520: 0a 2f 2a 0a 20 2a 20 51 75 61 6c 69 66 79 50 61 ./*. * QualifyPa
4530: 74 68 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 th --. *. *.This
4540: 20 63 6f 6d 70 6f 73 65 73 20 74 68 65 20 63 75 composes the cu
4550: 72 72 65 6e 74 20 77 6f 72 6b 69 6e 67 20 64 69 rrent working di
4560: 72 65 63 74 6f 72 79 20 77 69 74 68 20 61 20 70 rectory with a p
4570: 72 6f 76 69 64 65 64 20 70 61 74 68 0a 20 2a 09 rovided path. *.
4580: 61 6e 64 20 72 65 74 75 72 6e 73 20 74 68 65 20 and returns the
4590: 66 75 6c 6c 79 20 71 75 61 6c 69 66 69 65 64 20 fully qualified
45a0: 61 6e 64 20 6e 6f 72 6d 61 6c 69 7a 65 64 20 70 and normalized p
45b0: 61 74 68 2e 0a 20 2a 09 4d 6f 73 74 6c 79 20 6e ath.. *.Mostly n
45c0: 65 65 64 65 64 20 74 6f 20 73 65 74 75 70 20 70 eeded to setup p
45d0: 61 74 68 73 20 66 6f 72 20 74 65 73 74 69 6e 67 aths for testing
45e0: 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e .. */..static in
45f0: 74 0a 51 75 61 6c 69 66 79 50 61 74 68 28 0a 20 t.QualifyPath(.
4600: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 const char *s
4610: 7a 50 61 74 68 29 0a 7b 0a 20 20 20 20 63 68 61 zPath).{. cha
4620: 72 20 73 7a 43 77 64 5b 4d 41 58 5f 50 41 54 48 r szCwd[MAX_PATH
4630: 20 2b 20 31 5d 3b 0a 0a 20 20 20 20 47 65 74 46 + 1];.. GetF
4640: 75 6c 6c 50 61 74 68 4e 61 6d 65 28 73 7a 50 61 ullPathName(szPa
4650: 74 68 2c 20 73 69 7a 65 6f 66 28 73 7a 43 77 64 th, sizeof(szCwd
4660: 29 2d 31 2c 20 73 7a 43 77 64 2c 20 4e 55 4c 4c )-1, szCwd, NULL
4670: 29 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 25 );. printf("%
4680: 73 5c 6e 22 2c 20 73 7a 43 77 64 29 3b 0a 20 20 s\n", szCwd);.
4690: 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 2f return 0;.}../
46a0: 2a 0a 20 2a 20 49 6d 70 6c 65 6d 65 6e 74 73 20 *. * Implements
46b0: 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 LocateDependency
46c0: 20 66 6f 72 20 61 20 73 69 6e 67 6c 65 20 64 69 for a single di
46d0: 72 65 63 74 6f 72 79 2e 20 53 65 65 20 74 68 61 rectory. See tha
46e0: 74 20 63 6f 6d 6d 61 6e 64 0a 20 2a 20 66 6f 72 t command. * for
46f0: 20 61 6e 20 65 78 70 6c 61 6e 61 74 69 6f 6e 2e an explanation.
4700: 0a 20 2a 20 52 65 74 75 72 6e 73 20 30 20 69 66 . * Returns 0 if
4710: 20 66 6f 75 6e 64 20 61 66 74 65 72 20 70 72 69 found after pri
4720: 6e 74 69 6e 67 20 74 68 65 20 64 69 72 65 63 74 nting the direct
4730: 6f 72 79 2e 0a 20 2a 20 52 65 74 75 72 6e 73 20 ory.. * Returns
4740: 31 20 69 66 20 6e 6f 74 20 66 6f 75 6e 64 20 62 1 if not found b
4750: 75 74 20 6e 6f 20 65 72 72 6f 72 73 2e 0a 20 2a ut no errors.. *
4760: 20 52 65 74 75 72 6e 73 20 32 20 6f 6e 20 61 6e Returns 2 on an
4770: 79 20 6b 69 6e 64 20 6f 66 20 65 72 72 6f 72 0a y kind of error.
4780: 20 2a 20 42 61 73 69 63 61 6c 6c 79 2c 20 74 68 * Basically, th
4790: 65 73 65 20 61 72 65 20 75 73 65 64 20 61 73 20 ese are used as
47a0: 65 78 69 74 20 63 6f 64 65 73 20 66 6f 72 20 74 exit codes for t
47b0: 68 65 20 70 72 6f 63 65 73 73 2e 0a 20 2a 2f 0a he process.. */.
47c0: 73 74 61 74 69 63 20 69 6e 74 20 4c 6f 63 61 74 static int Locat
47d0: 65 44 65 70 65 6e 64 65 6e 63 79 48 65 6c 70 65 eDependencyHelpe
47e0: 72 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 64 69 r(const char *di
47f0: 72 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b r, const char *k
4800: 65 79 70 61 74 68 29 0a 7b 0a 20 20 20 20 48 41 eypath).{. HA
4810: 4e 44 4c 45 20 68 53 65 61 72 63 68 3b 0a 20 20 NDLE hSearch;.
4820: 20 20 63 68 61 72 20 70 61 74 68 5b 4d 41 58 5f char path[MAX_
4830: 50 41 54 48 2b 31 5d 3b 0a 20 20 20 20 73 69 7a PATH+1];. siz
4840: 65 5f 74 20 64 69 72 6c 65 6e 3b 0a 20 20 20 20 e_t dirlen;.
4850: 69 6e 74 20 6b 65 79 6c 65 6e 2c 20 72 65 74 3b int keylen, ret;
4860: 0a 20 20 20 20 57 49 4e 33 32 5f 46 49 4e 44 5f . WIN32_FIND_
4870: 44 41 54 41 20 66 69 6e 66 6f 3b 0a 0a 20 20 20 DATA finfo;..
4880: 20 69 66 20 28 64 69 72 20 3d 3d 20 4e 55 4c 4c if (dir == NULL
4890: 20 7c 7c 20 6b 65 79 70 61 74 68 20 3d 3d 20 4e || keypath == N
48a0: 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 32 ULL) {..return 2
48b0: 3b 20 2f 2a 20 48 61 76 65 20 6e 6f 20 72 65 61 ; /* Have no rea
48c0: 6c 20 65 72 72 6f 72 20 72 65 70 6f 72 74 69 6e l error reportin
48d0: 67 20 6d 65 63 68 61 6e 69 73 6d 20 69 6e 74 6f g mechanism into
48e0: 20 6e 6d 61 6b 65 20 2a 2f 0a 20 20 20 20 7d 0a nmake */. }.
48f0: 20 20 20 20 64 69 72 6c 65 6e 20 3d 20 73 74 72 dirlen = str
4900: 6c 65 6e 28 64 69 72 29 3b 0a 20 20 20 20 69 66 len(dir);. if
4910: 20 28 64 69 72 6c 65 6e 20 3e 20 73 69 7a 65 6f (dirlen > sizeo
4920: 66 28 70 61 74 68 29 20 2d 20 33 29 20 7b 0a 09 f(path) - 3) {..
4930: 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 7d 0a return 2;. }.
4940: 20 20 20 20 73 74 72 6e 63 70 79 28 70 61 74 68 strncpy(path
4950: 2c 20 64 69 72 2c 20 64 69 72 6c 65 6e 29 3b 0a , dir, dirlen);.
4960: 20 20 20 20 73 74 72 6e 63 70 79 28 70 61 74 68 strncpy(path
4970: 2b 64 69 72 6c 65 6e 2c 20 22 5c 5c 2a 22 2c 20 +dirlen, "\\*",
4980: 33 29 3b 09 2f 2a 20 49 6e 63 6c 75 64 69 6e 67 3);./* Including
4990: 20 74 65 72 6d 69 6e 61 74 69 6e 67 20 5c 30 20 terminating \0
49a0: 2a 2f 0a 20 20 20 20 6b 65 79 6c 65 6e 20 3d 20 */. keylen =
49b0: 73 74 72 6c 65 6e 28 6b 65 79 70 61 74 68 29 3b strlen(keypath);
49c0: 0a 0a 23 69 66 20 30 20 2f 2a 20 54 68 69 73 20 ..#if 0 /* This
49d0: 66 75 6e 63 74 69 6f 6e 20 69 73 20 6e 6f 74 20 function is not
49e0: 61 76 61 69 6c 61 62 6c 65 20 69 6e 20 56 69 73 available in Vis
49f0: 75 61 6c 20 43 2b 2b 20 36 20 2a 2f 0a 20 20 20 ual C++ 6 */.
4a00: 20 2f 2a 0a 20 20 20 20 20 2a 20 55 73 65 20 6e /*. * Use n
4a10: 75 6d 65 72 69 63 73 20 30 20 2d 3e 20 46 69 6e umerics 0 -> Fin
4a20: 64 45 78 49 6e 66 6f 53 74 61 6e 64 61 72 64 2c dExInfoStandard,
4a30: 0a 20 20 20 20 20 2a 20 31 20 2d 3e 20 46 69 6e . * 1 -> Fin
4a40: 64 45 78 53 65 61 72 63 68 4c 69 6d 69 74 54 6f dExSearchLimitTo
4a50: 44 69 72 65 63 74 6f 72 69 65 73 2c 0a 20 20 20 Directories,.
4a60: 20 20 2a 20 61 73 20 74 68 65 73 65 20 61 72 65 * as these are
4a70: 20 6e 6f 74 20 64 65 66 69 6e 65 64 20 69 6e 20 not defined in
4a80: 56 69 73 75 61 6c 20 43 2b 2b 20 36 0a 20 20 20 Visual C++ 6.
4a90: 20 20 2a 2f 0a 20 20 20 20 68 53 65 61 72 63 68 */. hSearch
4aa0: 20 3d 20 46 69 6e 64 46 69 72 73 74 46 69 6c 65 = FindFirstFile
4ab0: 45 78 28 70 61 74 68 2c 20 30 2c 20 26 66 69 6e Ex(path, 0, &fin
4ac0: 66 6f 2c 20 31 2c 20 4e 55 4c 4c 2c 20 30 29 3b fo, 1, NULL, 0);
4ad0: 0a 23 65 6c 73 65 0a 20 20 20 20 68 53 65 61 72 .#else. hSear
4ae0: 63 68 20 3d 20 46 69 6e 64 46 69 72 73 74 46 69 ch = FindFirstFi
4af0: 6c 65 28 70 61 74 68 2c 20 26 66 69 6e 66 6f 29 le(path, &finfo)
4b00: 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20 69 66 20 ;.#endif. if
4b10: 28 68 53 65 61 72 63 68 20 3d 3d 20 49 4e 56 41 (hSearch == INVA
4b20: 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 LID_HANDLE_VALUE
4b30: 29 20 7b 0a 09 72 65 74 75 72 6e 20 31 3b 20 2f ) {..return 1; /
4b40: 2a 20 4e 6f 74 20 66 6f 75 6e 64 20 2a 2f 0a 20 * Not found */.
4b50: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 4c 6f 6f }.. /* Loo
4b60: 70 20 74 68 72 6f 75 67 68 20 61 6c 6c 20 73 75 p through all su
4b70: 62 64 69 72 73 20 63 68 65 63 6b 69 6e 67 20 69 bdirs checking i
4b80: 66 20 74 68 65 20 6b 65 79 70 61 74 68 20 69 73 f the keypath is
4b90: 20 75 6e 64 65 72 20 74 68 65 72 65 20 2a 2f 0a under there */.
4ba0: 20 20 20 20 72 65 74 20 3d 20 31 3b 20 2f 2a 20 ret = 1; /*
4bb0: 41 73 73 75 6d 65 20 6e 6f 74 20 66 6f 75 6e 64 Assume not found
4bc0: 20 2a 2f 0a 20 20 20 20 64 6f 20 7b 0a 09 69 6e */. do {..in
4bd0: 74 20 73 75 62 6c 65 6e 3b 0a 09 2f 2a 0a 09 20 t sublen;../*..
4be0: 2a 20 57 65 20 6e 65 65 64 20 74 6f 20 63 68 65 * We need to che
4bf0: 63 6b 20 69 74 20 69 73 20 61 20 64 69 72 65 63 ck it is a direc
4c00: 74 6f 72 79 20 64 65 73 70 69 74 65 20 74 68 65 tory despite the
4c10: 0a 09 20 2a 20 46 69 6e 64 45 78 53 65 61 72 63 .. * FindExSearc
4c20: 68 4c 69 6d 69 74 54 6f 44 69 72 65 63 74 6f 72 hLimitToDirector
4c30: 69 65 73 20 69 6e 20 74 68 65 20 61 62 6f 76 65 ies in the above
4c40: 20 63 61 6c 6c 2e 20 53 65 65 20 53 44 4b 20 64 call. See SDK d
4c50: 6f 63 73 0a 09 20 2a 2f 0a 09 69 66 20 28 28 66 ocs.. */..if ((f
4c60: 69 6e 66 6f 2e 64 77 46 69 6c 65 41 74 74 72 69 info.dwFileAttri
4c70: 62 75 74 65 73 20 26 20 46 49 4c 45 5f 41 54 54 butes & FILE_ATT
4c80: 52 49 42 55 54 45 5f 44 49 52 45 43 54 4f 52 59 RIBUTE_DIRECTORY
4c90: 29 20 3d 3d 20 30 29 20 7b 0a 09 20 20 20 20 63 ) == 0) {.. c
4ca0: 6f 6e 74 69 6e 75 65 3b 0a 09 7d 0a 09 73 75 62 ontinue;..}..sub
4cb0: 6c 65 6e 20 3d 20 73 74 72 6c 65 6e 28 66 69 6e len = strlen(fin
4cc0: 66 6f 2e 63 46 69 6c 65 4e 61 6d 65 29 3b 0a 09 fo.cFileName);..
4cd0: 69 66 20 28 28 64 69 72 6c 65 6e 2b 31 2b 73 75 if ((dirlen+1+su
4ce0: 62 6c 65 6e 2b 31 2b 6b 65 79 6c 65 6e 2b 31 29 blen+1+keylen+1)
4cf0: 20 3e 20 73 69 7a 65 6f 66 28 70 61 74 68 29 29 > sizeof(path))
4d00: 20 7b 0a 09 20 20 20 20 63 6f 6e 74 69 6e 75 65 {.. continue
4d10: 3b 09 09 2f 2a 20 50 61 74 68 20 64 6f 65 73 20 ;../* Path does
4d20: 6e 6f 74 20 66 69 74 2c 20 61 73 73 75 6d 65 20 not fit, assume
4d30: 6e 6f 74 20 6d 61 74 63 68 65 64 20 2a 2f 0a 09 not matched */..
4d40: 7d 0a 09 73 74 72 6e 63 70 79 28 70 61 74 68 2b }..strncpy(path+
4d50: 64 69 72 6c 65 6e 2b 31 2c 20 66 69 6e 66 6f 2e dirlen+1, finfo.
4d60: 63 46 69 6c 65 4e 61 6d 65 2c 20 73 75 62 6c 65 cFileName, suble
4d70: 6e 29 3b 0a 09 70 61 74 68 5b 64 69 72 6c 65 6e n);..path[dirlen
4d80: 2b 31 2b 73 75 62 6c 65 6e 5d 20 3d 20 27 5c 5c +1+sublen] = '\\
4d90: 27 3b 0a 09 73 74 72 6e 63 70 79 28 70 61 74 68 ';..strncpy(path
4da0: 2b 64 69 72 6c 65 6e 2b 31 2b 73 75 62 6c 65 6e +dirlen+1+sublen
4db0: 2b 31 2c 20 6b 65 79 70 61 74 68 2c 20 6b 65 79 +1, keypath, key
4dc0: 6c 65 6e 2b 31 29 3b 0a 09 69 66 20 28 46 69 6c len+1);..if (Fil
4dd0: 65 45 78 69 73 74 73 28 70 61 74 68 29 29 20 7b eExists(path)) {
4de0: 0a 09 20 20 20 20 2f 2a 20 46 6f 75 6e 64 20 61 .. /* Found a
4df0: 20 6d 61 74 63 68 2c 20 70 72 69 6e 74 20 74 6f match, print to
4e00: 20 73 74 64 6f 75 74 20 2a 2f 0a 09 20 20 20 20 stdout */..
4e10: 70 61 74 68 5b 64 69 72 6c 65 6e 2b 31 2b 73 75 path[dirlen+1+su
4e20: 62 6c 65 6e 5d 20 3d 20 27 5c 30 27 3b 0a 09 20 blen] = '\0';..
4e30: 20 20 20 51 75 61 6c 69 66 79 50 61 74 68 28 70 QualifyPath(p
4e40: 61 74 68 29 3b 0a 09 20 20 20 20 72 65 74 20 3d ath);.. ret =
4e50: 20 30 3b 0a 09 20 20 20 20 62 72 65 61 6b 3b 0a 0;.. break;.
4e60: 09 7d 0a 20 20 20 20 7d 20 77 68 69 6c 65 20 28 .}. } while (
4e70: 46 69 6e 64 4e 65 78 74 46 69 6c 65 28 68 53 65 FindNextFile(hSe
4e80: 61 72 63 68 2c 20 26 66 69 6e 66 6f 29 29 3b 0a arch, &finfo));.
4e90: 20 20 20 20 46 69 6e 64 43 6c 6f 73 65 28 68 53 FindClose(hS
4ea0: 65 61 72 63 68 29 3b 0a 20 20 20 20 72 65 74 75 earch);. retu
4eb0: 72 6e 20 72 65 74 3b 0a 7d 0a 0a 2f 2a 0a 20 2a rn ret;.}../*. *
4ec0: 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 LocateDependenc
4ed0: 79 20 2d 2d 0a 20 2a 0a 20 2a 09 4c 6f 63 61 74 y --. *. *.Locat
4ee0: 65 73 20 61 20 64 65 70 65 6e 64 65 6e 63 79 20 es a dependency
4ef0: 66 6f 72 20 61 20 70 61 63 6b 61 67 65 2e 0a 20 for a package..
4f00: 2a 09 20 20 20 20 6b 65 79 70 61 74 68 20 2d 20 *. keypath -
4f10: 61 20 72 65 6c 61 74 69 76 65 20 70 61 74 68 20 a relative path
4f20: 77 69 74 68 69 6e 20 74 68 65 20 70 61 63 6b 61 within the packa
4f30: 67 65 20 64 69 72 65 63 74 6f 72 79 0a 20 2a 09 ge directory. *.
4f40: 20 20 20 20 20 20 74 68 61 74 20 69 73 20 75 73 that is us
4f50: 65 64 20 74 6f 20 63 6f 6e 66 69 72 6d 20 69 74 ed to confirm it
4f60: 20 69 73 20 74 68 65 20 63 6f 72 72 65 63 74 20 is the correct
4f70: 64 69 72 65 63 74 6f 72 79 2e 0a 20 2a 09 54 68 directory.. *.Th
4f80: 65 20 73 65 61 72 63 68 20 70 61 74 68 20 66 6f e search path fo
4f90: 72 20 74 68 65 20 70 61 63 6b 61 67 65 20 64 69 r the package di
4fa0: 72 65 63 74 6f 72 79 20 69 73 20 63 75 72 72 65 rectory is curre
4fb0: 6e 74 6c 79 20 6f 6e 6c 79 0a 20 2a 09 20 20 20 ntly only. *.
4fc0: 20 74 68 65 20 70 61 72 65 6e 74 20 61 6e 64 20 the parent and
4fd0: 67 72 61 6e 64 70 61 72 65 6e 74 20 6f 66 20 74 grandparent of t
4fe0: 68 65 20 63 75 72 72 65 6e 74 20 77 6f 72 6b 69 he current worki
4ff0: 6e 67 20 64 69 72 65 63 74 6f 72 79 2e 0a 20 2a ng directory.. *
5000: 09 20 20 20 20 49 66 20 66 6f 75 6e 64 2c 20 74 . If found, t
5010: 68 65 20 63 6f 6d 6d 61 6e 64 20 70 72 69 6e 74 he command print
5020: 73 0a 20 2a 09 20 20 20 20 20 20 6e 61 6d 65 5f s. *. name_
5030: 44 49 52 50 41 54 48 3d 3c 66 75 6c 6c 20 70 61 DIRPATH=<full pa
5040: 74 68 20 6f 66 20 6c 6f 63 61 74 65 64 20 64 69 th of located di
5050: 72 65 63 74 6f 72 79 3e 0a 20 2a 09 20 20 20 20 rectory>. *.
5060: 61 6e 64 20 72 65 74 75 72 6e 73 20 30 2e 20 49 and returns 0. I
5070: 66 20 6e 6f 74 20 66 6f 75 6e 64 2c 20 64 6f 65 f not found, doe
5080: 73 20 6e 6f 74 20 70 72 69 6e 74 20 61 6e 79 74 s not print anyt
5090: 68 69 6e 67 20 61 6e 64 20 72 65 74 75 72 6e 73 hing and returns
50a0: 20 31 2e 0a 20 2a 2f 0a 73 74 61 74 69 63 20 69 1.. */.static i
50b0: 6e 74 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 nt LocateDepende
50c0: 6e 63 79 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ncy(const char *
50d0: 6b 65 79 70 61 74 68 29 0a 7b 0a 20 20 20 20 73 keypath).{. s
50e0: 69 7a 65 5f 74 20 69 3b 0a 20 20 20 20 69 6e 74 ize_t i;. int
50f0: 20 72 65 74 3b 0a 20 20 20 20 73 74 61 74 69 63 ret;. static
5100: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61 74 const char *pat
5110: 68 73 5b 5d 20 3d 20 7b 22 2e 2e 22 2c 20 22 2e hs[] = {"..", ".
5120: 2e 5c 5c 2e 2e 22 2c 20 22 2e 2e 5c 5c 2e 2e 5c .\\..", "..\\..\
5130: 5c 2e 2e 22 7d 3b 0a 0a 20 20 20 20 66 6f 72 20 \.."};.. for
5140: 28 69 20 3d 20 30 3b 20 69 20 3c 20 28 73 69 7a (i = 0; i < (siz
5150: 65 6f 66 28 70 61 74 68 73 29 2f 73 69 7a 65 6f eof(paths)/sizeo
5160: 66 28 70 61 74 68 73 5b 30 5d 29 29 3b 20 2b 2b f(paths[0])); ++
5170: 69 29 20 7b 0a 09 72 65 74 20 3d 20 4c 6f 63 61 i) {..ret = Loca
5180: 74 65 44 65 70 65 6e 64 65 6e 63 79 48 65 6c 70 teDependencyHelp
5190: 65 72 28 70 61 74 68 73 5b 69 5d 2c 20 6b 65 79 er(paths[i], key
51a0: 70 61 74 68 29 3b 0a 09 69 66 20 28 72 65 74 20 path);..if (ret
51b0: 3d 3d 20 30 29 20 7b 0a 09 20 20 20 20 72 65 74 == 0) {.. ret
51c0: 75 72 6e 20 72 65 74 3b 0a 09 7d 0a 20 20 20 20 urn ret;..}.
51d0: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 72 65 74 }. return ret
51e0: 3b 0a 7d 0a 0a 0a 2f 2a 0a 20 2a 20 4c 6f 63 61 ;.}.../*. * Loca
51f0: 6c 20 76 61 72 69 61 62 6c 65 73 3a 0a 20 2a 20 l variables:. *
5200: 20 20 6d 6f 64 65 3a 20 63 0a 20 2a 20 20 20 63 mode: c. * c
5210: 2d 62 61 73 69 63 2d 6f 66 66 73 65 74 3a 20 34 -basic-offset: 4
5220: 0a 20 2a 20 20 20 66 69 6c 6c 2d 63 6f 6c 75 6d . * fill-colum
5230: 6e 3a 20 37 38 0a 20 2a 20 20 20 69 6e 64 65 6e n: 78. * inden
5240: 74 2d 74 61 62 73 2d 6d 6f 64 65 3a 20 74 0a 20 t-tabs-mode: t.
5250: 2a 20 20 20 74 61 62 2d 77 69 64 74 68 3a 20 38 * tab-width: 8
5260: 0a 20 2a 20 45 6e 64 3a 0a 20 2a 2f 0a . * End:. */.