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 62 79 20 44 61 76 69 64 20 47 72 2002 by David Gr
00d0: 61 76 65 72 65 61 75 78 2e 0a 20 2a 20 43 6f 70 avereaux.. * Cop
00e0: 79 72 69 67 68 74 20 28 63 29 20 32 30 30 36 20 yright (c) 2006
00f0: 62 79 20 50 61 74 20 54 68 6f 79 74 73 0a 20 2a by Pat Thoyts. *
0100: 0a 20 2a 20 53 65 65 20 74 68 65 20 66 69 6c 65 . * See the file
0110: 20 22 6c 69 63 65 6e 73 65 2e 74 65 72 6d 73 22 "license.terms"
0120: 20 66 6f 72 20 69 6e 66 6f 72 6d 61 74 69 6f 6e for information
0130: 20 6f 6e 20 75 73 61 67 65 20 61 6e 64 20 72 65 on usage and re
0140: 64 69 73 74 72 69 62 75 74 69 6f 6e 20 6f 66 0a distribution of.
0150: 20 2a 20 74 68 69 73 20 66 69 6c 65 2c 20 61 6e * this file, an
0160: 64 20 66 6f 72 20 61 20 44 49 53 43 4c 41 49 4d d for a DISCLAIM
0170: 45 52 20 4f 46 20 41 4c 4c 20 57 41 52 52 41 4e ER OF ALL WARRAN
0180: 54 49 45 53 2e 0a 20 2a 0a 20 2a 20 2d 2d 2d 2d TIES.. *. * ----
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 2d ----------------
01d0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 20 2a 20 52 43 53 3a --------. * RCS:
01e0: 20 40 28 23 29 20 24 49 64 3a 20 6e 6d 61 6b 65 @(#) $Id: nmake
01f0: 68 6c 70 2e 63 2c 76 20 31 2e 34 20 32 30 30 38 hlp.c,v 1.4 2008
0200: 2f 30 36 2f 31 38 20 31 31 3a 32 39 3a 33 37 20 /06/18 11:29:37
0210: 70 61 74 74 68 6f 79 74 73 20 45 78 70 20 24 0a patthoyts Exp $.
0220: 20 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d * -------------
0230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
0260: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a ---------------.
0270: 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 5f 43 52 */..#define _CR
0280: 54 5f 53 45 43 55 52 45 5f 4e 4f 5f 44 45 50 52 T_SECURE_NO_DEPR
0290: 45 43 41 54 45 0a 23 69 6e 63 6c 75 64 65 20 3c ECATE.#include <
02a0: 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 64 65 66 69 windows.h>.#defi
02b0: 6e 65 20 4e 4f 5f 53 48 4c 57 41 50 49 5f 47 44 ne NO_SHLWAPI_GD
02c0: 49 0a 23 64 65 66 69 6e 65 20 4e 4f 5f 53 48 4c I.#define NO_SHL
02d0: 57 41 50 49 5f 53 54 52 45 41 4d 0a 23 64 65 66 WAPI_STREAM.#def
02e0: 69 6e 65 20 4e 4f 5f 53 48 4c 57 41 50 49 5f 52 ine NO_SHLWAPI_R
02f0: 45 47 0a 23 69 6e 63 6c 75 64 65 20 3c 73 68 6c EG.#include <shl
0300: 77 61 70 69 2e 68 3e 0a 23 70 72 61 67 6d 61 20 wapi.h>.#pragma
0310: 63 6f 6d 6d 65 6e 74 20 28 6c 69 62 2c 20 22 75 comment (lib, "u
0320: 73 65 72 33 32 2e 6c 69 62 22 29 0a 23 70 72 61 ser32.lib").#pra
0330: 67 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 6c 69 62 gma comment (lib
0340: 2c 20 22 6b 65 72 6e 65 6c 33 32 2e 6c 69 62 22 , "kernel32.lib"
0350: 29 0a 23 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e ).#pragma commen
0360: 74 20 28 6c 69 62 2c 20 22 73 68 6c 77 61 70 69 t (lib, "shlwapi
0370: 2e 6c 69 62 22 29 0a 23 69 6e 63 6c 75 64 65 20 .lib").#include
0380: 3c 73 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75 <stdio.h>.#inclu
0390: 64 65 20 3c 6d 61 74 68 2e 68 3e 0a 0a 2f 2a 0a de <math.h>../*.
03a0: 20 2a 20 54 68 69 73 20 6c 69 62 72 61 72 79 20 * This library
03b0: 69 73 20 72 65 71 75 69 72 65 64 20 66 6f 72 20 is required for
03c0: 78 36 34 20 62 75 69 6c 64 73 20 77 69 74 68 20 x64 builds with
03d0: 5f 73 6f 6d 65 5f 20 76 65 72 73 69 6f 6e 73 20 _some_ versions
03e0: 6f 66 20 4d 53 56 43 0a 20 2a 2f 0a 23 69 66 20 of MSVC. */.#if
03f0: 64 65 66 69 6e 65 64 28 5f 4d 5f 49 41 36 34 29 defined(_M_IA64)
0400: 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 || defined(_M_A
0410: 4d 44 36 34 29 0a 23 69 66 20 5f 4d 53 43 5f 56 MD64).#if _MSC_V
0420: 45 52 20 3e 3d 20 31 34 30 30 20 26 26 20 5f 4d ER >= 1400 && _M
0430: 53 43 5f 56 45 52 20 3c 20 31 35 30 30 0a 23 70 SC_VER < 1500.#p
0440: 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 28 6c 69 ragma comment(li
0450: 62 2c 20 22 62 75 66 66 65 72 6f 76 65 72 66 6c b, "bufferoverfl
0460: 6f 77 55 22 29 0a 23 65 6e 64 69 66 0a 23 65 6e owU").#endif.#en
0470: 64 69 66 0a 0a 2f 2a 20 49 53 4f 20 68 61 63 6b dif../* ISO hack
0480: 20 66 6f 72 20 64 75 6d 62 20 56 43 2b 2b 20 2a for dumb VC++ *
0490: 2f 0a 23 69 66 64 65 66 20 5f 4d 53 43 5f 56 45 /.#ifdef _MSC_VE
04a0: 52 0a 23 64 65 66 69 6e 65 20 20 20 73 6e 70 72 R.#define snpr
04b0: 69 6e 74 66 09 5f 73 6e 70 72 69 6e 74 66 0a 23 intf._snprintf.#
04c0: 65 6e 64 69 66 0a 0a 0a 0a 2f 2a 20 70 72 6f 74 endif..../* prot
04d0: 6f 73 20 2a 2f 0a 0a 69 6e 74 09 09 43 68 65 63 os */..int..Chec
04e0: 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 61 74 kForCompilerFeat
04f0: 75 72 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ure(const char *
0500: 6f 70 74 69 6f 6e 29 3b 0a 69 6e 74 09 09 43 68 option);.int..Ch
0510: 65 63 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 eckForLinkerFeat
0520: 75 72 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a ure(const char *
0530: 6f 70 74 69 6f 6e 29 3b 0a 69 6e 74 09 09 49 73 option);.int..Is
0540: 49 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 In(const char *s
0550: 74 72 69 6e 67 2c 20 63 6f 6e 73 74 20 63 68 61 tring, const cha
0560: 72 20 2a 73 75 62 73 74 72 69 6e 67 29 3b 0a 69 r *substring);.i
0570: 6e 74 09 09 47 72 65 70 46 6f 72 44 65 66 69 6e nt..GrepForDefin
0580: 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 e(const char *fi
0590: 6c 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a le, const char *
05a0: 73 74 72 69 6e 67 29 3b 0a 69 6e 74 09 09 53 75 string);.int..Su
05b0: 62 73 74 69 74 75 74 65 46 69 6c 65 28 63 6f 6e bstituteFile(con
05c0: 73 74 20 63 68 61 72 20 2a 73 75 62 73 74 73 2c st char *substs,
05d0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c const char *fil
05e0: 65 6e 61 6d 65 29 3b 0a 69 6e 74 09 09 51 75 61 ename);.int..Qua
05f0: 6c 69 66 79 50 61 74 68 28 63 6f 6e 73 74 20 63 lifyPath(const c
0600: 68 61 72 20 2a 70 61 74 68 29 3b 0a 63 6f 6e 73 har *path);.cons
0610: 74 20 63 68 61 72 20 2a 20 20 20 20 47 65 74 56 t char * GetV
0620: 65 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 63 ersionFromFile(c
0630: 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c 65 6e onst char *filen
0640: 61 6d 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 ame, const char
0650: 2a 6d 61 74 63 68 29 3b 0a 44 57 4f 52 44 20 57 *match);.DWORD W
0660: 49 4e 41 50 49 09 52 65 61 64 46 72 6f 6d 50 69 INAPI.ReadFromPi
0670: 70 65 28 4c 50 56 4f 49 44 20 61 72 67 73 29 3b pe(LPVOID args);
0680: 0a 0a 2f 2a 20 67 6c 6f 62 61 6c 73 20 2a 2f 0a ../* globals */.
0690: 0a 23 64 65 66 69 6e 65 20 43 48 55 4e 4b 09 32 .#define CHUNK.2
06a0: 35 0a 23 64 65 66 69 6e 65 20 53 54 41 54 49 43 5.#define STATIC
06b0: 42 55 46 46 45 52 53 49 5a 45 20 20 20 20 31 30 BUFFERSIZE 10
06c0: 30 30 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 00.typedef struc
06d0: 74 20 7b 0a 20 20 20 20 48 41 4e 44 4c 45 20 70 t {. HANDLE p
06e0: 69 70 65 3b 0a 20 20 20 20 63 68 61 72 20 62 75 ipe;. char bu
06f0: 66 66 65 72 5b 53 54 41 54 49 43 42 55 46 46 45 ffer[STATICBUFFE
0700: 52 53 49 5a 45 5d 3b 0a 7d 20 70 69 70 65 69 6e RSIZE];.} pipein
0710: 66 6f 3b 0a 0a 70 69 70 65 69 6e 66 6f 20 4f 75 fo;..pipeinfo Ou
0720: 74 20 3d 20 7b 49 4e 56 41 4c 49 44 5f 48 41 4e t = {INVALID_HAN
0730: 44 4c 45 5f 56 41 4c 55 45 2c 20 27 5c 30 27 7d DLE_VALUE, '\0'}
0740: 3b 0a 70 69 70 65 69 6e 66 6f 20 45 72 72 20 3d ;.pipeinfo Err =
0750: 20 7b 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 {INVALID_HANDLE
0760: 5f 56 41 4c 55 45 2c 20 27 5c 30 27 7d 3b 0a 0c _VALUE, '\0'};..
0770: 0a 2f 2a 0a 20 2a 20 65 78 69 74 63 6f 64 65 73 ./*. * exitcodes
0780: 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 : 0 == no, 1 ==
0790: 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 0a yes, 2 == error.
07a0: 20 2a 2f 0a 0a 69 6e 74 0a 6d 61 69 6e 28 0a 20 */..int.main(.
07b0: 20 20 20 69 6e 74 20 61 72 67 63 2c 0a 20 20 20 int argc,.
07c0: 20 63 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a 7b char *argv[]).{
07d0: 0a 20 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 . char msg[30
07e0: 30 5d 3b 0a 20 20 20 20 44 57 4f 52 44 20 64 77 0];. DWORD dw
07f0: 57 72 69 74 74 65 6e 3b 0a 20 20 20 20 69 6e 74 Written;. int
0800: 20 63 68 61 72 73 3b 0a 0a 20 20 20 20 2f 2a 0a chars;.. /*.
0810: 20 20 20 20 20 2a 20 4d 61 6b 65 20 73 75 72 65 * Make sure
0820: 20 63 68 69 6c 64 72 65 6e 20 28 63 6c 2e 65 78 children (cl.ex
0830: 65 20 61 6e 64 20 6c 69 6e 6b 2e 65 78 65 29 20 e and link.exe)
0840: 61 72 65 20 6b 65 70 74 20 71 75 69 65 74 2e 0a are kept quiet..
0850: 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 53 65 74 */.. Set
0860: 45 72 72 6f 72 4d 6f 64 65 28 53 45 4d 5f 46 41 ErrorMode(SEM_FA
0870: 49 4c 43 52 49 54 49 43 41 4c 45 52 52 4f 52 53 ILCRITICALERRORS
0880: 20 7c 20 53 45 4d 5f 4e 4f 4f 50 45 4e 46 49 4c | SEM_NOOPENFIL
0890: 45 45 52 52 4f 52 42 4f 58 29 3b 0a 0a 20 20 20 EERRORBOX);..
08a0: 20 2f 2a 0a 20 20 20 20 20 2a 20 4d 61 6b 65 20 /*. * Make
08b0: 73 75 72 65 20 74 68 65 20 63 6f 6d 70 69 6c 65 sure the compile
08c0: 72 20 61 6e 64 20 6c 69 6e 6b 65 72 20 61 72 65 r and linker are
08d0: 6e 27 74 20 65 66 66 65 63 74 65 64 20 62 79 20 n't effected by
08e0: 74 68 65 20 6f 75 74 73 69 64 65 20 77 6f 72 6c the outside worl
08f0: 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 d.. */..
0900: 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56 61 SetEnvironmentVa
0910: 72 69 61 62 6c 65 28 22 43 4c 22 2c 20 22 22 29 riable("CL", "")
0920: 3b 0a 20 20 20 20 53 65 74 45 6e 76 69 72 6f 6e ;. SetEnviron
0930: 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 22 4c 49 mentVariable("LI
0940: 4e 4b 22 2c 20 22 22 29 3b 0a 0a 20 20 20 20 69 NK", "");.. i
0950: 66 20 28 61 72 67 63 20 3e 20 31 20 26 26 20 2a f (argc > 1 && *
0960: 61 72 67 76 5b 31 5d 20 3d 3d 20 27 2d 27 29 20 argv[1] == '-')
0970: 7b 0a 09 73 77 69 74 63 68 20 28 2a 28 61 72 67 {..switch (*(arg
0980: 76 5b 31 5d 2b 31 29 29 20 7b 0a 09 63 61 73 65 v[1]+1)) {..case
0990: 20 27 63 27 3a 0a 09 20 20 20 20 69 66 20 28 61 'c':.. if (a
09a0: 72 67 63 20 21 3d 20 33 29 20 7b 0a 09 09 63 68 rgc != 3) {...ch
09b0: 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d ars = snprintf(m
09c0: 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 sg, sizeof(msg)
09d0: 2d 20 31 2c 0a 09 09 20 20 20 20 20 20 20 20 22 - 1,... "
09e0: 75 73 61 67 65 3a 20 25 73 20 2d 63 20 3c 63 6f usage: %s -c <co
09f0: 6d 70 69 6c 65 72 20 6f 70 74 69 6f 6e 3e 5c 6e mpiler option>\n
0a00: 22 0a 09 09 09 22 54 65 73 74 73 20 66 6f 72 20 "...."Tests for
0a10: 77 68 65 74 68 65 72 20 63 6c 2e 65 78 65 20 73 whether cl.exe s
0a20: 75 70 70 6f 72 74 73 20 61 6e 20 6f 70 74 69 6f upports an optio
0a30: 6e 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 n\n"...."exitcod
0a40: 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d es: 0 == no, 1 =
0a50: 3d 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f = yes, 2 == erro
0a60: 72 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a r\n", argv[0]);.
0a70: 09 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 ..WriteFile(GetS
0a80: 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 tdHandle(STD_ERR
0a90: 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c OR_HANDLE), msg,
0aa0: 20 63 68 61 72 73 2c 0a 09 09 09 26 64 77 57 72 chars,....&dwWr
0ab0: 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 itten, NULL);...
0ac0: 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d return 2;.. }
0ad0: 0a 09 20 20 20 20 72 65 74 75 72 6e 20 43 68 65 .. return Che
0ae0: 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 61 ckForCompilerFea
0af0: 74 75 72 65 28 61 72 67 76 5b 32 5d 29 3b 0a 09 ture(argv[2]);..
0b00: 63 61 73 65 20 27 6c 27 3a 0a 09 20 20 20 20 69 case 'l':.. i
0b10: 66 20 28 61 72 67 63 20 21 3d 20 33 29 20 7b 0a f (argc != 3) {.
0b20: 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 69 6e ..chars = snprin
0b30: 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d tf(msg, sizeof(m
0b40: 73 67 29 20 2d 20 31 2c 0a 09 20 20 20 20 20 20 sg) - 1,..
0b50: 20 09 09 22 75 73 61 67 65 3a 20 25 73 20 2d 6c .."usage: %s -l
0b60: 20 3c 6c 69 6e 6b 65 72 20 6f 70 74 69 6f 6e 3e <linker option>
0b70: 5c 6e 22 0a 09 09 09 22 54 65 73 74 73 20 66 6f \n"...."Tests fo
0b80: 72 20 77 68 65 74 68 65 72 20 6c 69 6e 6b 2e 65 r whether link.e
0b90: 78 65 20 73 75 70 70 6f 72 74 73 20 61 6e 20 6f xe supports an o
0ba0: 70 74 69 6f 6e 5c 6e 22 0a 09 09 09 22 65 78 69 ption\n"...."exi
0bb0: 74 63 6f 64 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c tcodes: 0 == no,
0bc0: 20 31 20 3d 3d 20 79 65 73 2c 20 32 20 3d 3d 20 1 == yes, 2 ==
0bd0: 65 72 72 6f 72 5c 6e 22 2c 20 61 72 67 76 5b 30 error\n", argv[0
0be0: 5d 29 3b 0a 09 09 57 72 69 74 65 46 69 6c 65 28 ]);...WriteFile(
0bf0: 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 GetStdHandle(STD
0c00: 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 _ERROR_HANDLE),
0c10: 6d 73 67 2c 20 63 68 61 72 73 2c 0a 09 09 09 26 msg, chars,....&
0c20: 64 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 dwWritten, NULL)
0c30: 3b 0a 09 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 ;...return 2;..
0c40: 20 20 20 7d 0a 09 20 20 20 20 72 65 74 75 72 6e }.. return
0c50: 20 43 68 65 63 6b 46 6f 72 4c 69 6e 6b 65 72 46 CheckForLinkerF
0c60: 65 61 74 75 72 65 28 61 72 67 76 5b 32 5d 29 3b eature(argv[2]);
0c70: 0a 09 63 61 73 65 20 27 66 27 3a 0a 09 20 20 20 ..case 'f':..
0c80: 20 69 66 20 28 61 72 67 63 20 3d 3d 20 32 29 20 if (argc == 2)
0c90: 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 {...chars = snpr
0ca0: 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 intf(msg, sizeof
0cb0: 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 09 22 75 (msg) - 1,...."u
0cc0: 73 61 67 65 3a 20 25 73 20 2d 66 20 3c 73 74 72 sage: %s -f <str
0cd0: 69 6e 67 3e 20 3c 73 75 62 73 74 72 69 6e 67 3e ing> <substring>
0ce0: 5c 6e 22 0a 09 09 09 22 46 69 6e 64 20 61 20 73 \n"...."Find a s
0cf0: 75 62 73 74 72 69 6e 67 20 77 69 74 68 69 6e 20 ubstring within
0d00: 61 6e 6f 74 68 65 72 5c 6e 22 0a 09 09 09 22 65 another\n"...."e
0d10: 78 69 74 63 6f 64 65 73 3a 20 30 20 3d 3d 20 6e xitcodes: 0 == n
0d20: 6f 2c 20 31 20 3d 3d 20 79 65 73 2c 20 32 20 3d o, 1 == yes, 2 =
0d30: 3d 20 65 72 72 6f 72 5c 6e 22 2c 20 61 72 67 76 = error\n", argv
0d40: 5b 30 5d 29 3b 0a 09 09 57 72 69 74 65 46 69 6c [0]);...WriteFil
0d50: 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53 e(GetStdHandle(S
0d60: 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 TD_ERROR_HANDLE)
0d70: 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 0a 09 09 , msg, chars,...
0d80: 09 26 64 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c .&dwWritten, NUL
0d90: 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 32 3b 0a L);...return 2;.
0da0: 09 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 . } else if (
0db0: 61 72 67 63 20 3d 3d 20 33 29 20 7b 0a 09 09 2f argc == 3) {.../
0dc0: 2a 0a 09 09 20 2a 20 49 66 20 74 68 65 20 73 74 *... * If the st
0dd0: 72 69 6e 67 20 69 73 20 62 6c 61 6e 6b 2c 20 74 ring is blank, t
0de0: 68 65 72 65 20 69 73 20 6e 6f 20 6d 61 74 63 68 here is no match
0df0: 2e 0a 09 09 20 2a 2f 0a 0a 09 09 72 65 74 75 72 .... */....retur
0e00: 6e 20 30 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 n 0;.. } else
0e10: 20 7b 0a 09 09 72 65 74 75 72 6e 20 49 73 49 6e {...return IsIn
0e20: 28 61 72 67 76 5b 32 5d 2c 20 61 72 67 76 5b 33 (argv[2], argv[3
0e30: 5d 29 3b 0a 09 20 20 20 20 7d 0a 09 63 61 73 65 ]);.. }..case
0e40: 20 27 67 27 3a 0a 09 20 20 20 20 69 66 20 28 61 'g':.. if (a
0e50: 72 67 63 20 3d 3d 20 32 29 20 7b 0a 09 09 63 68 rgc == 2) {...ch
0e60: 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d ars = snprintf(m
0e70: 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 sg, sizeof(msg)
0e80: 2d 20 31 2c 0a 09 09 09 22 75 73 61 67 65 3a 20 - 1,...."usage:
0e90: 25 73 20 2d 67 20 3c 66 69 6c 65 3e 20 3c 73 74 %s -g <file> <st
0ea0: 72 69 6e 67 3e 5c 6e 22 0a 09 09 09 22 67 72 65 ring>\n"...."gre
0eb0: 70 20 66 6f 72 20 61 20 23 64 65 66 69 6e 65 5c p for a #define\
0ec0: 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 65 73 n"...."exitcodes
0ed0: 3a 20 69 6e 74 65 67 65 72 20 6f 66 20 74 68 65 : integer of the
0ee0: 20 66 6f 75 6e 64 20 73 74 72 69 6e 67 20 28 6e found string (n
0ef0: 6f 20 64 65 63 69 6d 61 6c 73 29 5c 6e 22 2c 0a o decimals)\n",.
0f00: 09 09 09 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 ...argv[0]);...W
0f10: 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 riteFile(GetStdH
0f20: 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f andle(STD_ERROR_
0f30: 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 HANDLE), msg, ch
0f40: 61 72 73 2c 0a 09 09 09 26 64 77 57 72 69 74 74 ars,....&dwWritt
0f50: 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 en, NULL);...ret
0f60: 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 urn 2;.. }..
0f70: 20 20 20 72 65 74 75 72 6e 20 47 72 65 70 46 6f return GrepFo
0f80: 72 44 65 66 69 6e 65 28 61 72 67 76 5b 32 5d 2c rDefine(argv[2],
0f90: 20 61 72 67 76 5b 33 5d 29 3b 0a 09 63 61 73 65 argv[3]);..case
0fa0: 20 27 73 27 3a 0a 09 20 20 20 20 69 66 20 28 61 's':.. if (a
0fb0: 72 67 63 20 3d 3d 20 32 29 20 7b 0a 09 09 63 68 rgc == 2) {...ch
0fc0: 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d ars = snprintf(m
0fd0: 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 sg, sizeof(msg)
0fe0: 2d 20 31 2c 0a 09 09 09 22 75 73 61 67 65 3a 20 - 1,...."usage:
0ff0: 25 73 20 2d 73 20 3c 73 75 62 73 74 69 74 75 74 %s -s <substitut
1000: 69 6f 6e 73 20 66 69 6c 65 3e 20 3c 66 69 6c 65 ions file> <file
1010: 3e 5c 6e 22 0a 09 09 09 22 50 65 72 66 6f 72 6d >\n"...."Perform
1020: 20 61 20 73 65 74 20 6f 66 20 73 74 72 69 6e 67 a set of string
1030: 20 6d 61 70 20 74 79 70 65 20 73 75 62 73 74 75 map type substu
1040: 74 69 74 69 6f 6e 73 20 6f 6e 20 61 20 66 69 6c titions on a fil
1050: 65 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 e\n"...."exitcod
1060: 65 73 3a 20 30 5c 6e 22 2c 0a 09 09 09 61 72 67 es: 0\n",....arg
1070: 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 65 46 69 v[0]);...WriteFi
1080: 6c 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 28 le(GetStdHandle(
1090: 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 STD_ERROR_HANDLE
10a0: 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 0a 09 ), msg, chars,..
10b0: 09 09 26 64 77 57 72 69 74 74 65 6e 2c 20 4e 55 ..&dwWritten, NU
10c0: 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 32 3b LL);...return 2;
10d0: 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 72 65 74 .. }.. ret
10e0: 75 72 6e 20 53 75 62 73 74 69 74 75 74 65 46 69 urn SubstituteFi
10f0: 6c 65 28 61 72 67 76 5b 32 5d 2c 20 61 72 67 76 le(argv[2], argv
1100: 5b 33 5d 29 3b 0a 09 63 61 73 65 20 27 56 27 3a [3]);..case 'V':
1110: 0a 09 20 20 20 20 69 66 20 28 61 72 67 63 20 21 .. if (argc !
1120: 3d 20 34 29 20 7b 0a 09 09 63 68 61 72 73 20 3d = 4) {...chars =
1130: 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 snprintf(msg, s
1140: 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a izeof(msg) - 1,.
1150: 09 09 20 20 20 20 22 75 73 61 67 65 3a 20 25 73 .. "usage: %s
1160: 20 2d 56 20 66 69 6c 65 6e 61 6d 65 20 6d 61 74 -V filename mat
1170: 63 68 73 74 72 69 6e 67 5c 6e 22 0a 09 09 20 20 chstring\n"...
1180: 20 20 22 45 78 74 72 61 63 74 20 61 20 76 65 72 "Extract a ver
1190: 73 69 6f 6e 20 66 72 6f 6d 20 61 20 66 69 6c 65 sion from a file
11a0: 3a 5c 6e 22 0a 09 09 20 20 20 20 22 65 67 3a 20 :\n"... "eg:
11b0: 70 6b 67 49 6e 64 65 78 2e 74 63 6c 20 5c 22 70 pkgIndex.tcl \"p
11c0: 61 63 6b 61 67 65 20 69 66 6e 65 65 64 65 64 20 ackage ifneeded
11d0: 68 74 74 70 5c 22 22 2c 0a 09 09 20 20 20 20 61 http\"",... a
11e0: 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 65 rgv[0]);...Write
11f0: 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 6c File(GetStdHandl
1200: 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 e(STD_ERROR_HAND
1210: 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c LE), msg, chars,
1220: 0a 09 09 20 20 20 20 26 64 77 57 72 69 74 74 65 ... &dwWritte
1230: 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 n, NULL);...retu
1240: 72 6e 20 30 3b 0a 09 20 20 20 20 7d 0a 09 20 20 rn 0;.. }..
1250: 20 20 70 72 69 6e 74 66 28 22 25 73 5c 6e 22 2c printf("%s\n",
1260: 20 47 65 74 56 65 72 73 69 6f 6e 46 72 6f 6d 46 GetVersionFromF
1270: 69 6c 65 28 61 72 67 76 5b 32 5d 2c 20 61 72 67 ile(argv[2], arg
1280: 76 5b 33 5d 29 29 3b 0a 09 20 20 20 20 72 65 74 v[3]));.. ret
1290: 75 72 6e 20 30 3b 0a 09 63 61 73 65 20 27 51 27 urn 0;..case 'Q'
12a0: 3a 0a 09 20 20 20 20 69 66 20 28 61 72 67 63 20 :.. if (argc
12b0: 21 3d 20 33 29 20 7b 0a 09 09 63 68 61 72 73 20 != 3) {...chars
12c0: 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 = snprintf(msg,
12d0: 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c sizeof(msg) - 1,
12e0: 0a 09 09 20 20 20 20 22 75 73 61 67 65 3a 20 25 ... "usage: %
12f0: 73 20 2d 71 20 70 61 74 68 5c 6e 22 0a 09 09 20 s -q path\n"...
1300: 20 20 20 22 45 6d 69 74 20 74 68 65 20 66 75 6c "Emit the ful
1310: 6c 79 20 71 75 61 6c 69 66 69 65 64 20 70 61 74 ly qualified pat
1320: 68 5c 6e 22 0a 09 09 20 20 20 20 22 65 78 69 74 h\n"... "exit
1330: 63 6f 64 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 codes: 0 == no,
1340: 31 20 3d 3d 20 79 65 73 2c 20 32 20 3d 3d 20 65 1 == yes, 2 == e
1350: 72 72 6f 72 5c 6e 22 2c 20 61 72 67 76 5b 30 5d rror\n", argv[0]
1360: 29 3b 0a 09 09 57 72 69 74 65 46 69 6c 65 28 47 );...WriteFile(G
1370: 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f etStdHandle(STD_
1380: 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d ERROR_HANDLE), m
1390: 73 67 2c 20 63 68 61 72 73 2c 0a 09 09 20 20 20 sg, chars,...
13a0: 20 26 64 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c &dwWritten, NUL
13b0: 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 32 3b 0a L);...return 2;.
13c0: 09 20 20 20 20 7d 0a 09 20 20 20 20 72 65 74 75 . }.. retu
13d0: 72 6e 20 51 75 61 6c 69 66 79 50 61 74 68 28 61 rn QualifyPath(a
13e0: 72 67 76 5b 32 5d 29 3b 0a 09 7d 0a 20 20 20 20 rgv[2]);..}.
13f0: 7d 0a 20 20 20 20 63 68 61 72 73 20 3d 20 73 6e }. chars = sn
1400: 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 printf(msg, size
1410: 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 20 20 of(msg) - 1,..
1420: 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 63 7c "usage: %s -c|
1430: 2d 6c 7c 2d 66 7c 2d 67 7c 2d 56 7c 2d 73 7c 2d -l|-f|-g|-V|-s|-
1440: 51 20 2e 2e 2e 5c 6e 22 0a 09 20 20 20 20 22 54 Q ...\n".. "T
1450: 68 69 73 20 69 73 20 61 20 6c 69 74 74 6c 65 20 his is a little
1460: 68 65 6c 70 65 72 20 61 70 70 20 74 6f 20 65 71 helper app to eq
1470: 75 61 6c 69 7a 65 20 73 68 65 6c 6c 20 64 69 66 ualize shell dif
1480: 66 65 72 65 6e 63 65 73 20 62 65 74 77 65 65 6e ferences between
1490: 20 57 69 6e 4e 54 20 61 6e 64 5c 6e 22 0a 09 20 WinNT and\n"..
14a0: 20 20 20 22 57 69 6e 39 78 20 61 6e 64 20 67 65 "Win9x and ge
14b0: 74 20 6e 6d 61 6b 65 2e 65 78 65 20 74 6f 20 61 t nmake.exe to a
14c0: 63 63 6f 6d 70 6c 69 73 68 20 69 74 73 20 6a 6f ccomplish its jo
14d0: 62 2e 5c 6e 22 2c 0a 09 20 20 20 20 61 72 67 76 b.\n",.. argv
14e0: 5b 30 5d 29 3b 0a 20 20 20 20 57 72 69 74 65 46 [0]);. WriteF
14f0: 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 ile(GetStdHandle
1500: 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c (STD_ERROR_HANDL
1510: 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 20 E), msg, chars,
1520: 26 64 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c &dwWritten, NULL
1530: 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 32 3b );. return 2;
1540: 0a 7d 0a 0c 0a 69 6e 74 0a 43 68 65 63 6b 46 6f .}...int.CheckFo
1550: 72 43 6f 6d 70 69 6c 65 72 46 65 61 74 75 72 65 rCompilerFeature
1560: 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 (. const char
1570: 20 2a 6f 70 74 69 6f 6e 29 0a 7b 0a 20 20 20 20 *option).{.
1580: 53 54 41 52 54 55 50 49 4e 46 4f 20 73 69 3b 0a STARTUPINFO si;.
1590: 20 20 20 20 50 52 4f 43 45 53 53 5f 49 4e 46 4f PROCESS_INFO
15a0: 52 4d 41 54 49 4f 4e 20 70 69 3b 0a 20 20 20 20 RMATION pi;.
15b0: 53 45 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 SECURITY_ATTRIBU
15c0: 54 45 53 20 73 61 3b 0a 20 20 20 20 44 57 4f 52 TES sa;. DWOR
15d0: 44 20 74 68 72 65 61 64 49 44 3b 0a 20 20 20 20 D threadID;.
15e0: 63 68 61 72 20 6d 73 67 5b 33 30 30 5d 3b 0a 20 char msg[300];.
15f0: 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 20 20 20 20 BOOL ok;.
1600: 48 41 4e 44 4c 45 20 68 50 72 6f 63 65 73 73 2c HANDLE hProcess,
1610: 20 68 2c 20 70 69 70 65 54 68 72 65 61 64 73 5b h, pipeThreads[
1620: 32 5d 3b 0a 20 20 20 20 63 68 61 72 20 63 6d 64 2];. char cmd
1630: 6c 69 6e 65 5b 31 30 30 5d 3b 0a 0a 20 20 20 20 line[100];..
1640: 68 50 72 6f 63 65 73 73 20 3d 20 47 65 74 43 75 hProcess = GetCu
1650: 72 72 65 6e 74 50 72 6f 63 65 73 73 28 29 3b 0a rrentProcess();.
1660: 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 . ZeroMemory(
1670: 26 70 69 2c 20 73 69 7a 65 6f 66 28 50 52 4f 43 &pi, sizeof(PROC
1680: 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 29 ESS_INFORMATION)
1690: 29 3b 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 );. ZeroMemor
16a0: 79 28 26 73 69 2c 20 73 69 7a 65 6f 66 28 53 54 y(&si, sizeof(ST
16b0: 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a 20 20 20 ARTUPINFO));.
16c0: 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 6f 66 28 si.cb = sizeof(
16d0: 53 54 41 52 54 55 50 49 4e 46 4f 29 3b 0a 20 20 STARTUPINFO);.
16e0: 20 20 73 69 2e 64 77 46 6c 61 67 73 20 20 20 3d si.dwFlags =
16f0: 20 53 54 41 52 54 46 5f 55 53 45 53 54 44 48 41 STARTF_USESTDHA
1700: 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 2e 68 53 NDLES;. si.hS
1710: 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 41 4c 49 tdInput = INVALI
1720: 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 3b 0a D_HANDLE_VALUE;.
1730: 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 . ZeroMemory(
1740: 26 73 61 2c 20 73 69 7a 65 6f 66 28 53 45 43 55 &sa, sizeof(SECU
1750: 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 RITY_ATTRIBUTES)
1760: 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e 67 74 );. sa.nLengt
1770: 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43 55 52 h = sizeof(SECUR
1780: 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 3b ITY_ATTRIBUTES);
1790: 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75 72 69 . sa.lpSecuri
17a0: 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d 20 4e tyDescriptor = N
17b0: 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49 6e 68 ULL;. sa.bInh
17c0: 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 46 41 4c eritHandle = FAL
17d0: 53 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 SE;.. /*.
17e0: 20 2a 20 43 72 65 61 74 65 20 61 20 6e 6f 6e 2d * Create a non-
17f0: 69 6e 68 65 72 69 74 69 62 6c 65 20 70 69 70 65 inheritible pipe
1800: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 .. */.. C
1810: 72 65 61 74 65 50 69 70 65 28 26 4f 75 74 2e 70 reatePipe(&Out.p
1820: 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 ipe, &h, &sa, 0)
1830: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
1840: 20 44 75 70 65 20 74 68 65 20 77 72 69 74 65 20 Dupe the write
1850: 73 69 64 65 2c 20 6d 61 6b 65 20 69 74 20 69 6e side, make it in
1860: 68 65 72 69 74 69 62 6c 65 2c 20 61 6e 64 20 63 heritible, and c
1870: 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 69 6e 61 lose the origina
1880: 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 l.. */..
1890: 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 DuplicateHandle(
18a0: 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 hProcess, h, hPr
18b0: 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 4f ocess, &si.hStdO
18c0: 75 74 70 75 74 2c 20 30 2c 20 54 52 55 45 2c 0a utput, 0, TRUE,.
18d0: 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 . DUPLICATE_S
18e0: 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 AME_ACCESS | DUP
18f0: 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 LICATE_CLOSE_SOU
1900: 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 RCE);.. /*.
1910: 20 20 20 2a 20 53 61 6d 65 20 61 73 20 61 62 6f * Same as abo
1920: 76 65 2c 20 62 75 74 20 66 6f 72 20 74 68 65 20 ve, but for the
1930: 65 72 72 6f 72 20 73 69 64 65 2e 0a 20 20 20 20 error side..
1940: 20 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 65 50 */.. CreateP
1950: 69 70 65 28 26 45 72 72 2e 70 69 70 65 2c 20 26 ipe(&Err.pipe, &
1960: 68 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20 20 20 h, &sa, 0);.
1970: 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 DuplicateHandle(
1980: 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 hProcess, h, hPr
1990: 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 45 ocess, &si.hStdE
19a0: 72 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c 0a 09 rror, 0, TRUE,..
19b0: 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 41 DUPLICATE_SA
19c0: 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 4c ME_ACCESS | DUPL
19d0: 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 52 ICATE_CLOSE_SOUR
19e0: 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 CE);.. /*.
19f0: 20 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61 6e 64 * Base command
1a00: 20 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a line.. */..
1a10: 20 20 20 20 6c 73 74 72 63 70 79 28 63 6d 64 6c lstrcpy(cmdl
1a20: 69 6e 65 2c 20 22 63 6c 2e 65 78 65 20 2d 6e 6f ine, "cl.exe -no
1a30: 6c 6f 67 6f 20 2d 63 20 2d 54 43 20 2d 5a 73 20 logo -c -TC -Zs
1a40: 2d 58 20 2d 46 70 2e 5c 5c 5f 6a 75 6e 6b 2e 70 -X -Fp.\\_junk.p
1a50: 63 68 20 22 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 ch ");.. /*.
1a60: 20 20 20 20 2a 20 41 70 70 65 6e 64 20 6f 75 72 * Append our
1a70: 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 65 73 74 option for test
1a80: 69 6e 67 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 ing. */..
1a90: 20 6c 73 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 lstrcat(cmdline
1aa0: 2c 20 6f 70 74 69 6f 6e 29 3b 0a 0a 20 20 20 20 , option);..
1ab0: 2f 2a 0a 20 20 20 20 20 2a 20 46 69 6c 65 6e 61 /*. * Filena
1ac0: 6d 65 20 74 6f 20 63 6f 6d 70 69 6c 65 2c 20 77 me to compile, w
1ad0: 68 69 63 68 20 65 78 69 73 74 73 2c 20 62 75 74 hich exists, but
1ae0: 20 69 73 20 6e 6f 74 68 69 6e 67 20 61 6e 64 20 is nothing and
1af0: 65 6d 70 74 79 2e 0a 20 20 20 20 20 2a 2f 0a 0a empty.. */..
1b00: 20 20 20 20 6c 73 74 72 63 61 74 28 63 6d 64 6c lstrcat(cmdl
1b10: 69 6e 65 2c 20 22 20 2e 5c 5c 6e 75 6c 22 29 3b ine, " .\\nul");
1b20: 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 65 61 74 .. ok = Creat
1b30: 65 50 72 6f 63 65 73 73 28 0a 09 20 20 20 20 4e eProcess(.. N
1b40: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d 6f 64 75 ULL,. /* Modu
1b50: 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 20 20 20 le name. */..
1b60: 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 20 2f 2a cmdline,. /*
1b70: 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 20 2a Command line. *
1b80: 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 /.. NULL,.
1b90: 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 61 6e 64 /* Process hand
1ba0: 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 74 61 62 le not inheritab
1bb0: 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c le. */.. NULL
1bc0: 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 61 64 20 ,. /* Thread
1bd0: 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 handle not inher
1be0: 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 itable. */..
1bf0: 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 79 65 73 TRUE,. /* yes
1c00: 2c 20 69 6e 68 65 72 69 74 20 68 61 6e 64 6c 65 , inherit handle
1c10: 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 54 41 43 s. */.. DETAC
1c20: 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 2f 2a 20 HED_PROCESS, /*
1c30: 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f 72 20 79 No console for y
1c40: 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c ou. */.. NULL
1c50: 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 70 61 72 ,. /* Use par
1c60: 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e 6d 65 6e ent's environmen
1c70: 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 20 20 20 t block. */..
1c80: 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 NULL,. /* Us
1c90: 65 20 70 61 72 65 6e 74 27 73 20 73 74 61 72 74 e parent's start
1ca0: 69 6e 67 20 64 69 72 65 63 74 6f 72 79 2e 20 2a ing directory. *
1cb0: 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 20 20 20 /.. &si,.
1cc0: 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 53 54 /* Pointer to ST
1cd0: 41 52 54 55 50 49 4e 46 4f 20 73 74 72 75 63 74 ARTUPINFO struct
1ce0: 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 26 70 69 ure. */.. &pi
1cf0: 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 );. /* Pointe
1d00: 72 20 74 6f 20 50 52 4f 43 45 53 53 5f 49 4e 46 r to PROCESS_INF
1d10: 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 63 74 75 ORMATION structu
1d20: 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 re. */.. if (
1d30: 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 20 65 72 !ok) {..DWORD er
1d40: 72 20 3d 20 47 65 74 4c 61 73 74 45 72 72 6f 72 r = GetLastError
1d50: 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 73 20 3d ();..int chars =
1d60: 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 snprintf(msg, s
1d70: 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a izeof(msg) - 1,.
1d80: 09 09 22 54 72 69 65 64 20 74 6f 20 6c 61 75 6e .."Tried to laun
1d90: 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 75 74 20 ch: \"%s\", but
1da0: 67 6f 74 20 65 72 72 6f 72 20 5b 25 75 5d 3a 20 got error [%u]:
1db0: 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65 72 72 29 ", cmdline, err)
1dc0: 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73 73 61 67 ;...FormatMessag
1dd0: 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 e(FORMAT_MESSAGE
1de0: 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c 46 4f 52 _FROM_SYSTEM|FOR
1df0: 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49 47 4e 4f MAT_MESSAGE_IGNO
1e00: 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09 09 46 4f RE_INSERTS|...FO
1e10: 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 4d 41 58 RMAT_MESSAGE_MAX
1e20: 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20 30 4c 2c _WIDTH_MASK, 0L,
1e30: 20 65 72 72 2c 20 30 2c 20 28 4c 50 56 4f 49 44 err, 0, (LPVOID
1e40: 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c 0a 09 09 )&msg[chars],...
1e50: 28 33 30 30 2d 63 68 61 72 73 29 2c 20 30 29 3b (300-chars), 0);
1e60: 0a 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 ..WriteFile(GetS
1e70: 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 tdHandle(STD_ERR
1e80: 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c OR_HANDLE), msg,
1e90: 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c 20 26 65 lstrlen(msg), &e
1ea0: 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65 74 75 72 rr,NULL);..retur
1eb0: 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 n 2;. }..
1ec0: 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f 73 65 20 /*. * Close
1ed0: 6f 75 72 20 72 65 66 65 72 65 6e 63 65 73 20 74 our references t
1ee0: 6f 20 74 68 65 20 77 72 69 74 65 20 68 61 6e 64 o the write hand
1ef0: 6c 65 73 20 74 68 61 74 20 68 61 76 65 20 6e 6f les that have no
1f00: 77 20 62 65 65 6e 20 69 6e 68 65 72 69 74 65 64 w been inherited
1f10: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 .. */.. C
1f20: 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 53 loseHandle(si.hS
1f30: 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 20 20 43 tdOutput);. C
1f40: 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 53 loseHandle(si.hS
1f50: 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 20 20 57 tdError);.. W
1f60: 61 69 74 46 6f 72 49 6e 70 75 74 49 64 6c 65 28 aitForInputIdle(
1f70: 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 35 30 30 pi.hProcess, 500
1f80: 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 0);. CloseHan
1f90: 64 6c 65 28 70 69 2e 68 54 68 72 65 61 64 29 3b dle(pi.hThread);
1fa0: 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 .. /*. *
1fb0: 53 74 61 72 74 20 74 68 65 20 70 69 70 65 20 72 Start the pipe r
1fc0: 65 61 64 65 72 20 74 68 72 65 61 64 73 2e 0a 20 eader threads..
1fd0: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70 69 70 65 */.. pipe
1fe0: 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 43 72 65 Threads[0] = Cre
1ff0: 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 ateThread(NULL,
2000: 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 2c 0, ReadFromPipe,
2010: 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 72 65 61 &Out, 0, &threa
2020: 64 49 44 29 3b 0a 20 20 20 20 70 69 70 65 54 68 dID);. pipeTh
2030: 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 65 61 74 reads[1] = Creat
2040: 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 30 2c eThread(NULL, 0,
2050: 20 52 65 61 64 46 72 6f 6d 50 69 70 65 2c 20 26 ReadFromPipe, &
2060: 45 72 72 2c 20 30 2c 20 26 74 68 72 65 61 64 49 Err, 0, &threadI
2070: 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 D);.. /*.
2080: 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74 69 6e 67 * Block waiting
2090: 20 66 6f 72 20 74 68 65 20 70 72 6f 63 65 73 73 for the process
20a0: 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20 20 2a 2f to end.. */
20b0: 0a 0a 20 20 20 20 57 61 69 74 46 6f 72 53 69 6e .. WaitForSin
20c0: 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e 68 50 72 gleObject(pi.hPr
20d0: 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49 54 45 29 ocess, INFINITE)
20e0: 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c ;. CloseHandl
20f0: 65 28 70 69 2e 68 50 72 6f 63 65 73 73 29 3b 0a e(pi.hProcess);.
2100: 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 57 . /*. * W
2110: 61 69 74 20 66 6f 72 20 6f 75 72 20 70 69 70 65 ait for our pipe
2120: 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 72 65 61 to get done rea
2130: 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 69 74 20 ding, should it
2140: 62 65 20 61 20 6c 69 74 74 6c 65 20 73 6c 6f 77 be a little slow
2150: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 57 .. */.. W
2160: 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c 65 4f 62 aitForMultipleOb
2170: 6a 65 63 74 73 28 32 2c 20 70 69 70 65 54 68 72 jects(2, pipeThr
2180: 65 61 64 73 2c 20 54 52 55 45 2c 20 35 30 30 29 eads, TRUE, 500)
2190: 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c ;. CloseHandl
21a0: 65 28 70 69 70 65 54 68 72 65 61 64 73 5b 30 5d e(pipeThreads[0]
21b0: 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 );. CloseHand
21c0: 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 5b 31 le(pipeThreads[1
21d0: 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 ]);.. /*.
21e0: 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74 68 65 20 * Look for the
21f0: 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77 61 72 6e commandline warn
2200: 69 6e 67 20 63 6f 64 65 20 69 6e 20 62 6f 74 68 ing code in both
2210: 20 73 74 72 65 61 6d 73 2e 0a 20 20 20 20 20 2a streams.. *
2220: 20 20 2d 20 69 6e 20 4d 53 56 43 20 36 20 26 20 - in MSVC 6 &
2230: 37 20 77 65 20 67 65 74 20 44 34 30 30 32 2c 20 7 we get D4002,
2240: 69 6e 20 4d 53 56 43 20 38 20 77 65 20 67 65 74 in MSVC 8 we get
2250: 20 44 39 30 30 32 2e 0a 20 20 20 20 20 2a 2f 0a D9002.. */.
2260: 0a 20 20 20 20 72 65 74 75 72 6e 20 21 28 73 74 . return !(st
2270: 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 72 2c rstr(Out.buffer,
2280: 20 22 44 34 30 30 32 22 29 20 21 3d 20 4e 55 4c "D4002") != NUL
2290: 4c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 7c L. |
22a0: 7c 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 66 | strstr(Err.buf
22b0: 66 65 72 2c 20 22 44 34 30 30 32 22 29 20 21 3d fer, "D4002") !=
22c0: 20 4e 55 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 NULL.
22d0: 20 20 20 7c 7c 20 73 74 72 73 74 72 28 4f 75 74 || strstr(Out
22e0: 2e 62 75 66 66 65 72 2c 20 22 44 39 30 30 32 22 .buffer, "D9002"
22f0: 29 20 21 3d 20 4e 55 4c 4c 0a 20 20 20 20 20 20 ) != NULL.
2300: 20 20 20 20 20 20 20 7c 7c 20 73 74 72 73 74 72 || strstr
2310: 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 44 39 (Err.buffer, "D9
2320: 30 30 32 22 29 20 21 3d 20 4e 55 4c 4c 0a 20 20 002") != NULL.
2330: 20 20 20 20 20 20 20 20 20 20 20 7c 7c 20 73 74 || st
2340: 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 72 2c rstr(Out.buffer,
2350: 20 22 44 32 30 32 31 22 29 20 21 3d 20 4e 55 4c "D2021") != NUL
2360: 4c 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 7c L. |
2370: 7c 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 66 | strstr(Err.buf
2380: 66 65 72 2c 20 22 44 32 30 32 31 22 29 20 21 3d fer, "D2021") !=
2390: 20 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a 69 6e 74 0a NULL);.}...int.
23a0: 43 68 65 63 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 CheckForLinkerFe
23b0: 61 74 75 72 65 28 0a 20 20 20 20 63 6f 6e 73 74 ature(. const
23c0: 20 63 68 61 72 20 2a 6f 70 74 69 6f 6e 29 0a 7b char *option).{
23d0: 0a 20 20 20 20 53 54 41 52 54 55 50 49 4e 46 4f . STARTUPINFO
23e0: 20 73 69 3b 0a 20 20 20 20 50 52 4f 43 45 53 53 si;. PROCESS
23f0: 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 70 69 3b _INFORMATION pi;
2400: 0a 20 20 20 20 53 45 43 55 52 49 54 59 5f 41 54 . SECURITY_AT
2410: 54 52 49 42 55 54 45 53 20 73 61 3b 0a 20 20 20 TRIBUTES sa;.
2420: 20 44 57 4f 52 44 20 74 68 72 65 61 64 49 44 3b DWORD threadID;
2430: 0a 20 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 . char msg[30
2440: 30 5d 3b 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0];. BOOL ok;
2450: 0a 20 20 20 20 48 41 4e 44 4c 45 20 68 50 72 6f . HANDLE hPro
2460: 63 65 73 73 2c 20 68 2c 20 70 69 70 65 54 68 72 cess, h, pipeThr
2470: 65 61 64 73 5b 32 5d 3b 0a 20 20 20 20 63 68 61 eads[2];. cha
2480: 72 20 63 6d 64 6c 69 6e 65 5b 31 30 30 5d 3b 0a r cmdline[100];.
2490: 0a 20 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20 . hProcess =
24a0: 47 65 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73 GetCurrentProces
24b0: 73 28 29 3b 0a 0a 20 20 20 20 5a 65 72 6f 4d 65 s();.. ZeroMe
24c0: 6d 6f 72 79 28 26 70 69 2c 20 73 69 7a 65 6f 66 mory(&pi, sizeof
24d0: 28 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 (PROCESS_INFORMA
24e0: 54 49 4f 4e 29 29 3b 0a 20 20 20 20 5a 65 72 6f TION));. Zero
24f0: 4d 65 6d 6f 72 79 28 26 73 69 2c 20 73 69 7a 65 Memory(&si, size
2500: 6f 66 28 53 54 41 52 54 55 50 49 4e 46 4f 29 29 of(STARTUPINFO))
2510: 3b 0a 20 20 20 20 73 69 2e 63 62 20 3d 20 73 69 ;. si.cb = si
2520: 7a 65 6f 66 28 53 54 41 52 54 55 50 49 4e 46 4f zeof(STARTUPINFO
2530: 29 3b 0a 20 20 20 20 73 69 2e 64 77 46 6c 61 67 );. si.dwFlag
2540: 73 20 20 20 3d 20 53 54 41 52 54 46 5f 55 53 45 s = STARTF_USE
2550: 53 54 44 48 41 4e 44 4c 45 53 3b 0a 20 20 20 20 STDHANDLES;.
2560: 73 69 2e 68 53 74 64 49 6e 70 75 74 20 3d 20 49 si.hStdInput = I
2570: 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 NVALID_HANDLE_VA
2580: 4c 55 45 3b 0a 0a 20 20 20 20 5a 65 72 6f 4d 65 LUE;.. ZeroMe
2590: 6d 6f 72 79 28 26 73 61 2c 20 73 69 7a 65 6f 66 mory(&sa, sizeof
25a0: 28 53 45 43 55 52 49 54 59 5f 41 54 54 52 49 42 (SECURITY_ATTRIB
25b0: 55 54 45 53 29 29 3b 0a 20 20 20 20 73 61 2e 6e UTES));. sa.n
25c0: 4c 65 6e 67 74 68 20 3d 20 73 69 7a 65 6f 66 28 Length = sizeof(
25d0: 53 45 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 SECURITY_ATTRIBU
25e0: 54 45 53 29 3b 0a 20 20 20 20 73 61 2e 6c 70 53 TES);. sa.lpS
25f0: 65 63 75 72 69 74 79 44 65 73 63 72 69 70 74 6f ecurityDescripto
2600: 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 73 61 r = NULL;. sa
2610: 2e 62 49 6e 68 65 72 69 74 48 61 6e 64 6c 65 20 .bInheritHandle
2620: 3d 20 54 52 55 45 3b 0a 0a 20 20 20 20 2f 2a 0a = TRUE;.. /*.
2630: 20 20 20 20 20 2a 20 43 72 65 61 74 65 20 61 20 * Create a
2640: 6e 6f 6e 2d 69 6e 68 65 72 69 74 69 62 6c 65 20 non-inheritible
2650: 70 69 70 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 pipe.. */..
2660: 20 20 20 43 72 65 61 74 65 50 69 70 65 28 26 4f CreatePipe(&O
2670: 75 74 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 ut.pipe, &h, &sa
2680: 2c 20 30 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 , 0);.. /*.
2690: 20 20 20 2a 20 44 75 70 65 20 74 68 65 20 77 72 * Dupe the wr
26a0: 69 74 65 20 73 69 64 65 2c 20 6d 61 6b 65 20 69 ite side, make i
26b0: 74 20 69 6e 68 65 72 69 74 69 62 6c 65 2c 20 61 t inheritible, a
26c0: 6e 64 20 63 6c 6f 73 65 20 74 68 65 20 6f 72 69 nd close the ori
26d0: 67 69 6e 61 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a ginal.. */..
26e0: 20 20 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e DuplicateHan
26f0: 64 6c 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c dle(hProcess, h,
2700: 20 68 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 hProcess, &si.h
2710: 53 74 64 4f 75 74 70 75 74 2c 20 30 2c 20 54 52 StdOutput, 0, TR
2720: 55 45 2c 0a 09 20 20 20 20 44 55 50 4c 49 43 41 UE,.. DUPLICA
2730: 54 45 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c TE_SAME_ACCESS |
2740: 20 44 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 DUPLICATE_CLOSE
2750: 5f 53 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f _SOURCE);.. /
2760: 2a 0a 20 20 20 20 20 2a 20 53 61 6d 65 20 61 73 *. * Same as
2770: 20 61 62 6f 76 65 2c 20 62 75 74 20 66 6f 72 20 above, but for
2780: 74 68 65 20 65 72 72 6f 72 20 73 69 64 65 2e 0a the error side..
2790: 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 72 65 */.. Cre
27a0: 61 74 65 50 69 70 65 28 26 45 72 72 2e 70 69 70 atePipe(&Err.pip
27b0: 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 3b 0a e, &h, &sa, 0);.
27c0: 20 20 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e DuplicateHan
27d0: 64 6c 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c dle(hProcess, h,
27e0: 20 68 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 hProcess, &si.h
27f0: 53 74 64 45 72 72 6f 72 2c 20 30 2c 20 54 52 55 StdError, 0, TRU
2800: 45 2c 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 E,.. DUPLICAT
2810: 45 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 E_SAME_ACCESS |
2820: 44 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f DUPLICATE_CLOSE_
2830: 53 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a SOURCE);.. /*
2840: 0a 20 20 20 20 20 2a 20 42 61 73 65 20 63 6f 6d . * Base com
2850: 6d 61 6e 64 20 6c 69 6e 65 2e 0a 20 20 20 20 20 mand line..
2860: 2a 2f 0a 0a 20 20 20 20 6c 73 74 72 63 70 79 28 */.. lstrcpy(
2870: 63 6d 64 6c 69 6e 65 2c 20 22 6c 69 6e 6b 2e 65 cmdline, "link.e
2880: 78 65 20 2d 6e 6f 6c 6f 67 6f 20 22 29 3b 0a 0a xe -nologo ");..
2890: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 41 70 /*. * Ap
28a0: 70 65 6e 64 20 6f 75 72 20 6f 70 74 69 6f 6e 20 pend our option
28b0: 66 6f 72 20 74 65 73 74 69 6e 67 2e 0a 20 20 20 for testing..
28c0: 20 20 2a 2f 0a 0a 20 20 20 20 6c 73 74 72 63 61 */.. lstrca
28d0: 74 28 63 6d 64 6c 69 6e 65 2c 20 6f 70 74 69 6f t(cmdline, optio
28e0: 6e 29 3b 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 n);.. ok = Cr
28f0: 65 61 74 65 50 72 6f 63 65 73 73 28 0a 09 20 20 eateProcess(..
2900: 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d NULL,. /* M
2910: 6f 64 75 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 odule name. */..
2920: 20 20 20 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 cmdline,.
2930: 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 /* Command line
2940: 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 . */.. NULL,.
2950: 20 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 /* Process h
2960: 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 andle not inheri
2970: 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e table. */.. N
2980: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 ULL,. /* Thre
2990: 61 64 20 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e ad handle not in
29a0: 68 65 72 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 heritable. */..
29b0: 20 20 20 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 TRUE,. /*
29c0: 79 65 73 2c 20 69 6e 68 65 72 69 74 20 68 61 6e yes, inherit han
29d0: 64 6c 65 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 dles. */.. DE
29e0: 54 41 43 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 TACHED_PROCESS,
29f0: 2f 2a 20 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f /* No console fo
2a00: 72 20 79 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e r you. */.. N
2a10: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 ULL,. /* Use
2a20: 70 61 72 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e parent's environ
2a30: 6d 65 6e 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 ment block. */..
2a40: 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a NULL,. /*
2a50: 20 55 73 65 20 70 61 72 65 6e 74 27 73 20 73 74 Use parent's st
2a60: 61 72 74 69 6e 67 20 64 69 72 65 63 74 6f 72 79 arting directory
2a70: 2e 20 2a 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 . */.. &si,.
2a80: 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f /* Pointer to
2a90: 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 74 72 STARTUPINFO str
2aa0: 75 63 74 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 ucture. */..
2ab0: 26 70 69 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 &pi);. /* Poi
2ac0: 6e 74 65 72 20 74 6f 20 50 52 4f 43 45 53 53 5f nter to PROCESS_
2ad0: 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 INFORMATION stru
2ae0: 63 74 75 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 cture. */.. i
2af0: 66 20 28 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 f (!ok) {..DWORD
2b00: 20 65 72 72 20 3d 20 47 65 74 4c 61 73 74 45 72 err = GetLastEr
2b10: 72 6f 72 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 ror();..int char
2b20: 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 s = snprintf(msg
2b30: 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 , sizeof(msg) -
2b40: 31 2c 0a 09 09 22 54 72 69 65 64 20 74 6f 20 6c 1,..."Tried to l
2b50: 61 75 6e 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 aunch: \"%s\", b
2b60: 75 74 20 67 6f 74 20 65 72 72 6f 72 20 5b 25 75 ut got error [%u
2b70: 5d 3a 20 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65 ]: ", cmdline, e
2b80: 72 72 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73 rr);...FormatMes
2b90: 73 61 67 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53 sage(FORMAT_MESS
2ba0: 41 47 45 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c AGE_FROM_SYSTEM|
2bb0: 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49 FORMAT_MESSAGE_I
2bc0: 47 4e 4f 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09 GNORE_INSERTS|..
2bd0: 09 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f .FORMAT_MESSAGE_
2be0: 4d 41 58 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20 MAX_WIDTH_MASK,
2bf0: 30 4c 2c 20 65 72 72 2c 20 30 2c 20 28 4c 50 56 0L, err, 0, (LPV
2c00: 4f 49 44 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c OID)&msg[chars],
2c10: 0a 09 09 28 33 30 30 2d 63 68 61 72 73 29 2c 20 ...(300-chars),
2c20: 30 29 3b 0a 09 57 72 69 74 65 46 69 6c 65 28 47 0);..WriteFile(G
2c30: 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f etStdHandle(STD_
2c40: 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d ERROR_HANDLE), m
2c50: 73 67 2c 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c sg,lstrlen(msg),
2c60: 20 26 65 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65 &err,NULL);..re
2c70: 74 75 72 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 turn 2;. }..
2c80: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f /*. * Clo
2c90: 73 65 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65 se our reference
2ca0: 73 20 74 6f 20 74 68 65 20 77 72 69 74 65 20 68 s to the write h
2cb0: 61 6e 64 6c 65 73 20 74 68 61 74 20 68 61 76 65 andles that have
2cc0: 20 6e 6f 77 20 62 65 65 6e 20 69 6e 68 65 72 69 now been inheri
2cd0: 74 65 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 ted.. */..
2ce0: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 CloseHandle(si
2cf0: 2e 68 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 .hStdOutput);.
2d00: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 CloseHandle(si
2d10: 2e 68 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 .hStdError);..
2d20: 20 20 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64 WaitForInputId
2d30: 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 le(pi.hProcess,
2d40: 35 30 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 5000);. Close
2d50: 48 61 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61 Handle(pi.hThrea
2d60: 64 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 d);.. /*.
2d70: 20 2a 20 53 74 61 72 74 20 74 68 65 20 70 69 70 * Start the pip
2d80: 65 20 72 65 61 64 65 72 20 74 68 72 65 61 64 73 e reader threads
2d90: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70 .. */.. p
2da0: 69 70 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 ipeThreads[0] =
2db0: 43 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c CreateThread(NUL
2dc0: 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 L, 0, ReadFromPi
2dd0: 70 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 pe, &Out, 0, &th
2de0: 72 65 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70 readID);. pip
2df0: 65 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 eThreads[1] = Cr
2e00: 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c eateThread(NULL,
2e10: 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 0, ReadFromPipe
2e20: 2c 20 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65 , &Err, 0, &thre
2e30: 61 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 adID);.. /*.
2e40: 20 20 20 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74 * Block wait
2e50: 69 6e 67 20 66 6f 72 20 74 68 65 20 70 72 6f 63 ing for the proc
2e60: 65 73 73 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20 ess to end..
2e70: 20 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f 72 */.. WaitFor
2e80: 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e SingleObject(pi.
2e90: 68 50 72 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49 hProcess, INFINI
2ea0: 54 45 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 TE);. CloseHa
2eb0: 6e 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 ndle(pi.hProcess
2ec0: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
2ed0: 2a 20 57 61 69 74 20 66 6f 72 20 6f 75 72 20 70 * Wait for our p
2ee0: 69 70 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 ipe to get done
2ef0: 72 65 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 reading, should
2f00: 69 74 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73 it be a little s
2f10: 6c 6f 77 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 low.. */..
2f20: 20 20 57 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c WaitForMultipl
2f30: 65 4f 62 6a 65 63 74 73 28 32 2c 20 70 69 70 65 eObjects(2, pipe
2f40: 54 68 72 65 61 64 73 2c 20 54 52 55 45 2c 20 35 Threads, TRUE, 5
2f50: 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 00);. CloseHa
2f60: 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 ndle(pipeThreads
2f70: 5b 30 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 [0]);. CloseH
2f80: 61 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 andle(pipeThread
2f90: 73 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 s[1]);.. /*.
2fa0: 20 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74 * Look for t
2fb0: 68 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77 he commandline w
2fc0: 61 72 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 74 arning code in t
2fd0: 68 65 20 73 74 64 65 72 72 20 73 74 72 65 61 6d he stderr stream
2fe0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 72 .. */.. r
2ff0: 65 74 75 72 6e 20 21 28 73 74 72 73 74 72 28 4f eturn !(strstr(O
3000: 75 74 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 31 ut.buffer, "LNK1
3010: 31 31 37 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 117") != NULL ||
3020: 0a 09 20 20 20 20 73 74 72 73 74 72 28 45 72 72 .. strstr(Err
3030: 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 31 31 31 .buffer, "LNK111
3040: 37 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 7") != NULL ||..
3050: 20 20 20 20 73 74 72 73 74 72 28 4f 75 74 2e 62 strstr(Out.b
3060: 75 66 66 65 72 2c 20 22 4c 4e 4b 34 30 34 34 22 uffer, "LNK4044"
3070: 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 ) != NULL ||..
3080: 20 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 66 strstr(Err.buf
3090: 66 65 72 2c 20 22 4c 4e 4b 34 30 34 34 22 29 20 fer, "LNK4044")
30a0: 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a 44 57 != NULL);.}...DW
30b0: 4f 52 44 20 57 49 4e 41 50 49 0a 52 65 61 64 46 ORD WINAPI.ReadF
30c0: 72 6f 6d 50 69 70 65 28 0a 20 20 20 20 4c 50 56 romPipe(. LPV
30d0: 4f 49 44 20 61 72 67 73 29 0a 7b 0a 20 20 20 20 OID args).{.
30e0: 70 69 70 65 69 6e 66 6f 20 2a 70 69 20 3d 20 28 pipeinfo *pi = (
30f0: 70 69 70 65 69 6e 66 6f 20 2a 29 20 61 72 67 73 pipeinfo *) args
3100: 3b 0a 20 20 20 20 63 68 61 72 20 2a 6c 61 73 74 ;. char *last
3110: 42 75 66 20 3d 20 70 69 2d 3e 62 75 66 66 65 72 Buf = pi->buffer
3120: 3b 0a 20 20 20 20 44 57 4f 52 44 20 64 77 52 65 ;. DWORD dwRe
3130: 61 64 3b 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b ad;. BOOL ok;
3140: 0a 0a 20 20 61 67 61 69 6e 3a 0a 20 20 20 20 69 .. again:. i
3150: 66 20 28 6c 61 73 74 42 75 66 20 2d 20 70 69 2d f (lastBuf - pi-
3160: 3e 62 75 66 66 65 72 20 2b 20 43 48 55 4e 4b 20 >buffer + CHUNK
3170: 3e 20 53 54 41 54 49 43 42 55 46 46 45 52 53 49 > STATICBUFFERSI
3180: 5a 45 29 20 7b 0a 09 43 6c 6f 73 65 48 61 6e 64 ZE) {..CloseHand
3190: 6c 65 28 70 69 2d 3e 70 69 70 65 29 3b 0a 09 72 le(pi->pipe);..r
31a0: 65 74 75 72 6e 20 28 44 57 4f 52 44 29 2d 31 3b eturn (DWORD)-1;
31b0: 0a 20 20 20 20 7d 0a 20 20 20 20 6f 6b 20 3d 20 . }. ok =
31c0: 52 65 61 64 46 69 6c 65 28 70 69 2d 3e 70 69 70 ReadFile(pi->pip
31d0: 65 2c 20 6c 61 73 74 42 75 66 2c 20 43 48 55 4e e, lastBuf, CHUN
31e0: 4b 2c 20 26 64 77 52 65 61 64 2c 20 30 4c 29 3b K, &dwRead, 0L);
31f0: 0a 20 20 20 20 69 66 20 28 21 6f 6b 20 7c 7c 20 . if (!ok ||
3200: 64 77 52 65 61 64 20 3d 3d 20 30 29 20 7b 0a 09 dwRead == 0) {..
3210: 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 2d 3e CloseHandle(pi->
3220: 70 69 70 65 29 3b 0a 09 72 65 74 75 72 6e 20 30 pipe);..return 0
3230: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6c 61 73 74 ;. }. last
3240: 42 75 66 20 2b 3d 20 64 77 52 65 61 64 3b 0a 20 Buf += dwRead;.
3250: 20 20 20 67 6f 74 6f 20 61 67 61 69 6e 3b 0a 0a goto again;..
3260: 20 20 20 20 72 65 74 75 72 6e 20 30 3b 20 20 2f return 0; /
3270: 2a 20 6d 61 6b 65 73 20 74 68 65 20 63 6f 6d 70 * makes the comp
3280: 69 6c 65 72 20 68 61 70 70 79 20 2a 2f 0a 7d 0a iler happy */.}.
3290: 0c 0a 69 6e 74 0a 49 73 49 6e 28 0a 20 20 20 20 ..int.IsIn(.
32a0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 72 69 const char *stri
32b0: 6e 67 2c 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 ng,. const ch
32c0: 61 72 20 2a 73 75 62 73 74 72 69 6e 67 29 0a 7b ar *substring).{
32d0: 0a 20 20 20 20 72 65 74 75 72 6e 20 28 73 74 72 . return (str
32e0: 73 74 72 28 73 74 72 69 6e 67 2c 20 73 75 62 73 str(string, subs
32f0: 74 72 69 6e 67 29 20 21 3d 20 4e 55 4c 4c 29 3b tring) != NULL);
3300: 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 46 69 6e 64 20 .}.../*. * Find
3310: 61 20 73 70 65 63 69 66 69 65 64 20 23 64 65 66 a specified #def
3320: 69 6e 65 20 62 79 20 6e 61 6d 65 2e 0a 20 2a 0a ine by name.. *.
3330: 20 2a 20 49 66 20 74 68 65 20 6c 69 6e 65 20 69 * If the line i
3340: 73 20 27 23 64 65 66 69 6e 65 20 54 43 4c 5f 56 s '#define TCL_V
3350: 45 52 53 49 4f 4e 20 22 38 2e 35 22 27 2c 20 69 ERSION "8.5"', i
3360: 74 20 72 65 74 75 72 6e 73 20 38 35 20 61 73 20 t returns 85 as
3370: 74 68 65 20 72 65 73 75 6c 74 2e 0a 20 2a 2f 0a the result.. */.
3380: 0a 69 6e 74 0a 47 72 65 70 46 6f 72 44 65 66 69 .int.GrepForDefi
3390: 6e 65 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 ne(. const ch
33a0: 61 72 20 2a 66 69 6c 65 2c 0a 20 20 20 20 63 6f ar *file,. co
33b0: 6e 73 74 20 63 68 61 72 20 2a 73 74 72 69 6e 67 nst char *string
33c0: 29 0a 7b 0a 20 20 20 20 63 68 61 72 20 73 31 5b ).{. char s1[
33d0: 35 31 5d 2c 20 73 32 5b 35 31 5d 2c 20 73 33 5b 51], s2[51], s3[
33e0: 35 31 5d 3b 0a 20 20 20 20 46 49 4c 45 20 2a 66 51];. FILE *f
33f0: 20 3d 20 66 6f 70 65 6e 28 66 69 6c 65 2c 20 22 = fopen(file, "
3400: 72 74 22 29 3b 0a 0a 20 20 20 20 69 66 20 28 66 rt");.. if (f
3410: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 == NULL) {..ret
3420: 75 72 6e 20 30 3b 0a 20 20 20 20 7d 0a 0a 20 20 urn 0;. }..
3430: 20 20 64 6f 20 7b 0a 09 69 6e 74 20 72 20 3d 20 do {..int r =
3440: 66 73 63 61 6e 66 28 66 2c 20 22 25 35 30 73 22 fscanf(f, "%50s"
3450: 2c 20 73 31 29 3b 0a 0a 09 69 66 20 28 72 20 3d , s1);...if (r =
3460: 3d 20 31 20 26 26 20 21 73 74 72 63 6d 70 28 73 = 1 && !strcmp(s
3470: 31 2c 20 22 23 64 65 66 69 6e 65 22 29 29 20 7b 1, "#define")) {
3480: 0a 09 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a .. /*.. *
3490: 20 47 65 74 20 6e 65 78 74 20 74 77 6f 20 77 6f Get next two wo
34a0: 72 64 73 2e 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 rds... */...
34b0: 20 20 20 20 72 20 3d 20 66 73 63 61 6e 66 28 66 r = fscanf(f
34c0: 2c 20 22 25 35 30 73 20 25 35 30 73 22 2c 20 73 , "%50s %50s", s
34d0: 32 2c 20 73 33 29 3b 0a 09 20 20 20 20 69 66 20 2, s3);.. if
34e0: 28 72 20 21 3d 20 32 29 20 7b 0a 09 09 63 6f 6e (r != 2) {...con
34f0: 74 69 6e 75 65 3b 0a 09 20 20 20 20 7d 0a 0a 09 tinue;.. }...
3500: 20 20 20 20 2f 2a 0a 09 20 20 20 20 20 2a 20 49 /*.. * I
3510: 73 20 74 68 65 20 66 69 72 73 74 20 77 6f 72 64 s the first word
3520: 20 77 68 61 74 20 77 65 27 72 65 20 6c 6f 6f 6b what we're look
3530: 69 6e 67 20 66 6f 72 3f 0a 09 20 20 20 20 20 2a ing for?.. *
3540: 2f 0a 0a 09 20 20 20 20 69 66 20 28 21 73 74 72 /... if (!str
3550: 63 6d 70 28 73 32 2c 20 73 74 72 69 6e 67 29 29 cmp(s2, string))
3560: 20 7b 0a 09 09 64 6f 75 62 6c 65 20 64 31 3b 0a {...double d1;.
3570: 0a 09 09 66 63 6c 6f 73 65 28 66 29 3b 0a 0a 09 ...fclose(f);...
3580: 09 2f 2a 0a 09 09 20 2a 20 41 64 64 20 31 20 70 ./*... * Add 1 p
3590: 61 73 74 20 66 69 72 73 74 20 64 6f 75 62 6c 65 ast first double
35a0: 20 71 75 6f 74 65 20 63 68 61 72 2e 20 22 38 2e quote char. "8.
35b0: 35 22 0a 09 09 20 2a 2f 0a 0a 09 09 64 31 20 3d 5"... */....d1 =
35c0: 20 61 74 6f 66 28 73 33 20 2b 20 31 29 3b 09 09 atof(s3 + 1);..
35d0: 20 20 2f 2a 20 20 20 20 38 2e 35 20 20 2a 2f 0a /* 8.5 */.
35e0: 09 09 77 68 69 6c 65 20 28 66 6c 6f 6f 72 28 64 ..while (floor(d
35f0: 31 29 20 21 3d 20 64 31 29 20 7b 0a 09 09 20 20 1) != d1) {...
3600: 20 20 64 31 20 2a 3d 20 31 30 2e 30 3b 0a 09 09 d1 *= 10.0;...
3610: 7d 0a 09 09 72 65 74 75 72 6e 20 28 28 69 6e 74 }...return ((int
3620: 29 20 64 31 29 3b 09 09 20 20 2f 2a 20 20 20 20 ) d1);.. /*
3630: 38 35 20 20 20 2a 2f 0a 09 20 20 20 20 7d 0a 09 85 */.. }..
3640: 7d 0a 20 20 20 20 7d 20 77 68 69 6c 65 20 28 21 }. } while (!
3650: 66 65 6f 66 28 66 29 29 3b 0a 0a 20 20 20 20 66 feof(f));.. f
3660: 63 6c 6f 73 65 28 66 29 3b 0a 20 20 20 20 72 65 close(f);. re
3670: 74 75 72 6e 20 30 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 turn 0;.}.../*.
3680: 2a 20 47 65 74 56 65 72 73 69 6f 6e 46 72 6f 6d * GetVersionFrom
3690: 46 69 6c 65 20 2d 2d 0a 20 2a 20 09 4c 6f 6f 6b File --. * .Look
36a0: 73 20 66 6f 72 20 61 20 6d 61 74 63 68 20 73 74 s for a match st
36b0: 72 69 6e 67 20 69 6e 20 61 20 66 69 6c 65 20 61 ring in a file a
36c0: 6e 64 20 74 68 65 6e 20 72 65 74 75 72 6e 73 20 nd then returns
36d0: 74 68 65 20 76 65 72 73 69 6f 6e 0a 20 2a 20 09 the version. * .
36e0: 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65 20 6d 61 following the ma
36f0: 74 63 68 20 77 68 65 72 65 20 61 20 76 65 72 73 tch where a vers
3700: 69 6f 6e 20 69 73 20 61 6e 79 74 68 69 6e 67 20 ion is anything
3710: 61 63 63 65 70 74 61 62 6c 65 20 74 6f 0a 20 2a acceptable to. *
3720: 20 09 70 61 63 6b 61 67 65 20 70 72 6f 76 69 64 .package provid
3730: 65 20 6f 72 20 70 61 63 6b 61 67 65 20 69 66 6e e or package ifn
3740: 65 65 64 65 64 2e 0a 20 2a 2f 0a 0a 63 6f 6e 73 eeded.. */..cons
3750: 74 20 63 68 61 72 20 2a 0a 47 65 74 56 65 72 73 t char *.GetVers
3760: 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 0a 20 20 20 ionFromFile(.
3770: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c const char *fil
3780: 65 6e 61 6d 65 2c 0a 20 20 20 20 63 6f 6e 73 74 ename,. const
3790: 20 63 68 61 72 20 2a 6d 61 74 63 68 29 0a 7b 0a char *match).{.
37a0: 20 20 20 20 73 69 7a 65 5f 74 20 63 62 42 75 66 size_t cbBuf
37b0: 66 65 72 20 3d 20 31 30 30 3b 0a 20 20 20 20 73 fer = 100;. s
37c0: 74 61 74 69 63 20 63 68 61 72 20 73 7a 42 75 66 tatic char szBuf
37d0: 66 65 72 5b 31 30 30 5d 3b 0a 20 20 20 20 63 68 fer[100];. ch
37e0: 61 72 20 2a 73 7a 52 65 73 75 6c 74 20 3d 20 4e ar *szResult = N
37f0: 55 4c 4c 3b 0a 20 20 20 20 46 49 4c 45 20 2a 66 ULL;. FILE *f
3800: 70 20 3d 20 66 6f 70 65 6e 28 66 69 6c 65 6e 61 p = fopen(filena
3810: 6d 65 2c 20 22 72 74 22 29 3b 0a 0a 20 20 20 20 me, "rt");..
3820: 69 66 20 28 66 70 20 21 3d 20 4e 55 4c 4c 29 20 if (fp != NULL)
3830: 7b 0a 09 2f 2a 0a 09 20 2a 20 52 65 61 64 20 64 {../*.. * Read d
3840: 61 74 61 20 75 6e 74 69 6c 20 77 65 20 73 65 65 ata until we see
3850: 20 6f 75 72 20 6d 61 74 63 68 20 73 74 72 69 6e our match strin
3860: 67 2e 0a 09 20 2a 2f 0a 0a 09 77 68 69 6c 65 20 g... */...while
3870: 28 66 67 65 74 73 28 73 7a 42 75 66 66 65 72 2c (fgets(szBuffer,
3880: 20 63 62 42 75 66 66 65 72 2c 20 66 70 29 20 21 cbBuffer, fp) !
3890: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 4c = NULL) {.. L
38a0: 50 53 54 52 20 70 2c 20 71 3b 0a 0a 09 20 20 20 PSTR p, q;...
38b0: 20 70 20 3d 20 73 74 72 73 74 72 28 73 7a 42 75 p = strstr(szBu
38c0: 66 66 65 72 2c 20 6d 61 74 63 68 29 3b 0a 09 20 ffer, match);..
38d0: 20 20 20 69 66 20 28 70 20 21 3d 20 4e 55 4c 4c if (p != NULL
38e0: 29 20 7b 0a 09 09 2f 2a 0a 09 09 20 2a 20 53 6b ) {.../*... * Sk
38f0: 69 70 20 74 6f 20 66 69 72 73 74 20 64 69 67 69 ip to first digi
3900: 74 2e 0a 09 09 20 2a 2f 0a 0a 09 09 77 68 69 6c t.... */....whil
3910: 65 20 28 2a 70 20 26 26 20 21 69 73 64 69 67 69 e (*p && !isdigi
3920: 74 28 2a 70 29 29 20 7b 0a 09 09 20 20 20 20 2b t(*p)) {... +
3930: 2b 70 3b 0a 09 09 7d 0a 0a 09 09 2f 2a 0a 09 09 +p;...}..../*...
3940: 20 2a 20 46 69 6e 64 20 65 6e 64 69 6e 67 20 77 * Find ending w
3950: 68 69 74 65 73 70 61 63 65 2e 0a 09 09 20 2a 2f hitespace.... */
3960: 0a 0a 09 09 71 20 3d 20 70 3b 0a 09 09 77 68 69 ....q = p;...whi
3970: 6c 65 20 28 2a 71 20 26 26 20 28 69 73 61 6c 6e le (*q && (isaln
3980: 75 6d 28 2a 71 29 20 7c 7c 20 2a 71 20 3d 3d 20 um(*q) || *q ==
3990: 27 2e 27 29 29 20 7b 0a 09 09 20 20 20 20 2b 2b '.')) {... ++
39a0: 71 3b 0a 09 09 7d 0a 0a 09 09 6d 65 6d 63 70 79 q;...}....memcpy
39b0: 28 73 7a 42 75 66 66 65 72 2c 20 70 2c 20 71 20 (szBuffer, p, q
39c0: 2d 20 70 29 3b 0a 09 09 73 7a 42 75 66 66 65 72 - p);...szBuffer
39d0: 5b 71 2d 70 5d 20 3d 20 30 3b 0a 09 09 73 7a 52 [q-p] = 0;...szR
39e0: 65 73 75 6c 74 20 3d 20 73 7a 42 75 66 66 65 72 esult = szBuffer
39f0: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 20 20 20 20 ;...break;..
3a00: 7d 0a 09 7d 0a 09 66 63 6c 6f 73 65 28 66 70 29 }..}..fclose(fp)
3a10: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 ;. }. retu
3a20: 72 6e 20 73 7a 52 65 73 75 6c 74 3b 0a 7d 0a 0c rn szResult;.}..
3a30: 0a 2f 2a 0a 20 2a 20 4c 69 73 74 20 68 65 6c 70 ./*. * List help
3a40: 65 72 73 20 66 6f 72 20 74 68 65 20 53 75 62 73 ers for the Subs
3a50: 74 69 74 75 74 65 46 69 6c 65 20 66 75 6e 63 74 tituteFile funct
3a60: 69 6f 6e 0a 20 2a 2f 0a 0a 74 79 70 65 64 65 66 ion. */..typedef
3a70: 20 73 74 72 75 63 74 20 6c 69 73 74 5f 69 74 65 struct list_ite
3a80: 6d 5f 74 20 7b 0a 20 20 20 20 73 74 72 75 63 74 m_t {. struct
3a90: 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 6e 65 list_item_t *ne
3aa0: 78 74 50 74 72 3b 0a 20 20 20 20 63 68 61 72 20 xtPtr;. char
3ab0: 2a 20 6b 65 79 3b 0a 20 20 20 20 63 68 61 72 20 * key;. char
3ac0: 2a 20 76 61 6c 75 65 3b 0a 7d 20 6c 69 73 74 5f * value;.} list_
3ad0: 69 74 65 6d 5f 74 3b 0a 0a 2f 2a 20 69 6e 73 65 item_t;../* inse
3ae0: 72 74 20 61 20 6c 69 73 74 20 69 74 65 6d 20 69 rt a list item i
3af0: 6e 74 6f 20 74 68 65 20 6c 69 73 74 20 28 6c 69 nto the list (li
3b00: 73 74 20 6d 61 79 20 62 65 20 6e 75 6c 6c 29 20 st may be null)
3b10: 2a 2f 0a 73 74 61 74 69 63 20 6c 69 73 74 5f 69 */.static list_i
3b20: 74 65 6d 5f 74 20 2a 0a 6c 69 73 74 5f 69 6e 73 tem_t *.list_ins
3b30: 65 72 74 28 6c 69 73 74 5f 69 74 65 6d 5f 74 20 ert(list_item_t
3b40: 2a 2a 6c 69 73 74 50 74 72 50 74 72 2c 20 63 6f **listPtrPtr, co
3b50: 6e 73 74 20 63 68 61 72 20 2a 6b 65 79 2c 20 63 nst char *key, c
3b60: 6f 6e 73 74 20 63 68 61 72 20 2a 76 61 6c 75 65 onst char *value
3b70: 29 0a 7b 0a 20 20 20 20 6c 69 73 74 5f 69 74 65 ).{. list_ite
3b80: 6d 5f 74 20 2a 69 74 65 6d 50 74 72 20 3d 20 6d m_t *itemPtr = m
3b90: 61 6c 6c 6f 63 28 73 69 7a 65 6f 66 28 6c 69 73 alloc(sizeof(lis
3ba0: 74 5f 69 74 65 6d 5f 74 29 29 3b 0a 20 20 20 20 t_item_t));.
3bb0: 69 66 20 28 69 74 65 6d 50 74 72 29 20 7b 0a 09 if (itemPtr) {..
3bc0: 69 74 65 6d 50 74 72 2d 3e 6b 65 79 20 3d 20 73 itemPtr->key = s
3bd0: 74 72 64 75 70 28 6b 65 79 29 3b 0a 09 69 74 65 trdup(key);..ite
3be0: 6d 50 74 72 2d 3e 76 61 6c 75 65 20 3d 20 73 74 mPtr->value = st
3bf0: 72 64 75 70 28 76 61 6c 75 65 29 3b 0a 09 69 74 rdup(value);..it
3c00: 65 6d 50 74 72 2d 3e 6e 65 78 74 50 74 72 20 3d emPtr->nextPtr =
3c10: 20 4e 55 4c 4c 3b 0a 0a 09 77 68 69 6c 65 28 2a NULL;...while(*
3c20: 6c 69 73 74 50 74 72 50 74 72 29 20 7b 0a 09 20 listPtrPtr) {..
3c30: 20 20 20 6c 69 73 74 50 74 72 50 74 72 20 3d 20 listPtrPtr =
3c40: 26 28 2a 6c 69 73 74 50 74 72 50 74 72 29 2d 3e &(*listPtrPtr)->
3c50: 6e 65 78 74 50 74 72 3b 0a 09 7d 0a 09 2a 6c 69 nextPtr;..}..*li
3c60: 73 74 50 74 72 50 74 72 20 3d 20 69 74 65 6d 50 stPtrPtr = itemP
3c70: 74 72 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 tr;. }. re
3c80: 74 75 72 6e 20 69 74 65 6d 50 74 72 3b 0a 7d 0a turn itemPtr;.}.
3c90: 0a 73 74 61 74 69 63 20 76 6f 69 64 0a 6c 69 73 .static void.lis
3ca0: 74 5f 66 72 65 65 28 6c 69 73 74 5f 69 74 65 6d t_free(list_item
3cb0: 5f 74 20 2a 2a 6c 69 73 74 50 74 72 50 74 72 29 _t **listPtrPtr)
3cc0: 0a 7b 0a 20 20 20 20 6c 69 73 74 5f 69 74 65 6d .{. list_item
3cd0: 5f 74 20 2a 74 6d 70 50 74 72 2c 20 2a 6c 69 73 _t *tmpPtr, *lis
3ce0: 74 50 74 72 20 3d 20 2a 6c 69 73 74 50 74 72 50 tPtr = *listPtrP
3cf0: 74 72 3b 0a 20 20 20 20 77 68 69 6c 65 20 28 6c tr;. while (l
3d00: 69 73 74 50 74 72 29 20 7b 0a 09 74 6d 70 50 74 istPtr) {..tmpPt
3d10: 72 20 3d 20 6c 69 73 74 50 74 72 3b 0a 09 6c 69 r = listPtr;..li
3d20: 73 74 50 74 72 20 3d 20 6c 69 73 74 50 74 72 2d stPtr = listPtr-
3d30: 3e 6e 65 78 74 50 74 72 3b 0a 09 66 72 65 65 28 >nextPtr;..free(
3d40: 74 6d 70 50 74 72 2d 3e 6b 65 79 29 3b 0a 09 66 tmpPtr->key);..f
3d50: 72 65 65 28 74 6d 70 50 74 72 2d 3e 76 61 6c 75 ree(tmpPtr->valu
3d60: 65 29 3b 0a 09 66 72 65 65 28 74 6d 70 50 74 72 e);..free(tmpPtr
3d70: 29 3b 0a 20 20 20 20 7d 0a 7d 0a 0c 0a 2f 2a 0a );. }.}.../*.
3d80: 20 2a 20 53 75 62 73 74 69 74 75 74 65 46 69 6c * SubstituteFil
3d90: 65 20 2d 2d 0a 20 2a 09 41 73 20 77 69 6e 64 6f e --. *.As windo
3da0: 77 73 20 64 6f 65 73 6e 27 74 20 70 72 6f 76 69 ws doesn't provi
3db0: 64 65 20 61 6e 79 74 68 69 6e 67 20 75 73 65 66 de anything usef
3dc0: 75 6c 20 6c 69 6b 65 20 73 65 64 20 61 6e 64 20 ul like sed and
3dd0: 69 74 27 73 20 75 6e 72 65 6c 69 61 62 6c 65 0a it's unreliable.
3de0: 20 2a 09 74 6f 20 75 73 65 20 74 68 65 20 74 63 *.to use the tc
3df0: 6c 73 68 20 79 6f 75 20 61 72 65 20 62 75 69 6c lsh you are buil
3e00: 64 69 6e 67 20 61 67 61 69 6e 73 74 20 28 63 6f ding against (co
3e10: 6e 73 69 64 65 72 20 78 2d 70 6c 61 74 66 6f 72 nsider x-platfor
3e20: 6d 20 62 75 69 6c 64 73 20 2d 0a 20 2a 09 65 67 m builds -. *.eg
3e30: 20 63 6f 6d 70 69 6c 69 6e 67 20 41 4d 44 36 34 compiling AMD64
3e40: 20 74 61 72 67 65 74 20 66 72 6f 6d 20 49 58 38 target from IX8
3e50: 36 29 20 77 65 20 70 72 6f 76 69 64 65 20 61 20 6) we provide a
3e60: 73 69 6d 70 6c 65 20 73 75 62 73 74 69 74 75 74 simple substitut
3e70: 69 6f 6e 0a 20 2a 09 6f 70 74 69 6f 6e 20 68 65 ion. *.option he
3e80: 72 65 20 74 6f 20 68 61 6e 64 6c 65 20 61 75 74 re to handle aut
3e90: 6f 63 6f 6e 66 20 73 74 79 6c 65 20 73 75 62 73 oconf style subs
3ea0: 74 69 74 75 74 69 6f 6e 73 2e 0a 20 2a 09 54 68 titutions.. *.Th
3eb0: 65 20 73 75 62 73 74 69 74 75 74 69 6f 6e 20 66 e substitution f
3ec0: 69 6c 65 20 69 73 20 77 68 69 74 65 73 70 61 63 ile is whitespac
3ed0: 65 20 61 6e 64 20 6c 69 6e 65 20 64 65 6c 69 6d e and line delim
3ee0: 69 74 65 64 2e 20 54 68 65 20 66 69 6c 65 20 73 ited. The file s
3ef0: 68 6f 75 6c 64 0a 20 2a 09 63 6f 6e 73 69 73 74 hould. *.consist
3f00: 20 6f 66 20 6c 69 6e 65 73 20 6d 61 74 63 68 69 of lines matchi
3f10: 6e 67 20 74 68 65 20 72 65 67 75 6c 61 72 20 65 ng the regular e
3f20: 78 70 72 65 73 73 69 6f 6e 3a 0a 20 2a 09 20 20 xpression:. *.
3f30: 5c 73 2a 5c 53 2b 5c 73 2b 5c 53 2a 24 0a 20 2a \s*\S+\s+\S*$. *
3f40: 0a 20 2a 09 55 73 61 67 65 20 69 73 20 73 6f 6d . *.Usage is som
3f50: 65 74 68 69 6e 67 20 6c 69 6b 65 3a 0a 20 2a 09 ething like:. *.
3f60: 20 20 6e 6d 61 6b 65 68 6c 70 20 2d 53 20 3c 3c nmakehlp -S <<
3f70: 20 24 2a 2a 20 3e 20 24 40 0a 20 2a 20 20 20 20 $** > $@. *
3f80: 20 20 20 20 40 50 41 43 4b 41 47 45 5f 4e 41 4d @PACKAGE_NAM
3f90: 45 40 20 24 28 50 41 43 4b 41 47 45 5f 4e 41 4d E@ $(PACKAGE_NAM
3fa0: 45 29 0a 20 2a 20 20 20 20 20 20 20 20 40 50 41 E). * @PA
3fb0: 43 4b 41 47 45 5f 56 45 52 53 49 4f 4e 40 20 24 CKAGE_VERSION@ $
3fc0: 28 50 41 43 4b 41 47 45 5f 56 45 52 53 49 4f 4e (PACKAGE_VERSION
3fd0: 29 0a 20 2a 20 20 20 20 20 20 20 20 3c 3c 0a 20 ). * <<.
3fe0: 2a 2f 0a 0a 69 6e 74 0a 53 75 62 73 74 69 74 75 */..int.Substitu
3ff0: 74 65 46 69 6c 65 28 0a 20 20 20 20 63 6f 6e 73 teFile(. cons
4000: 74 20 63 68 61 72 20 2a 73 75 62 73 74 69 74 75 t char *substitu
4010: 74 69 6f 6e 73 2c 0a 20 20 20 20 63 6f 6e 73 74 tions,. const
4020: 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d 65 29 char *filename)
4030: 0a 7b 0a 20 20 20 20 73 69 7a 65 5f 74 20 63 62 .{. size_t cb
4040: 42 75 66 66 65 72 20 3d 20 31 30 32 34 3b 0a 20 Buffer = 1024;.
4050: 20 20 20 73 74 61 74 69 63 20 63 68 61 72 20 73 static char s
4060: 7a 42 75 66 66 65 72 5b 31 30 32 34 5d 2c 20 73 zBuffer[1024], s
4070: 7a 43 6f 70 79 5b 31 30 32 34 5d 3b 0a 20 20 20 zCopy[1024];.
4080: 20 63 68 61 72 20 2a 73 7a 52 65 73 75 6c 74 20 char *szResult
4090: 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 6c 69 73 74 = NULL;. list
40a0: 5f 69 74 65 6d 5f 74 20 2a 73 75 62 73 74 50 74 _item_t *substPt
40b0: 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 46 49 r = NULL;. FI
40c0: 4c 45 20 2a 66 70 2c 20 2a 73 70 3b 0a 0a 20 20 LE *fp, *sp;..
40d0: 20 20 66 70 20 3d 20 66 6f 70 65 6e 28 66 69 6c fp = fopen(fil
40e0: 65 6e 61 6d 65 2c 20 22 72 74 22 29 3b 0a 20 20 ename, "rt");.
40f0: 20 20 69 66 20 28 66 70 20 21 3d 20 4e 55 4c 4c if (fp != NULL
4100: 29 20 7b 0a 0a 09 2f 2a 0a 09 20 2a 20 42 75 69 ) {.../*.. * Bui
4110: 6c 64 20 61 20 6c 69 73 74 20 6f 66 20 73 75 62 ld a list of sub
4120: 73 74 75 74 69 74 69 6f 6e 73 20 66 72 6f 6d 20 stutitions from
4130: 74 68 65 20 66 69 72 73 74 20 66 69 6c 65 6e 61 the first filena
4140: 6d 65 0a 09 20 2a 2f 0a 0a 09 73 70 20 3d 20 66 me.. */...sp = f
4150: 6f 70 65 6e 28 73 75 62 73 74 69 74 75 74 69 6f open(substitutio
4160: 6e 73 2c 20 22 72 74 22 29 3b 0a 09 69 66 20 28 ns, "rt");..if (
4170: 73 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 sp != NULL) {..
4180: 20 20 20 77 68 69 6c 65 20 28 66 67 65 74 73 28 while (fgets(
4190: 73 7a 42 75 66 66 65 72 2c 20 63 62 42 75 66 66 szBuffer, cbBuff
41a0: 65 72 2c 20 73 70 29 20 21 3d 20 4e 55 4c 4c 29 er, sp) != NULL)
41b0: 20 7b 0a 09 09 63 68 61 72 20 2a 6b 73 2c 20 2a {...char *ks, *
41c0: 6b 65 2c 20 2a 76 73 2c 20 2a 76 65 3b 0a 09 09 ke, *vs, *ve;...
41d0: 6b 73 20 3d 20 73 7a 42 75 66 66 65 72 3b 0a 09 ks = szBuffer;..
41e0: 09 77 68 69 6c 65 20 28 6b 73 20 26 26 20 2a 6b .while (ks && *k
41f0: 73 20 26 26 20 69 73 73 70 61 63 65 28 2a 6b 73 s && isspace(*ks
4200: 29 29 20 2b 2b 6b 73 3b 0a 09 09 6b 65 20 3d 20 )) ++ks;...ke =
4210: 6b 73 3b 0a 09 09 77 68 69 6c 65 20 28 6b 65 20 ks;...while (ke
4220: 26 26 20 2a 6b 65 20 26 26 20 21 69 73 73 70 61 && *ke && !isspa
4230: 63 65 28 2a 6b 65 29 29 20 2b 2b 6b 65 3b 0a 09 ce(*ke)) ++ke;..
4240: 09 76 73 20 3d 20 6b 65 3b 0a 09 09 77 68 69 6c .vs = ke;...whil
4250: 65 20 28 76 73 20 26 26 20 2a 76 73 20 26 26 20 e (vs && *vs &&
4260: 69 73 73 70 61 63 65 28 2a 76 73 29 29 20 2b 2b isspace(*vs)) ++
4270: 76 73 3b 0a 09 09 76 65 20 3d 20 76 73 3b 0a 09 vs;...ve = vs;..
4280: 09 77 68 69 6c 65 20 28 76 65 20 26 26 20 2a 76 .while (ve && *v
4290: 65 20 26 26 20 21 28 2a 76 65 20 3d 3d 20 27 5c e && !(*ve == '\
42a0: 72 27 20 7c 7c 20 2a 76 65 20 3d 3d 20 27 5c 6e r' || *ve == '\n
42b0: 27 29 29 20 2b 2b 76 65 3b 0a 09 09 2a 6b 65 20 ')) ++ve;...*ke
42c0: 3d 20 30 2c 20 2a 76 65 20 3d 20 30 3b 0a 09 09 = 0, *ve = 0;...
42d0: 6c 69 73 74 5f 69 6e 73 65 72 74 28 26 73 75 62 list_insert(&sub
42e0: 73 74 50 74 72 2c 20 6b 73 2c 20 76 73 29 3b 0a stPtr, ks, vs);.
42f0: 09 20 20 20 20 7d 0a 09 20 20 20 20 66 63 6c 6f . }.. fclo
4300: 73 65 28 73 70 29 3b 0a 09 7d 0a 0a 09 2f 2a 20 se(sp);..}.../*
4310: 64 65 62 75 67 3a 20 64 75 6d 70 20 74 68 65 20 debug: dump the
4320: 6c 69 73 74 20 2a 2f 0a 23 69 66 64 65 66 20 5f list */.#ifdef _
4330: 44 45 42 55 47 0a 09 7b 0a 09 20 20 20 20 69 6e DEBUG..{.. in
4340: 74 20 6e 20 3d 20 30 3b 0a 09 20 20 20 20 6c 69 t n = 0;.. li
4350: 73 74 5f 69 74 65 6d 5f 74 20 2a 70 20 3d 20 4e st_item_t *p = N
4360: 55 4c 4c 3b 0a 09 20 20 20 20 66 6f 72 20 28 70 ULL;.. for (p
4370: 20 3d 20 73 75 62 73 74 50 74 72 3b 20 70 20 21 = substPtr; p !
4380: 3d 20 4e 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e 6e = NULL; p = p->n
4390: 65 78 74 50 74 72 2c 20 2b 2b 6e 29 20 7b 0a 09 extPtr, ++n) {..
43a0: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c .fprintf(stderr,
43b0: 20 22 25 20 33 64 20 27 25 73 27 20 3d 3e 20 27 "% 3d '%s' => '
43c0: 25 73 27 5c 6e 22 2c 20 6e 2c 20 70 2d 3e 6b 65 %s'\n", n, p->ke
43d0: 79 2c 20 70 2d 3e 76 61 6c 75 65 29 3b 0a 09 20 y, p->value);..
43e0: 20 20 20 7d 0a 09 7d 0a 23 65 6e 64 69 66 0a 09 }..}.#endif..
43f0: 0a 09 2f 2a 0a 09 20 2a 20 52 75 6e 20 74 68 65 ../*.. * Run the
4400: 20 73 75 62 73 74 69 74 75 74 69 6f 6e 73 20 6f substitutions o
4410: 76 65 72 20 65 61 63 68 20 6c 69 6e 65 20 6f 66 ver each line of
4420: 20 74 68 65 20 69 6e 70 75 74 0a 09 20 2a 2f 0a the input.. */.
4430: 09 0a 09 77 68 69 6c 65 20 28 66 67 65 74 73 28 ...while (fgets(
4440: 73 7a 42 75 66 66 65 72 2c 20 63 62 42 75 66 66 szBuffer, cbBuff
4450: 65 72 2c 20 66 70 29 20 21 3d 20 4e 55 4c 4c 29 er, fp) != NULL)
4460: 20 7b 0a 09 20 20 20 20 6c 69 73 74 5f 69 74 65 {.. list_ite
4470: 6d 5f 74 20 2a 70 20 3d 20 4e 55 4c 4c 3b 0a 09 m_t *p = NULL;..
4480: 20 20 20 20 66 6f 72 20 28 70 20 3d 20 73 75 62 for (p = sub
4490: 73 74 50 74 72 3b 20 70 20 21 3d 20 4e 55 4c 4c stPtr; p != NULL
44a0: 3b 20 70 20 3d 20 70 2d 3e 6e 65 78 74 50 74 72 ; p = p->nextPtr
44b0: 29 20 7b 0a 09 09 63 68 61 72 20 2a 6d 20 3d 20 ) {...char *m =
44c0: 73 74 72 73 74 72 28 73 7a 42 75 66 66 65 72 2c strstr(szBuffer,
44d0: 20 70 2d 3e 6b 65 79 29 3b 0a 09 09 69 66 20 28 p->key);...if (
44e0: 6d 29 20 7b 0a 09 09 20 20 20 20 63 68 61 72 20 m) {... char
44f0: 2a 63 70 2c 20 2a 6f 70 2c 20 2a 73 70 3b 0a 09 *cp, *op, *sp;..
4500: 09 20 20 20 20 63 70 20 3d 20 73 7a 43 6f 70 79 . cp = szCopy
4510: 3b 0a 09 09 20 20 20 20 6f 70 20 3d 20 73 7a 42 ;... op = szB
4520: 75 66 66 65 72 3b 0a 09 09 20 20 20 20 77 68 69 uffer;... whi
4530: 6c 65 20 28 6f 70 20 21 3d 20 6d 29 20 2a 63 70 le (op != m) *cp
4540: 2b 2b 20 3d 20 2a 6f 70 2b 2b 3b 0a 09 09 20 20 ++ = *op++;...
4550: 20 20 73 70 20 3d 20 70 2d 3e 76 61 6c 75 65 3b sp = p->value;
4560: 0a 09 09 20 20 20 20 77 68 69 6c 65 20 28 73 70 ... while (sp
4570: 20 26 26 20 2a 73 70 29 20 2a 63 70 2b 2b 20 3d && *sp) *cp++ =
4580: 20 2a 73 70 2b 2b 3b 0a 09 09 20 20 20 20 6f 70 *sp++;... op
4590: 20 2b 3d 20 73 74 72 6c 65 6e 28 70 2d 3e 6b 65 += strlen(p->ke
45a0: 79 29 3b 0a 09 09 20 20 20 20 77 68 69 6c 65 20 y);... while
45b0: 28 2a 6f 70 29 20 2a 63 70 2b 2b 20 3d 20 2a 6f (*op) *cp++ = *o
45c0: 70 2b 2b 3b 0a 09 09 20 20 20 20 2a 63 70 20 3d p++;... *cp =
45d0: 20 30 3b 0a 09 09 20 20 20 20 6d 65 6d 63 70 79 0;... memcpy
45e0: 28 73 7a 42 75 66 66 65 72 2c 20 73 7a 43 6f 70 (szBuffer, szCop
45f0: 79 2c 20 73 69 7a 65 6f 66 28 73 7a 43 6f 70 79 y, sizeof(szCopy
4600: 29 29 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 ));...}.. }..
4610: 20 20 20 20 70 72 69 6e 74 66 28 73 7a 42 75 66 printf(szBuf
4620: 66 65 72 29 3b 0a 09 7d 0a 09 0a 09 6c 69 73 74 fer);..}....list
4630: 5f 66 72 65 65 28 26 73 75 62 73 74 50 74 72 29 _free(&substPtr)
4640: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 63 6c 6f ;. }. fclo
4650: 73 65 28 66 70 29 3b 0a 20 20 20 20 72 65 74 75 se(fp);. retu
4660: 72 6e 20 30 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 rn 0;.}.../*. *
4670: 51 75 61 6c 69 66 79 50 61 74 68 20 2d 2d 0a 20 QualifyPath --.
4680: 2a 0a 20 2a 09 54 68 69 73 20 63 6f 6d 70 6f 73 *. *.This compos
4690: 65 73 20 74 68 65 20 63 75 72 72 65 6e 74 20 77 es the current w
46a0: 6f 72 6b 69 6e 67 20 64 69 72 65 63 74 6f 72 79 orking directory
46b0: 20 77 69 74 68 20 61 20 70 72 6f 76 69 64 65 64 with a provided
46c0: 20 70 61 74 68 0a 20 2a 09 61 6e 64 20 72 65 74 path. *.and ret
46d0: 75 72 6e 73 20 74 68 65 20 66 75 6c 6c 79 20 71 urns the fully q
46e0: 75 61 6c 69 66 69 65 64 20 61 6e 64 20 6e 6f 72 ualified and nor
46f0: 6d 61 6c 69 7a 65 64 20 70 61 74 68 2e 0a 20 2a malized path.. *
4700: 09 4d 6f 73 74 6c 79 20 6e 65 65 64 65 64 20 74 .Mostly needed t
4710: 6f 20 73 65 74 75 70 20 70 61 74 68 73 20 66 6f o setup paths fo
4720: 72 20 74 65 73 74 69 6e 67 2e 0a 20 2a 2f 0a 0a r testing.. */..
4730: 69 6e 74 0a 51 75 61 6c 69 66 79 50 61 74 68 28 int.QualifyPath(
4740: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
4750: 2a 73 7a 50 61 74 68 29 0a 7b 0a 20 20 20 20 63 *szPath).{. c
4760: 68 61 72 20 73 7a 43 77 64 5b 4d 41 58 5f 50 41 har szCwd[MAX_PA
4770: 54 48 20 2b 20 31 5d 3b 0a 20 20 20 20 63 68 61 TH + 1];. cha
4780: 72 20 73 7a 54 6d 70 5b 4d 41 58 5f 50 41 54 48 r szTmp[MAX_PATH
4790: 20 2b 20 31 5d 3b 0a 20 20 20 20 63 68 61 72 20 + 1];. char
47a0: 2a 70 3b 0a 20 20 20 20 47 65 74 43 75 72 72 65 *p;. GetCurre
47b0: 6e 74 44 69 72 65 63 74 6f 72 79 28 4d 41 58 5f ntDirectory(MAX_
47c0: 50 41 54 48 2c 20 73 7a 43 77 64 29 3b 0a 20 20 PATH, szCwd);.
47d0: 20 20 77 68 69 6c 65 20 28 28 70 20 3d 20 73 74 while ((p = st
47e0: 72 63 68 72 28 73 7a 50 61 74 68 2c 20 27 2f 27 rchr(szPath, '/'
47f0: 29 29 20 26 26 20 2a 70 29 0a 09 2a 70 20 3d 20 )) && *p)..*p =
4800: 27 5c 5c 27 3b 0a 20 20 20 20 50 61 74 68 43 6f '\\';. PathCo
4810: 6d 62 69 6e 65 28 73 7a 54 6d 70 2c 20 73 7a 43 mbine(szTmp, szC
4820: 77 64 2c 20 73 7a 50 61 74 68 29 3b 0a 20 20 20 wd, szPath);.
4830: 20 50 61 74 68 43 61 6e 6f 6e 69 63 61 6c 69 7a PathCanonicaliz
4840: 65 28 73 7a 43 77 64 2c 20 73 7a 54 6d 70 29 3b e(szCwd, szTmp);
4850: 0a 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c . printf("%s\
4860: 6e 22 2c 20 73 7a 43 77 64 29 3b 0a 20 20 20 20 n", szCwd);.
4870: 72 65 74 75 72 6e 20 30 3b 0a 7d 0a 0a 2f 2a 0a return 0;.}../*.
4880: 20 2a 20 4c 6f 63 61 6c 20 76 61 72 69 61 62 6c * Local variabl
4890: 65 73 3a 0a 20 2a 20 20 20 6d 6f 64 65 3a 20 63 es:. * mode: c
48a0: 0a 20 2a 20 20 20 63 2d 62 61 73 69 63 2d 6f 66 . * c-basic-of
48b0: 66 73 65 74 3a 20 34 0a 20 2a 20 20 20 66 69 6c fset: 4. * fil
48c0: 6c 2d 63 6f 6c 75 6d 6e 3a 20 37 38 0a 20 2a 20 l-column: 78. *
48d0: 20 20 69 6e 64 65 6e 74 2d 74 61 62 73 2d 6d 6f indent-tabs-mo
48e0: 64 65 3a 20 74 0a 20 2a 20 20 20 74 61 62 2d 77 de: t. * tab-w
48f0: 69 64 74 68 3a 20 38 0a 20 2a 20 45 6e 64 3a 0a idth: 8. * End:.
4900: 20 2a 2f 0a */.