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 32 20 32 30 30 37 hlp.c,v 1.2 2007
0200: 2f 30 39 2f 30 36 20 32 31 3a 30 31 3a 35 35 20 /09/06 21:01:55
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 70 72 61 67 windows.h>.#prag
02b0: 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 6c 69 62 2c ma comment (lib,
02c0: 20 22 75 73 65 72 33 32 2e 6c 69 62 22 29 0a 23 "user32.lib").#
02d0: 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 pragma comment (
02e0: 6c 69 62 2c 20 22 6b 65 72 6e 65 6c 33 32 2e 6c lib, "kernel32.l
02f0: 69 62 22 29 0a 23 69 6e 63 6c 75 64 65 20 3c 73 ib").#include <s
0300: 74 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 tdio.h>.#include
0310: 20 3c 6d 61 74 68 2e 68 3e 0a 23 69 66 20 64 65 <math.h>.#if de
0320: 66 69 6e 65 64 28 5f 4d 5f 49 41 36 34 29 20 7c fined(_M_IA64) |
0330: 7c 20 64 65 66 69 6e 65 64 28 5f 4d 5f 41 4d 44 | defined(_M_AMD
0340: 36 34 29 0a 23 70 72 61 67 6d 61 20 63 6f 6d 6d 64).#pragma comm
0350: 65 6e 74 28 6c 69 62 2c 20 22 62 75 66 66 65 72 ent(lib, "buffer
0360: 6f 76 65 72 66 6c 6f 77 55 22 29 0a 23 65 6e 64 overflowU").#end
0370: 69 66 0a 0a 2f 2a 20 49 53 4f 20 68 61 63 6b 20 if../* ISO hack
0380: 66 6f 72 20 64 75 6d 62 20 56 43 2b 2b 20 2a 2f for dumb VC++ */
0390: 0a 23 69 66 64 65 66 20 5f 4d 53 43 5f 56 45 52 .#ifdef _MSC_VER
03a0: 0a 23 64 65 66 69 6e 65 20 20 20 73 6e 70 72 69 .#define snpri
03b0: 6e 74 66 09 5f 73 6e 70 72 69 6e 74 66 0a 23 65 ntf._snprintf.#e
03c0: 6e 64 69 66 0a 0a 0a 0a 2f 2a 20 70 72 6f 74 6f ndif..../* proto
03d0: 73 20 2a 2f 0a 0a 69 6e 74 09 09 43 68 65 63 6b s */..int..Check
03e0: 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 61 74 75 ForCompilerFeatu
03f0: 72 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6f re(const char *o
0400: 70 74 69 6f 6e 29 3b 0a 69 6e 74 09 09 43 68 65 ption);.int..Che
0410: 63 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 ckForLinkerFeatu
0420: 72 65 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6f re(const char *o
0430: 70 74 69 6f 6e 29 3b 0a 69 6e 74 09 09 49 73 49 ption);.int..IsI
0440: 6e 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 n(const char *st
0450: 72 69 6e 67 2c 20 63 6f 6e 73 74 20 63 68 61 72 ring, const char
0460: 20 2a 73 75 62 73 74 72 69 6e 67 29 3b 0a 69 6e *substring);.in
0470: 74 09 09 47 72 65 70 46 6f 72 44 65 66 69 6e 65 t..GrepForDefine
0480: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c (const char *fil
0490: 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 e, const char *s
04a0: 74 72 69 6e 67 29 3b 0a 69 6e 74 09 09 53 75 62 tring);.int..Sub
04b0: 73 74 69 74 75 74 65 46 69 6c 65 28 63 6f 6e 73 stituteFile(cons
04c0: 74 20 63 68 61 72 20 2a 73 75 62 73 74 73 2c 20 t char *substs,
04d0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69 6c 65 const char *file
04e0: 6e 61 6d 65 29 3b 0a 63 6f 6e 73 74 20 63 68 61 name);.const cha
04f0: 72 20 2a 20 20 20 20 47 65 74 56 65 72 73 69 6f r * GetVersio
0500: 6e 46 72 6f 6d 46 69 6c 65 28 63 6f 6e 73 74 20 nFromFile(const
0510: 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d 65 2c 20 char *filename,
0520: 63 6f 6e 73 74 20 63 68 61 72 20 2a 6d 61 74 63 const char *matc
0530: 68 29 3b 0a 44 57 4f 52 44 20 57 49 4e 41 50 49 h);.DWORD WINAPI
0540: 09 52 65 61 64 46 72 6f 6d 50 69 70 65 28 4c 50 .ReadFromPipe(LP
0550: 56 4f 49 44 20 61 72 67 73 29 3b 0a 0a 2f 2a 20 VOID args);../*
0560: 67 6c 6f 62 61 6c 73 20 2a 2f 0a 0a 23 64 65 66 globals */..#def
0570: 69 6e 65 20 43 48 55 4e 4b 09 32 35 0a 23 64 65 ine CHUNK.25.#de
0580: 66 69 6e 65 20 53 54 41 54 49 43 42 55 46 46 45 fine STATICBUFFE
0590: 52 53 49 5a 45 20 20 20 20 31 30 30 30 0a 74 79 RSIZE 1000.ty
05a0: 70 65 64 65 66 20 73 74 72 75 63 74 20 7b 0a 20 pedef struct {.
05b0: 20 20 20 48 41 4e 44 4c 45 20 70 69 70 65 3b 0a HANDLE pipe;.
05c0: 20 20 20 20 63 68 61 72 20 62 75 66 66 65 72 5b char buffer[
05d0: 53 54 41 54 49 43 42 55 46 46 45 52 53 49 5a 45 STATICBUFFERSIZE
05e0: 5d 3b 0a 7d 20 70 69 70 65 69 6e 66 6f 3b 0a 0a ];.} pipeinfo;..
05f0: 70 69 70 65 69 6e 66 6f 20 4f 75 74 20 3d 20 7b pipeinfo Out = {
0600: 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 INVALID_HANDLE_V
0610: 41 4c 55 45 2c 20 27 5c 30 27 7d 3b 0a 70 69 70 ALUE, '\0'};.pip
0620: 65 69 6e 66 6f 20 45 72 72 20 3d 20 7b 49 4e 56 einfo Err = {INV
0630: 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 ALID_HANDLE_VALU
0640: 45 2c 20 27 5c 30 27 7d 3b 0a 0c 0a 2f 2a 0a 20 E, '\0'};.../*.
0650: 2a 20 65 78 69 74 63 6f 64 65 73 3a 20 30 20 3d * exitcodes: 0 =
0660: 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c 20 = no, 1 == yes,
0670: 32 20 3d 3d 20 65 72 72 6f 72 0a 20 2a 2f 0a 0a 2 == error. */..
0680: 69 6e 74 0a 6d 61 69 6e 28 0a 20 20 20 20 69 6e int.main(. in
0690: 74 20 61 72 67 63 2c 0a 20 20 20 20 63 68 61 72 t argc,. char
06a0: 20 2a 61 72 67 76 5b 5d 29 0a 7b 0a 20 20 20 20 *argv[]).{.
06b0: 63 68 61 72 20 6d 73 67 5b 33 30 30 5d 3b 0a 20 char msg[300];.
06c0: 20 20 20 44 57 4f 52 44 20 64 77 57 72 69 74 74 DWORD dwWritt
06d0: 65 6e 3b 0a 20 20 20 20 69 6e 74 20 63 68 61 72 en;. int char
06e0: 73 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 s;.. /*.
06f0: 2a 20 4d 61 6b 65 20 73 75 72 65 20 63 68 69 6c * Make sure chil
0700: 64 72 65 6e 20 28 63 6c 2e 65 78 65 20 61 6e 64 dren (cl.exe and
0710: 20 6c 69 6e 6b 2e 65 78 65 29 20 61 72 65 20 6b link.exe) are k
0720: 65 70 74 20 71 75 69 65 74 2e 0a 20 20 20 20 20 ept quiet..
0730: 2a 2f 0a 0a 20 20 20 20 53 65 74 45 72 72 6f 72 */.. SetError
0740: 4d 6f 64 65 28 53 45 4d 5f 46 41 49 4c 43 52 49 Mode(SEM_FAILCRI
0750: 54 49 43 41 4c 45 52 52 4f 52 53 20 7c 20 53 45 TICALERRORS | SE
0760: 4d 5f 4e 4f 4f 50 45 4e 46 49 4c 45 45 52 52 4f M_NOOPENFILEERRO
0770: 52 42 4f 58 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 RBOX);.. /*.
0780: 20 20 20 20 2a 20 4d 61 6b 65 20 73 75 72 65 20 * Make sure
0790: 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 61 6e 64 the compiler and
07a0: 20 6c 69 6e 6b 65 72 20 61 72 65 6e 27 74 20 65 linker aren't e
07b0: 66 66 65 63 74 65 64 20 62 79 20 74 68 65 20 6f ffected by the o
07c0: 75 74 73 69 64 65 20 77 6f 72 6c 64 2e 0a 20 20 utside world..
07d0: 20 20 20 2a 2f 0a 0a 20 20 20 20 53 65 74 45 6e */.. SetEn
07e0: 76 69 72 6f 6e 6d 65 6e 74 56 61 72 69 61 62 6c vironmentVariabl
07f0: 65 28 22 43 4c 22 2c 20 22 22 29 3b 0a 20 20 20 e("CL", "");.
0800: 20 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56 SetEnvironmentV
0810: 61 72 69 61 62 6c 65 28 22 4c 49 4e 4b 22 2c 20 ariable("LINK",
0820: 22 22 29 3b 0a 0a 20 20 20 20 69 66 20 28 61 72 "");.. if (ar
0830: 67 63 20 3e 20 31 20 26 26 20 2a 61 72 67 76 5b gc > 1 && *argv[
0840: 31 5d 20 3d 3d 20 27 2d 27 29 20 7b 0a 09 73 77 1] == '-') {..sw
0850: 69 74 63 68 20 28 2a 28 61 72 67 76 5b 31 5d 2b itch (*(argv[1]+
0860: 31 29 29 20 7b 0a 09 63 61 73 65 20 27 63 27 3a 1)) {..case 'c':
0870: 0a 09 20 20 20 20 69 66 20 28 61 72 67 63 20 21 .. if (argc !
0880: 3d 20 33 29 20 7b 0a 09 09 63 68 61 72 73 20 3d = 3) {...chars =
0890: 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 snprintf(msg, s
08a0: 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a izeof(msg) - 1,.
08b0: 09 09 20 20 20 20 20 20 20 20 22 75 73 61 67 65 .. "usage
08c0: 3a 20 25 73 20 2d 63 20 3c 63 6f 6d 70 69 6c 65 : %s -c <compile
08d0: 72 20 6f 70 74 69 6f 6e 3e 5c 6e 22 0a 09 09 09 r option>\n"....
08e0: 22 54 65 73 74 73 20 66 6f 72 20 77 68 65 74 68 "Tests for wheth
08f0: 65 72 20 63 6c 2e 65 78 65 20 73 75 70 70 6f 72 er cl.exe suppor
0900: 74 73 20 61 6e 20 6f 70 74 69 6f 6e 5c 6e 22 0a ts an option\n".
0910: 09 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 ..."exitcodes: 0
0920: 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 == no, 1 == yes
0930: 2c 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c , 2 == error\n",
0940: 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 argv[0]);...Wri
0950: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e teFile(GetStdHan
0960: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 dle(STD_ERROR_HA
0970: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 NDLE), msg, char
0980: 73 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e s,....&dwWritten
0990: 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 , NULL);...retur
09a0: 6e 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 n 2;.. }..
09b0: 20 72 65 74 75 72 6e 20 43 68 65 63 6b 46 6f 72 return CheckFor
09c0: 43 6f 6d 70 69 6c 65 72 46 65 61 74 75 72 65 28 CompilerFeature(
09d0: 61 72 67 76 5b 32 5d 29 3b 0a 09 63 61 73 65 20 argv[2]);..case
09e0: 27 6c 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 'l':.. if (ar
09f0: 67 63 20 21 3d 20 33 29 20 7b 0a 09 09 63 68 61 gc != 3) {...cha
0a00: 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 rs = snprintf(ms
0a10: 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d g, sizeof(msg) -
0a20: 20 31 2c 0a 09 20 20 20 20 20 20 20 09 09 22 75 1,.. .."u
0a30: 73 61 67 65 3a 20 25 73 20 2d 6c 20 3c 6c 69 6e sage: %s -l <lin
0a40: 6b 65 72 20 6f 70 74 69 6f 6e 3e 5c 6e 22 0a 09 ker option>\n"..
0a50: 09 09 22 54 65 73 74 73 20 66 6f 72 20 77 68 65 .."Tests for whe
0a60: 74 68 65 72 20 6c 69 6e 6b 2e 65 78 65 20 73 75 ther link.exe su
0a70: 70 70 6f 72 74 73 20 61 6e 20 6f 70 74 69 6f 6e pports an option
0a80: 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 65 \n"...."exitcode
0a90: 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d s: 0 == no, 1 ==
0aa0: 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 yes, 2 == error
0ab0: 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 \n", argv[0]);..
0ac0: 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 .WriteFile(GetSt
0ad0: 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f dHandle(STD_ERRO
0ae0: 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 R_HANDLE), msg,
0af0: 63 68 61 72 73 2c 0a 09 09 09 26 64 77 57 72 69 chars,....&dwWri
0b00: 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 tten, NULL);...r
0b10: 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a eturn 2;.. }.
0b20: 09 20 20 20 20 72 65 74 75 72 6e 20 43 68 65 63 . return Chec
0b30: 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 kForLinkerFeatur
0b40: 65 28 61 72 67 76 5b 32 5d 29 3b 0a 09 63 61 73 e(argv[2]);..cas
0b50: 65 20 27 66 27 3a 0a 09 20 20 20 20 69 66 20 28 e 'f':.. if (
0b60: 61 72 67 63 20 3d 3d 20 32 29 20 7b 0a 09 09 63 argc == 2) {...c
0b70: 68 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 hars = snprintf(
0b80: 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 msg, sizeof(msg)
0b90: 20 2d 20 31 2c 0a 09 09 09 22 75 73 61 67 65 3a - 1,...."usage:
0ba0: 20 25 73 20 2d 66 20 3c 73 74 72 69 6e 67 3e 20 %s -f <string>
0bb0: 3c 73 75 62 73 74 72 69 6e 67 3e 5c 6e 22 0a 09 <substring>\n"..
0bc0: 09 09 22 46 69 6e 64 20 61 20 73 75 62 73 74 72 .."Find a substr
0bd0: 69 6e 67 20 77 69 74 68 69 6e 20 61 6e 6f 74 68 ing within anoth
0be0: 65 72 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f er\n"...."exitco
0bf0: 64 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 des: 0 == no, 1
0c00: 3d 3d 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 == yes, 2 == err
0c10: 6f 72 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b or\n", argv[0]);
0c20: 0a 09 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 ...WriteFile(Get
0c30: 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 StdHandle(STD_ER
0c40: 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 ROR_HANDLE), msg
0c50: 2c 20 63 68 61 72 73 2c 0a 09 09 09 26 64 77 57 , chars,....&dwW
0c60: 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 ritten, NULL);..
0c70: 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 .return 2;..
0c80: 7d 20 65 6c 73 65 20 69 66 20 28 61 72 67 63 20 } else if (argc
0c90: 3d 3d 20 33 29 20 7b 0a 09 09 2f 2a 0a 09 09 20 == 3) {.../*...
0ca0: 2a 20 49 66 20 74 68 65 20 73 74 72 69 6e 67 20 * If the string
0cb0: 69 73 20 62 6c 61 6e 6b 2c 20 74 68 65 72 65 20 is blank, there
0cc0: 69 73 20 6e 6f 20 6d 61 74 63 68 2e 0a 09 09 20 is no match....
0cd0: 2a 2f 0a 0a 09 09 72 65 74 75 72 6e 20 30 3b 0a */....return 0;.
0ce0: 09 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 09 . } else {...
0cf0: 72 65 74 75 72 6e 20 49 73 49 6e 28 61 72 67 76 return IsIn(argv
0d00: 5b 32 5d 2c 20 61 72 67 76 5b 33 5d 29 3b 0a 09 [2], argv[3]);..
0d10: 20 20 20 20 7d 0a 09 63 61 73 65 20 27 67 27 3a }..case 'g':
0d20: 0a 09 20 20 20 20 69 66 20 28 61 72 67 63 20 3d .. if (argc =
0d30: 3d 20 32 29 20 7b 0a 09 09 63 68 61 72 73 20 3d = 2) {...chars =
0d40: 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 snprintf(msg, s
0d50: 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a izeof(msg) - 1,.
0d60: 09 09 09 22 75 73 61 67 65 3a 20 25 73 20 2d 67 ..."usage: %s -g
0d70: 20 3c 66 69 6c 65 3e 20 3c 73 74 72 69 6e 67 3e <file> <string>
0d80: 5c 6e 22 0a 09 09 09 22 67 72 65 70 20 66 6f 72 \n"...."grep for
0d90: 20 61 20 23 64 65 66 69 6e 65 5c 6e 22 0a 09 09 a #define\n"...
0da0: 09 22 65 78 69 74 63 6f 64 65 73 3a 20 69 6e 74 ."exitcodes: int
0db0: 65 67 65 72 20 6f 66 20 74 68 65 20 66 6f 75 6e eger of the foun
0dc0: 64 20 73 74 72 69 6e 67 20 28 6e 6f 20 64 65 63 d string (no dec
0dd0: 69 6d 61 6c 73 29 5c 6e 22 2c 0a 09 09 09 61 72 imals)\n",....ar
0de0: 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 65 46 gv[0]);...WriteF
0df0: 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 ile(GetStdHandle
0e00: 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c (STD_ERROR_HANDL
0e10: 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 0a E), msg, chars,.
0e20: 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c 20 4e ...&dwWritten, N
0e30: 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 32 ULL);...return 2
0e40: 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 72 65 ;.. }.. re
0e50: 74 75 72 6e 20 47 72 65 70 46 6f 72 44 65 66 69 turn GrepForDefi
0e60: 6e 65 28 61 72 67 76 5b 32 5d 2c 20 61 72 67 76 ne(argv[2], argv
0e70: 5b 33 5d 29 3b 0a 09 63 61 73 65 20 27 73 27 3a [3]);..case 's':
0e80: 0a 09 20 20 20 20 69 66 20 28 61 72 67 63 20 3d .. if (argc =
0e90: 3d 20 32 29 20 7b 0a 09 09 63 68 61 72 73 20 3d = 2) {...chars =
0ea0: 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 snprintf(msg, s
0eb0: 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a izeof(msg) - 1,.
0ec0: 09 09 09 22 75 73 61 67 65 3a 20 25 73 20 2d 73 ..."usage: %s -s
0ed0: 20 3c 73 75 62 73 74 69 74 75 74 69 6f 6e 73 20 <substitutions
0ee0: 66 69 6c 65 3e 20 3c 66 69 6c 65 3e 5c 6e 22 0a file> <file>\n".
0ef0: 09 09 09 22 50 65 72 66 6f 72 6d 20 61 20 73 65 ..."Perform a se
0f00: 74 20 6f 66 20 73 74 72 69 6e 67 20 6d 61 70 20 t of string map
0f10: 74 79 70 65 20 73 75 62 73 74 75 74 69 74 69 6f type substutitio
0f20: 6e 73 20 6f 6e 20 61 20 66 69 6c 65 5c 6e 22 0a ns on a file\n".
0f30: 09 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 ..."exitcodes: 0
0f40: 5c 6e 22 2c 0a 09 09 09 61 72 67 76 5b 30 5d 29 \n",....argv[0])
0f50: 3b 0a 09 09 57 72 69 74 65 46 69 6c 65 28 47 65 ;...WriteFile(Ge
0f60: 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 tStdHandle(STD_E
0f70: 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 RROR_HANDLE), ms
0f80: 67 2c 20 63 68 61 72 73 2c 0a 09 09 09 26 64 77 g, chars,....&dw
0f90: 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a Written, NULL);.
0fa0: 09 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 ..return 2;..
0fb0: 20 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 53 }.. return S
0fc0: 75 62 73 74 69 74 75 74 65 46 69 6c 65 28 61 72 ubstituteFile(ar
0fd0: 67 76 5b 32 5d 2c 20 61 72 67 76 5b 33 5d 29 3b gv[2], argv[3]);
0fe0: 0a 09 63 61 73 65 20 27 56 27 3a 0a 09 20 20 20 ..case 'V':..
0ff0: 20 69 66 20 28 61 72 67 63 20 21 3d 20 34 29 20 if (argc != 4)
1000: 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 {...chars = snpr
1010: 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 intf(msg, sizeof
1020: 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 20 20 20 (msg) - 1,...
1030: 20 22 75 73 61 67 65 3a 20 25 73 20 2d 56 20 66 "usage: %s -V f
1040: 69 6c 65 6e 61 6d 65 20 6d 61 74 63 68 73 74 72 ilename matchstr
1050: 69 6e 67 5c 6e 22 0a 09 09 20 20 20 20 22 45 78 ing\n"... "Ex
1060: 74 72 61 63 74 20 61 20 76 65 72 73 69 6f 6e 20 tract a version
1070: 66 72 6f 6d 20 61 20 66 69 6c 65 3a 5c 6e 22 0a from a file:\n".
1080: 09 09 20 20 20 20 22 65 67 3a 20 70 6b 67 49 6e .. "eg: pkgIn
1090: 64 65 78 2e 74 63 6c 20 5c 22 70 61 63 6b 61 67 dex.tcl \"packag
10a0: 65 20 69 66 6e 65 65 64 65 64 20 68 74 74 70 5c e ifneeded http\
10b0: 22 22 2c 0a 09 09 20 20 20 20 61 72 67 76 5b 30 "",... argv[0
10c0: 5d 29 3b 0a 09 09 57 72 69 74 65 46 69 6c 65 28 ]);...WriteFile(
10d0: 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 GetStdHandle(STD
10e0: 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 _ERROR_HANDLE),
10f0: 6d 73 67 2c 20 63 68 61 72 73 2c 0a 09 09 20 20 msg, chars,...
1100: 20 20 26 64 77 57 72 69 74 74 65 6e 2c 20 4e 55 &dwWritten, NU
1110: 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 30 3b LL);...return 0;
1120: 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 70 72 69 .. }.. pri
1130: 6e 74 66 28 22 25 73 5c 6e 22 2c 20 47 65 74 56 ntf("%s\n", GetV
1140: 65 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 61 ersionFromFile(a
1150: 72 67 76 5b 32 5d 2c 20 61 72 67 76 5b 33 5d 29 rgv[2], argv[3])
1160: 29 3b 0a 09 20 20 20 20 72 65 74 75 72 6e 20 30 );.. return 0
1170: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 63 ;..}. }. c
1180: 68 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 hars = snprintf(
1190: 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 msg, sizeof(msg)
11a0: 20 2d 20 31 2c 0a 09 20 20 20 20 22 75 73 61 67 - 1,.. "usag
11b0: 65 3a 20 25 73 20 2d 63 7c 2d 6c 7c 2d 66 7c 2d e: %s -c|-l|-f|-
11c0: 67 7c 2d 56 20 2e 2e 2e 5c 6e 22 0a 09 20 20 20 g|-V ...\n"..
11d0: 20 22 54 68 69 73 20 69 73 20 61 20 6c 69 74 74 "This is a litt
11e0: 6c 65 20 68 65 6c 70 65 72 20 61 70 70 20 74 6f le helper app to
11f0: 20 65 71 75 61 6c 69 7a 65 20 73 68 65 6c 6c 20 equalize shell
1200: 64 69 66 66 65 72 65 6e 63 65 73 20 62 65 74 77 differences betw
1210: 65 65 6e 20 57 69 6e 4e 54 20 61 6e 64 5c 6e 22 een WinNT and\n"
1220: 0a 09 20 20 20 20 22 57 69 6e 39 78 20 61 6e 64 .. "Win9x and
1230: 20 67 65 74 20 6e 6d 61 6b 65 2e 65 78 65 20 74 get nmake.exe t
1240: 6f 20 61 63 63 6f 6d 70 6c 69 73 68 20 69 74 73 o accomplish its
1250: 20 6a 6f 62 2e 5c 6e 22 2c 0a 09 20 20 20 20 61 job.\n",.. a
1260: 72 67 76 5b 30 5d 29 3b 0a 20 20 20 20 57 72 69 rgv[0]);. Wri
1270: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e teFile(GetStdHan
1280: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 dle(STD_ERROR_HA
1290: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 NDLE), msg, char
12a0: 73 2c 20 26 64 77 57 72 69 74 74 65 6e 2c 20 4e s, &dwWritten, N
12b0: 55 4c 4c 29 3b 0a 20 20 20 20 72 65 74 75 72 6e ULL);. return
12c0: 20 32 3b 0a 7d 0a 0c 0a 69 6e 74 0a 43 68 65 63 2;.}...int.Chec
12d0: 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 61 74 kForCompilerFeat
12e0: 75 72 65 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 ure(. const c
12f0: 68 61 72 20 2a 6f 70 74 69 6f 6e 29 0a 7b 0a 20 har *option).{.
1300: 20 20 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 STARTUPINFO s
1310: 69 3b 0a 20 20 20 20 50 52 4f 43 45 53 53 5f 49 i;. PROCESS_I
1320: 4e 46 4f 52 4d 41 54 49 4f 4e 20 70 69 3b 0a 20 NFORMATION pi;.
1330: 20 20 20 53 45 43 55 52 49 54 59 5f 41 54 54 52 SECURITY_ATTR
1340: 49 42 55 54 45 53 20 73 61 3b 0a 20 20 20 20 44 IBUTES sa;. D
1350: 57 4f 52 44 20 74 68 72 65 61 64 49 44 3b 0a 20 WORD threadID;.
1360: 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 30 5d char msg[300]
1370: 3b 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 20 ;. BOOL ok;.
1380: 20 20 20 48 41 4e 44 4c 45 20 68 50 72 6f 63 65 HANDLE hProce
1390: 73 73 2c 20 68 2c 20 70 69 70 65 54 68 72 65 61 ss, h, pipeThrea
13a0: 64 73 5b 32 5d 3b 0a 20 20 20 20 63 68 61 72 20 ds[2];. char
13b0: 63 6d 64 6c 69 6e 65 5b 31 30 30 5d 3b 0a 0a 20 cmdline[100];..
13c0: 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20 47 65 hProcess = Ge
13d0: 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73 73 28 tCurrentProcess(
13e0: 29 3b 0a 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f );.. ZeroMemo
13f0: 72 79 28 26 70 69 2c 20 73 69 7a 65 6f 66 28 50 ry(&pi, sizeof(P
1400: 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 ROCESS_INFORMATI
1410: 4f 4e 29 29 3b 0a 20 20 20 20 5a 65 72 6f 4d 65 ON));. ZeroMe
1420: 6d 6f 72 79 28 26 73 69 2c 20 73 69 7a 65 6f 66 mory(&si, sizeof
1430: 28 53 54 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a (STARTUPINFO));.
1440: 20 20 20 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 si.cb = size
1450: 6f 66 28 53 54 41 52 54 55 50 49 4e 46 4f 29 3b of(STARTUPINFO);
1460: 0a 20 20 20 20 73 69 2e 64 77 46 6c 61 67 73 20 . si.dwFlags
1470: 20 20 3d 20 53 54 41 52 54 46 5f 55 53 45 53 54 = STARTF_USEST
1480: 44 48 41 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 DHANDLES;. si
1490: 2e 68 53 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 .hStdInput = INV
14a0: 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 ALID_HANDLE_VALU
14b0: 45 3b 0a 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f E;.. ZeroMemo
14c0: 72 79 28 26 73 61 2c 20 73 69 7a 65 6f 66 28 53 ry(&sa, sizeof(S
14d0: 45 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 ECURITY_ATTRIBUT
14e0: 45 53 29 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 ES));. sa.nLe
14f0: 6e 67 74 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 ngth = sizeof(SE
1500: 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 CURITY_ATTRIBUTE
1510: 53 29 3b 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 S);. sa.lpSec
1520: 75 72 69 74 79 44 65 73 63 72 69 70 74 6f 72 20 urityDescriptor
1530: 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 = NULL;. sa.b
1540: 49 6e 68 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 InheritHandle =
1550: 46 41 4c 53 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 FALSE;.. /*.
1560: 20 20 20 20 2a 20 43 72 65 61 74 65 20 61 20 6e * Create a n
1570: 6f 6e 2d 69 6e 68 65 72 69 74 69 62 6c 65 20 70 on-inheritible p
1580: 69 70 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 ipe.. */..
1590: 20 20 43 72 65 61 74 65 50 69 70 65 28 26 4f 75 CreatePipe(&Ou
15a0: 74 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c t.pipe, &h, &sa,
15b0: 20 30 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 0);.. /*.
15c0: 20 20 2a 20 44 75 70 65 20 74 68 65 20 77 72 69 * Dupe the wri
15d0: 74 65 20 73 69 64 65 2c 20 6d 61 6b 65 20 69 74 te side, make it
15e0: 20 69 6e 68 65 72 69 74 69 62 6c 65 2c 20 61 6e inheritible, an
15f0: 64 20 63 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 d close the orig
1600: 69 6e 61 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 inal.. */..
1610: 20 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 DuplicateHand
1620: 6c 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 le(hProcess, h,
1630: 68 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 hProcess, &si.hS
1640: 74 64 4f 75 74 70 75 74 2c 20 30 2c 20 54 52 55 tdOutput, 0, TRU
1650: 45 2c 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 E,.. DUPLICAT
1660: 45 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 E_SAME_ACCESS |
1670: 44 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f DUPLICATE_CLOSE_
1680: 53 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a SOURCE);.. /*
1690: 0a 20 20 20 20 20 2a 20 53 61 6d 65 20 61 73 20 . * Same as
16a0: 61 62 6f 76 65 2c 20 62 75 74 20 66 6f 72 20 74 above, but for t
16b0: 68 65 20 65 72 72 6f 72 20 73 69 64 65 2e 0a 20 he error side..
16c0: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 72 65 61 */.. Crea
16d0: 74 65 50 69 70 65 28 26 45 72 72 2e 70 69 70 65 tePipe(&Err.pipe
16e0: 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 3b 0a 20 , &h, &sa, 0);.
16f0: 20 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 DuplicateHand
1700: 6c 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 le(hProcess, h,
1710: 68 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 hProcess, &si.hS
1720: 74 64 45 72 72 6f 72 2c 20 30 2c 20 54 52 55 45 tdError, 0, TRUE
1730: 2c 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 ,.. DUPLICATE
1740: 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 _SAME_ACCESS | D
1750: 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 UPLICATE_CLOSE_S
1760: 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a OURCE);.. /*.
1770: 20 20 20 20 20 2a 20 42 61 73 65 20 63 6f 6d 6d * Base comm
1780: 61 6e 64 20 6c 69 6e 65 2e 0a 20 20 20 20 20 2a and line.. *
1790: 2f 0a 0a 20 20 20 20 6c 73 74 72 63 70 79 28 63 /.. lstrcpy(c
17a0: 6d 64 6c 69 6e 65 2c 20 22 63 6c 2e 65 78 65 20 mdline, "cl.exe
17b0: 2d 6e 6f 6c 6f 67 6f 20 2d 63 20 2d 54 43 20 2d -nologo -c -TC -
17c0: 5a 73 20 2d 58 20 2d 46 70 2e 5c 5c 5f 6a 75 6e Zs -X -Fp.\\_jun
17d0: 6b 2e 70 63 68 20 22 29 3b 0a 0a 20 20 20 20 2f k.pch ");.. /
17e0: 2a 0a 20 20 20 20 20 2a 20 41 70 70 65 6e 64 20 *. * Append
17f0: 6f 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 our option for t
1800: 65 73 74 69 6e 67 0a 20 20 20 20 20 2a 2f 0a 0a esting. */..
1810: 20 20 20 20 6c 73 74 72 63 61 74 28 63 6d 64 6c lstrcat(cmdl
1820: 69 6e 65 2c 20 6f 70 74 69 6f 6e 29 3b 0a 0a 20 ine, option);..
1830: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 46 69 6c /*. * Fil
1840: 65 6e 61 6d 65 20 74 6f 20 63 6f 6d 70 69 6c 65 ename to compile
1850: 2c 20 77 68 69 63 68 20 65 78 69 73 74 73 2c 20 , which exists,
1860: 62 75 74 20 69 73 20 6e 6f 74 68 69 6e 67 20 61 but is nothing a
1870: 6e 64 20 65 6d 70 74 79 2e 0a 20 20 20 20 20 2a nd empty.. *
1880: 2f 0a 0a 20 20 20 20 6c 73 74 72 63 61 74 28 63 /.. lstrcat(c
1890: 6d 64 6c 69 6e 65 2c 20 22 20 2e 5c 5c 6e 75 6c mdline, " .\\nul
18a0: 22 29 3b 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 ");.. ok = Cr
18b0: 65 61 74 65 50 72 6f 63 65 73 73 28 0a 09 20 20 eateProcess(..
18c0: 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d NULL,. /* M
18d0: 6f 64 75 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 odule name. */..
18e0: 20 20 20 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 cmdline,.
18f0: 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 /* Command line
1900: 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 . */.. NULL,.
1910: 20 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 /* Process h
1920: 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 andle not inheri
1930: 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e table. */.. N
1940: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 ULL,. /* Thre
1950: 61 64 20 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e ad handle not in
1960: 68 65 72 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 heritable. */..
1970: 20 20 20 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 TRUE,. /*
1980: 79 65 73 2c 20 69 6e 68 65 72 69 74 20 68 61 6e yes, inherit han
1990: 64 6c 65 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 dles. */.. DE
19a0: 54 41 43 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 TACHED_PROCESS,
19b0: 2f 2a 20 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f /* No console fo
19c0: 72 20 79 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e r you. */.. N
19d0: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 ULL,. /* Use
19e0: 70 61 72 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e parent's environ
19f0: 6d 65 6e 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 ment block. */..
1a00: 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a NULL,. /*
1a10: 20 55 73 65 20 70 61 72 65 6e 74 27 73 20 73 74 Use parent's st
1a20: 61 72 74 69 6e 67 20 64 69 72 65 63 74 6f 72 79 arting directory
1a30: 2e 20 2a 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 . */.. &si,.
1a40: 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f /* Pointer to
1a50: 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 74 72 STARTUPINFO str
1a60: 75 63 74 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 ucture. */..
1a70: 26 70 69 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 &pi);. /* Poi
1a80: 6e 74 65 72 20 74 6f 20 50 52 4f 43 45 53 53 5f nter to PROCESS_
1a90: 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 INFORMATION stru
1aa0: 63 74 75 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 cture. */.. i
1ab0: 66 20 28 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 f (!ok) {..DWORD
1ac0: 20 65 72 72 20 3d 20 47 65 74 4c 61 73 74 45 72 err = GetLastEr
1ad0: 72 6f 72 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 ror();..int char
1ae0: 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 s = snprintf(msg
1af0: 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 , sizeof(msg) -
1b00: 31 2c 0a 09 09 22 54 72 69 65 64 20 74 6f 20 6c 1,..."Tried to l
1b10: 61 75 6e 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 aunch: \"%s\", b
1b20: 75 74 20 67 6f 74 20 65 72 72 6f 72 20 5b 25 75 ut got error [%u
1b30: 5d 3a 20 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65 ]: ", cmdline, e
1b40: 72 72 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73 rr);...FormatMes
1b50: 73 61 67 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53 sage(FORMAT_MESS
1b60: 41 47 45 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c AGE_FROM_SYSTEM|
1b70: 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49 FORMAT_MESSAGE_I
1b80: 47 4e 4f 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09 GNORE_INSERTS|..
1b90: 09 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f .FORMAT_MESSAGE_
1ba0: 4d 41 58 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20 MAX_WIDTH_MASK,
1bb0: 30 4c 2c 20 65 72 72 2c 20 30 2c 20 28 4c 50 56 0L, err, 0, (LPV
1bc0: 4f 49 44 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c OID)&msg[chars],
1bd0: 0a 09 09 28 33 30 30 2d 63 68 61 72 73 29 2c 20 ...(300-chars),
1be0: 30 29 3b 0a 09 57 72 69 74 65 46 69 6c 65 28 47 0);..WriteFile(G
1bf0: 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f etStdHandle(STD_
1c00: 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d ERROR_HANDLE), m
1c10: 73 67 2c 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c sg,lstrlen(msg),
1c20: 20 26 65 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65 &err,NULL);..re
1c30: 74 75 72 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 turn 2;. }..
1c40: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f /*. * Clo
1c50: 73 65 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65 se our reference
1c60: 73 20 74 6f 20 74 68 65 20 77 72 69 74 65 20 68 s to the write h
1c70: 61 6e 64 6c 65 73 20 74 68 61 74 20 68 61 76 65 andles that have
1c80: 20 6e 6f 77 20 62 65 65 6e 20 69 6e 68 65 72 69 now been inheri
1c90: 74 65 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 ted.. */..
1ca0: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 CloseHandle(si
1cb0: 2e 68 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 .hStdOutput);.
1cc0: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 CloseHandle(si
1cd0: 2e 68 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 .hStdError);..
1ce0: 20 20 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64 WaitForInputId
1cf0: 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 le(pi.hProcess,
1d00: 35 30 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 5000);. Close
1d10: 48 61 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61 Handle(pi.hThrea
1d20: 64 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 d);.. /*.
1d30: 20 2a 20 53 74 61 72 74 20 74 68 65 20 70 69 70 * Start the pip
1d40: 65 20 72 65 61 64 65 72 20 74 68 72 65 61 64 73 e reader threads
1d50: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70 .. */.. p
1d60: 69 70 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 ipeThreads[0] =
1d70: 43 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c CreateThread(NUL
1d80: 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 L, 0, ReadFromPi
1d90: 70 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 pe, &Out, 0, &th
1da0: 72 65 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70 readID);. pip
1db0: 65 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 eThreads[1] = Cr
1dc0: 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c eateThread(NULL,
1dd0: 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 0, ReadFromPipe
1de0: 2c 20 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65 , &Err, 0, &thre
1df0: 61 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 adID);.. /*.
1e00: 20 20 20 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74 * Block wait
1e10: 69 6e 67 20 66 6f 72 20 74 68 65 20 70 72 6f 63 ing for the proc
1e20: 65 73 73 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20 ess to end..
1e30: 20 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f 72 */.. WaitFor
1e40: 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e SingleObject(pi.
1e50: 68 50 72 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49 hProcess, INFINI
1e60: 54 45 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 TE);. CloseHa
1e70: 6e 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 ndle(pi.hProcess
1e80: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 );.. /*.
1e90: 2a 20 57 61 69 74 20 66 6f 72 20 6f 75 72 20 70 * Wait for our p
1ea0: 69 70 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 ipe to get done
1eb0: 72 65 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 reading, should
1ec0: 69 74 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73 it be a little s
1ed0: 6c 6f 77 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 low.. */..
1ee0: 20 20 57 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c WaitForMultipl
1ef0: 65 4f 62 6a 65 63 74 73 28 32 2c 20 70 69 70 65 eObjects(2, pipe
1f00: 54 68 72 65 61 64 73 2c 20 54 52 55 45 2c 20 35 Threads, TRUE, 5
1f10: 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 00);. CloseHa
1f20: 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73 ndle(pipeThreads
1f30: 5b 30 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 [0]);. CloseH
1f40: 61 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 andle(pipeThread
1f50: 73 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 s[1]);.. /*.
1f60: 20 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74 * Look for t
1f70: 68 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77 he commandline w
1f80: 61 72 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 62 arning code in b
1f90: 6f 74 68 20 73 74 72 65 61 6d 73 2e 0a 20 20 20 oth streams..
1fa0: 20 20 2a 20 20 2d 20 69 6e 20 4d 53 56 43 20 36 * - in MSVC 6
1fb0: 20 26 20 37 20 77 65 20 67 65 74 20 44 34 30 30 & 7 we get D400
1fc0: 32 2c 20 69 6e 20 4d 53 56 43 20 38 20 77 65 20 2, in MSVC 8 we
1fd0: 67 65 74 20 44 39 30 30 32 2e 0a 20 20 20 20 20 get D9002..
1fe0: 2a 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 21 */.. return !
1ff0: 28 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 (strstr(Out.buff
2000: 65 72 2c 20 22 44 34 30 30 32 22 29 20 21 3d 20 er, "D4002") !=
2010: 4e 55 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 20 NULL.
2020: 20 20 7c 7c 20 73 74 72 73 74 72 28 45 72 72 2e || strstr(Err.
2030: 62 75 66 66 65 72 2c 20 22 44 34 30 30 32 22 29 buffer, "D4002")
2040: 20 21 3d 20 4e 55 4c 4c 0a 20 20 20 20 20 20 20 != NULL.
2050: 20 20 20 20 20 20 7c 7c 20 73 74 72 73 74 72 28 || strstr(
2060: 4f 75 74 2e 62 75 66 66 65 72 2c 20 22 44 39 30 Out.buffer, "D90
2070: 30 32 22 29 20 21 3d 20 4e 55 4c 4c 0a 20 20 20 02") != NULL.
2080: 20 20 20 20 20 20 20 20 20 20 7c 7c 20 73 74 72 || str
2090: 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20 str(Err.buffer,
20a0: 22 44 39 30 30 32 22 29 20 21 3d 20 4e 55 4c 4c "D9002") != NULL
20b0: 29 3b 0a 7d 0a 0c 0a 69 6e 74 0a 43 68 65 63 6b );.}...int.Check
20c0: 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 ForLinkerFeature
20d0: 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 (. const char
20e0: 20 2a 6f 70 74 69 6f 6e 29 0a 7b 0a 20 20 20 20 *option).{.
20f0: 53 54 41 52 54 55 50 49 4e 46 4f 20 73 69 3b 0a STARTUPINFO si;.
2100: 20 20 20 20 50 52 4f 43 45 53 53 5f 49 4e 46 4f PROCESS_INFO
2110: 52 4d 41 54 49 4f 4e 20 70 69 3b 0a 20 20 20 20 RMATION pi;.
2120: 53 45 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 SECURITY_ATTRIBU
2130: 54 45 53 20 73 61 3b 0a 20 20 20 20 44 57 4f 52 TES sa;. DWOR
2140: 44 20 74 68 72 65 61 64 49 44 3b 0a 20 20 20 20 D threadID;.
2150: 63 68 61 72 20 6d 73 67 5b 33 30 30 5d 3b 0a 20 char msg[300];.
2160: 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 20 20 20 20 BOOL ok;.
2170: 48 41 4e 44 4c 45 20 68 50 72 6f 63 65 73 73 2c HANDLE hProcess,
2180: 20 68 2c 20 70 69 70 65 54 68 72 65 61 64 73 5b h, pipeThreads[
2190: 32 5d 3b 0a 20 20 20 20 63 68 61 72 20 63 6d 64 2];. char cmd
21a0: 6c 69 6e 65 5b 31 30 30 5d 3b 0a 0a 20 20 20 20 line[100];..
21b0: 68 50 72 6f 63 65 73 73 20 3d 20 47 65 74 43 75 hProcess = GetCu
21c0: 72 72 65 6e 74 50 72 6f 63 65 73 73 28 29 3b 0a rrentProcess();.
21d0: 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 . ZeroMemory(
21e0: 26 70 69 2c 20 73 69 7a 65 6f 66 28 50 52 4f 43 &pi, sizeof(PROC
21f0: 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 29 ESS_INFORMATION)
2200: 29 3b 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 );. ZeroMemor
2210: 79 28 26 73 69 2c 20 73 69 7a 65 6f 66 28 53 54 y(&si, sizeof(ST
2220: 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a 20 20 20 ARTUPINFO));.
2230: 20 73 69 2e 63 62 20 3d 20 73 69 7a 65 6f 66 28 si.cb = sizeof(
2240: 53 54 41 52 54 55 50 49 4e 46 4f 29 3b 0a 20 20 STARTUPINFO);.
2250: 20 20 73 69 2e 64 77 46 6c 61 67 73 20 20 20 3d si.dwFlags =
2260: 20 53 54 41 52 54 46 5f 55 53 45 53 54 44 48 41 STARTF_USESTDHA
2270: 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69 2e 68 53 NDLES;. si.hS
2280: 74 64 49 6e 70 75 74 20 3d 20 49 4e 56 41 4c 49 tdInput = INVALI
2290: 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55 45 3b 0a D_HANDLE_VALUE;.
22a0: 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 . ZeroMemory(
22b0: 26 73 61 2c 20 73 69 7a 65 6f 66 28 53 45 43 55 &sa, sizeof(SECU
22c0: 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 RITY_ATTRIBUTES)
22d0: 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e 67 74 );. sa.nLengt
22e0: 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43 55 52 h = sizeof(SECUR
22f0: 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 3b ITY_ATTRIBUTES);
2300: 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75 72 69 . sa.lpSecuri
2310: 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d 20 4e tyDescriptor = N
2320: 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49 6e 68 ULL;. sa.bInh
2330: 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 54 52 55 eritHandle = TRU
2340: 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 E;.. /*.
2350: 2a 20 43 72 65 61 74 65 20 61 20 6e 6f 6e 2d 69 * Create a non-i
2360: 6e 68 65 72 69 74 69 62 6c 65 20 70 69 70 65 2e nheritible pipe.
2370: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 72 . */.. Cr
2380: 65 61 74 65 50 69 70 65 28 26 4f 75 74 2e 70 69 eatePipe(&Out.pi
2390: 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 3b pe, &h, &sa, 0);
23a0: 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 .. /*. *
23b0: 44 75 70 65 20 74 68 65 20 77 72 69 74 65 20 73 Dupe the write s
23c0: 69 64 65 2c 20 6d 61 6b 65 20 69 74 20 69 6e 68 ide, make it inh
23d0: 65 72 69 74 69 62 6c 65 2c 20 61 6e 64 20 63 6c eritible, and cl
23e0: 6f 73 65 20 74 68 65 20 6f 72 69 67 69 6e 61 6c ose the original
23f0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 44 .. */.. D
2400: 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 68 uplicateHandle(h
2410: 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 6f Process, h, hPro
2420: 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 4f 75 cess, &si.hStdOu
2430: 74 70 75 74 2c 20 30 2c 20 54 52 55 45 2c 0a 09 tput, 0, TRUE,..
2440: 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 41 DUPLICATE_SA
2450: 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 4c ME_ACCESS | DUPL
2460: 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 52 ICATE_CLOSE_SOUR
2470: 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 CE);.. /*.
2480: 20 20 2a 20 53 61 6d 65 20 61 73 20 61 62 6f 76 * Same as abov
2490: 65 2c 20 62 75 74 20 66 6f 72 20 74 68 65 20 65 e, but for the e
24a0: 72 72 6f 72 20 73 69 64 65 2e 0a 20 20 20 20 20 rror side..
24b0: 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 65 50 69 */.. CreatePi
24c0: 70 65 28 26 45 72 72 2e 70 69 70 65 2c 20 26 68 pe(&Err.pipe, &h
24d0: 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20 20 20 44 , &sa, 0);. D
24e0: 75 70 6c 69 63 61 74 65 48 61 6e 64 6c 65 28 68 uplicateHandle(h
24f0: 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 50 72 6f Process, h, hPro
2500: 63 65 73 73 2c 20 26 73 69 2e 68 53 74 64 45 72 cess, &si.hStdEr
2510: 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c 0a 09 20 ror, 0, TRUE,..
2520: 20 20 20 44 55 50 4c 49 43 41 54 45 5f 53 41 4d DUPLICATE_SAM
2530: 45 5f 41 43 43 45 53 53 20 7c 20 44 55 50 4c 49 E_ACCESS | DUPLI
2540: 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f 55 52 43 CATE_CLOSE_SOURC
2550: 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 E);.. /*.
2560: 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61 6e 64 20 * Base command
2570: 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 line.. */..
2580: 20 20 20 6c 73 74 72 63 70 79 28 63 6d 64 6c 69 lstrcpy(cmdli
2590: 6e 65 2c 20 22 6c 69 6e 6b 2e 65 78 65 20 2d 6e ne, "link.exe -n
25a0: 6f 6c 6f 67 6f 20 22 29 3b 0a 0a 20 20 20 20 2f ologo ");.. /
25b0: 2a 0a 20 20 20 20 20 2a 20 41 70 70 65 6e 64 20 *. * Append
25c0: 6f 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 our option for t
25d0: 65 73 74 69 6e 67 2e 0a 20 20 20 20 20 2a 2f 0a esting.. */.
25e0: 0a 20 20 20 20 6c 73 74 72 63 61 74 28 63 6d 64 . lstrcat(cmd
25f0: 6c 69 6e 65 2c 20 6f 70 74 69 6f 6e 29 3b 0a 0a line, option);..
2600: 20 20 20 20 6f 6b 20 3d 20 43 72 65 61 74 65 50 ok = CreateP
2610: 72 6f 63 65 73 73 28 0a 09 20 20 20 20 4e 55 4c rocess(.. NUL
2620: 4c 2c 09 20 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 L,. /* Module
2630: 20 6e 61 6d 65 2e 20 2a 2f 0a 09 20 20 20 20 63 name. */.. c
2640: 6d 64 6c 69 6e 65 2c 09 20 20 20 20 2f 2a 20 43 mdline,. /* C
2650: 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 20 2a 2f 0a ommand line. */.
2660: 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f . NULL,. /
2670: 2a 20 50 72 6f 63 65 73 73 20 68 61 6e 64 6c 65 * Process handle
2680: 20 6e 6f 74 20 69 6e 68 65 72 69 74 61 62 6c 65 not inheritable
2690: 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 . */.. NULL,.
26a0: 20 20 20 20 2f 2a 20 54 68 72 65 61 64 20 68 61 /* Thread ha
26b0: 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 74 ndle not inherit
26c0: 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 54 52 able. */.. TR
26d0: 55 45 2c 09 20 20 20 20 2f 2a 20 79 65 73 2c 20 UE,. /* yes,
26e0: 69 6e 68 65 72 69 74 20 68 61 6e 64 6c 65 73 2e inherit handles.
26f0: 20 2a 2f 0a 09 20 20 20 20 44 45 54 41 43 48 45 */.. DETACHE
2700: 44 5f 50 52 4f 43 45 53 53 2c 20 2f 2a 20 4e 6f D_PROCESS, /* No
2710: 20 63 6f 6e 73 6f 6c 65 20 66 6f 72 20 79 6f 75 console for you
2720: 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 . */.. NULL,.
2730: 20 20 20 20 2f 2a 20 55 73 65 20 70 61 72 65 6e /* Use paren
2740: 74 27 73 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 t's environment
2750: 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 20 20 20 20 4e block. */.. N
2760: 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 ULL,. /* Use
2770: 70 61 72 65 6e 74 27 73 20 73 74 61 72 74 69 6e parent's startin
2780: 67 20 64 69 72 65 63 74 6f 72 79 2e 20 2a 2f 0a g directory. */.
2790: 09 20 20 20 20 26 73 69 2c 09 20 20 20 20 2f 2a . &si,. /*
27a0: 20 50 6f 69 6e 74 65 72 20 74 6f 20 53 54 41 52 Pointer to STAR
27b0: 54 55 50 49 4e 46 4f 20 73 74 72 75 63 74 75 72 TUPINFO structur
27c0: 65 2e 20 2a 2f 0a 09 20 20 20 20 26 70 69 29 3b e. */.. &pi);
27d0: 09 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 . /* Pointer
27e0: 74 6f 20 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 to PROCESS_INFOR
27f0: 4d 41 54 49 4f 4e 20 73 74 72 75 63 74 75 72 65 MATION structure
2800: 2e 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 21 6f . */.. if (!o
2810: 6b 29 20 7b 0a 09 44 57 4f 52 44 20 65 72 72 20 k) {..DWORD err
2820: 3d 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 = GetLastError()
2830: 3b 0a 09 69 6e 74 20 63 68 61 72 73 20 3d 20 73 ;..int chars = s
2840: 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a nprintf(msg, siz
2850: 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 eof(msg) - 1,...
2860: 22 54 72 69 65 64 20 74 6f 20 6c 61 75 6e 63 68 "Tried to launch
2870: 3a 20 5c 22 25 73 5c 22 2c 20 62 75 74 20 67 6f : \"%s\", but go
2880: 74 20 65 72 72 6f 72 20 5b 25 75 5d 3a 20 22 2c t error [%u]: ",
2890: 20 63 6d 64 6c 69 6e 65 2c 20 65 72 72 29 3b 0a cmdline, err);.
28a0: 0a 09 46 6f 72 6d 61 74 4d 65 73 73 61 67 65 28 ..FormatMessage(
28b0: 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 46 FORMAT_MESSAGE_F
28c0: 52 4f 4d 5f 53 59 53 54 45 4d 7c 46 4f 52 4d 41 ROM_SYSTEM|FORMA
28d0: 54 5f 4d 45 53 53 41 47 45 5f 49 47 4e 4f 52 45 T_MESSAGE_IGNORE
28e0: 5f 49 4e 53 45 52 54 53 7c 0a 09 09 46 4f 52 4d _INSERTS|...FORM
28f0: 41 54 5f 4d 45 53 53 41 47 45 5f 4d 41 58 5f 57 AT_MESSAGE_MAX_W
2900: 49 44 54 48 5f 4d 41 53 4b 2c 20 30 4c 2c 20 65 IDTH_MASK, 0L, e
2910: 72 72 2c 20 30 2c 20 28 4c 50 56 4f 49 44 29 26 rr, 0, (LPVOID)&
2920: 6d 73 67 5b 63 68 61 72 73 5d 2c 0a 09 09 28 33 msg[chars],...(3
2930: 30 30 2d 63 68 61 72 73 29 2c 20 30 29 3b 0a 09 00-chars), 0);..
2940: 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 WriteFile(GetStd
2950: 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 Handle(STD_ERROR
2960: 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 6c 73 _HANDLE), msg,ls
2970: 74 72 6c 65 6e 28 6d 73 67 29 2c 20 26 65 72 72 trlen(msg), &err
2980: 2c 4e 55 4c 4c 29 3b 0a 09 72 65 74 75 72 6e 20 ,NULL);..return
2990: 32 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 2;. }.. /*
29a0: 0a 20 20 20 20 20 2a 20 43 6c 6f 73 65 20 6f 75 . * Close ou
29b0: 72 20 72 65 66 65 72 65 6e 63 65 73 20 74 6f 20 r references to
29c0: 74 68 65 20 77 72 69 74 65 20 68 61 6e 64 6c 65 the write handle
29d0: 73 20 74 68 61 74 20 68 61 76 65 20 6e 6f 77 20 s that have now
29e0: 62 65 65 6e 20 69 6e 68 65 72 69 74 65 64 2e 0a been inherited..
29f0: 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 43 6c 6f */.. Clo
2a00: 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 53 74 64 seHandle(si.hStd
2a10: 4f 75 74 70 75 74 29 3b 0a 20 20 20 20 43 6c 6f Output);. Clo
2a20: 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 53 74 64 seHandle(si.hStd
2a30: 45 72 72 6f 72 29 3b 0a 0a 20 20 20 20 57 61 69 Error);.. Wai
2a40: 74 46 6f 72 49 6e 70 75 74 49 64 6c 65 28 70 69 tForInputIdle(pi
2a50: 2e 68 50 72 6f 63 65 73 73 2c 20 35 30 30 30 29 .hProcess, 5000)
2a60: 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c ;. CloseHandl
2a70: 65 28 70 69 2e 68 54 68 72 65 61 64 29 3b 0a 0a e(pi.hThread);..
2a80: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 53 74 /*. * St
2a90: 61 72 74 20 74 68 65 20 70 69 70 65 20 72 65 61 art the pipe rea
2aa0: 64 65 72 20 74 68 72 65 61 64 73 2e 0a 20 20 20 der threads..
2ab0: 20 20 2a 2f 0a 0a 20 20 20 20 70 69 70 65 54 68 */.. pipeTh
2ac0: 72 65 61 64 73 5b 30 5d 20 3d 20 43 72 65 61 74 reads[0] = Creat
2ad0: 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 30 2c eThread(NULL, 0,
2ae0: 20 52 65 61 64 46 72 6f 6d 50 69 70 65 2c 20 26 ReadFromPipe, &
2af0: 4f 75 74 2c 20 30 2c 20 26 74 68 72 65 61 64 49 Out, 0, &threadI
2b00: 44 29 3b 0a 20 20 20 20 70 69 70 65 54 68 72 65 D);. pipeThre
2b10: 61 64 73 5b 31 5d 20 3d 20 43 72 65 61 74 65 54 ads[1] = CreateT
2b20: 68 72 65 61 64 28 4e 55 4c 4c 2c 20 30 2c 20 52 hread(NULL, 0, R
2b30: 65 61 64 46 72 6f 6d 50 69 70 65 2c 20 26 45 72 eadFromPipe, &Er
2b40: 72 2c 20 30 2c 20 26 74 68 72 65 61 64 49 44 29 r, 0, &threadID)
2b50: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
2b60: 20 42 6c 6f 63 6b 20 77 61 69 74 69 6e 67 20 66 Block waiting f
2b70: 6f 72 20 74 68 65 20 70 72 6f 63 65 73 73 20 74 or the process t
2b80: 6f 20 65 6e 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a o end.. */..
2b90: 20 20 20 20 57 61 69 74 46 6f 72 53 69 6e 67 6c WaitForSingl
2ba0: 65 4f 62 6a 65 63 74 28 70 69 2e 68 50 72 6f 63 eObject(pi.hProc
2bb0: 65 73 73 2c 20 49 4e 46 49 4e 49 54 45 29 3b 0a ess, INFINITE);.
2bc0: 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 CloseHandle(
2bd0: 70 69 2e 68 50 72 6f 63 65 73 73 29 3b 0a 0a 20 pi.hProcess);..
2be0: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 57 61 69 /*. * Wai
2bf0: 74 20 66 6f 72 20 6f 75 72 20 70 69 70 65 20 74 t for our pipe t
2c00: 6f 20 67 65 74 20 64 6f 6e 65 20 72 65 61 64 69 o get done readi
2c10: 6e 67 2c 20 73 68 6f 75 6c 64 20 69 74 20 62 65 ng, should it be
2c20: 20 61 20 6c 69 74 74 6c 65 20 73 6c 6f 77 2e 0a a little slow..
2c30: 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 57 61 69 */.. Wai
2c40: 74 46 6f 72 4d 75 6c 74 69 70 6c 65 4f 62 6a 65 tForMultipleObje
2c50: 63 74 73 28 32 2c 20 70 69 70 65 54 68 72 65 61 cts(2, pipeThrea
2c60: 64 73 2c 20 54 52 55 45 2c 20 35 30 30 29 3b 0a ds, TRUE, 500);.
2c70: 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 CloseHandle(
2c80: 70 69 70 65 54 68 72 65 61 64 73 5b 30 5d 29 3b pipeThreads[0]);
2c90: 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 . CloseHandle
2ca0: 28 70 69 70 65 54 68 72 65 61 64 73 5b 31 5d 29 (pipeThreads[1])
2cb0: 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a ;.. /*. *
2cc0: 20 4c 6f 6f 6b 20 66 6f 72 20 74 68 65 20 63 6f Look for the co
2cd0: 6d 6d 61 6e 64 6c 69 6e 65 20 77 61 72 6e 69 6e mmandline warnin
2ce0: 67 20 63 6f 64 65 20 69 6e 20 74 68 65 20 73 74 g code in the st
2cf0: 64 65 72 72 20 73 74 72 65 61 6d 2e 0a 20 20 20 derr stream..
2d00: 20 20 2a 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e */.. return
2d10: 20 21 28 73 74 72 73 74 72 28 4f 75 74 2e 62 75 !(strstr(Out.bu
2d20: 66 66 65 72 2c 20 22 4c 4e 4b 31 31 31 37 22 29 ffer, "LNK1117")
2d30: 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20 != NULL ||..
2d40: 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 66 66 strstr(Err.buff
2d50: 65 72 2c 20 22 4c 4e 4b 31 31 31 37 22 29 20 21 er, "LNK1117") !
2d60: 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 73 = NULL ||.. s
2d70: 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66 65 72 trstr(Out.buffer
2d80: 2c 20 22 4c 4e 4b 34 30 34 34 22 29 20 21 3d 20 , "LNK4044") !=
2d90: 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20 20 73 74 72 NULL ||.. str
2da0: 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20 str(Err.buffer,
2db0: 22 4c 4e 4b 34 30 34 34 22 29 20 21 3d 20 4e 55 "LNK4044") != NU
2dc0: 4c 4c 29 3b 0a 7d 0a 0c 0a 44 57 4f 52 44 20 57 LL);.}...DWORD W
2dd0: 49 4e 41 50 49 0a 52 65 61 64 46 72 6f 6d 50 69 INAPI.ReadFromPi
2de0: 70 65 28 0a 20 20 20 20 4c 50 56 4f 49 44 20 61 pe(. LPVOID a
2df0: 72 67 73 29 0a 7b 0a 20 20 20 20 70 69 70 65 69 rgs).{. pipei
2e00: 6e 66 6f 20 2a 70 69 20 3d 20 28 70 69 70 65 69 nfo *pi = (pipei
2e10: 6e 66 6f 20 2a 29 20 61 72 67 73 3b 0a 20 20 20 nfo *) args;.
2e20: 20 63 68 61 72 20 2a 6c 61 73 74 42 75 66 20 3d char *lastBuf =
2e30: 20 70 69 2d 3e 62 75 66 66 65 72 3b 0a 20 20 20 pi->buffer;.
2e40: 20 44 57 4f 52 44 20 64 77 52 65 61 64 3b 0a 20 DWORD dwRead;.
2e50: 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 0a 20 20 61 BOOL ok;.. a
2e60: 67 61 69 6e 3a 0a 20 20 20 20 69 66 20 28 6c 61 gain:. if (la
2e70: 73 74 42 75 66 20 2d 20 70 69 2d 3e 62 75 66 66 stBuf - pi->buff
2e80: 65 72 20 2b 20 43 48 55 4e 4b 20 3e 20 53 54 41 er + CHUNK > STA
2e90: 54 49 43 42 55 46 46 45 52 53 49 5a 45 29 20 7b TICBUFFERSIZE) {
2ea0: 0a 09 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 ..CloseHandle(pi
2eb0: 2d 3e 70 69 70 65 29 3b 0a 09 72 65 74 75 72 6e ->pipe);..return
2ec0: 20 28 44 57 4f 52 44 29 2d 31 3b 0a 20 20 20 20 (DWORD)-1;.
2ed0: 7d 0a 20 20 20 20 6f 6b 20 3d 20 52 65 61 64 46 }. ok = ReadF
2ee0: 69 6c 65 28 70 69 2d 3e 70 69 70 65 2c 20 6c 61 ile(pi->pipe, la
2ef0: 73 74 42 75 66 2c 20 43 48 55 4e 4b 2c 20 26 64 stBuf, CHUNK, &d
2f00: 77 52 65 61 64 2c 20 30 4c 29 3b 0a 20 20 20 20 wRead, 0L);.
2f10: 69 66 20 28 21 6f 6b 20 7c 7c 20 64 77 52 65 61 if (!ok || dwRea
2f20: 64 20 3d 3d 20 30 29 20 7b 0a 09 43 6c 6f 73 65 d == 0) {..Close
2f30: 48 61 6e 64 6c 65 28 70 69 2d 3e 70 69 70 65 29 Handle(pi->pipe)
2f40: 3b 0a 09 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 ;..return 0;.
2f50: 20 7d 0a 20 20 20 20 6c 61 73 74 42 75 66 20 2b }. lastBuf +
2f60: 3d 20 64 77 52 65 61 64 3b 0a 20 20 20 20 67 6f = dwRead;. go
2f70: 74 6f 20 61 67 61 69 6e 3b 0a 0a 20 20 20 20 72 to again;.. r
2f80: 65 74 75 72 6e 20 30 3b 20 20 2f 2a 20 6d 61 6b eturn 0; /* mak
2f90: 65 73 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20 es the compiler
2fa0: 68 61 70 70 79 20 2a 2f 0a 7d 0a 0c 0a 69 6e 74 happy */.}...int
2fb0: 0a 49 73 49 6e 28 0a 20 20 20 20 63 6f 6e 73 74 .IsIn(. const
2fc0: 20 63 68 61 72 20 2a 73 74 72 69 6e 67 2c 0a 20 char *string,.
2fd0: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 const char *s
2fe0: 75 62 73 74 72 69 6e 67 29 0a 7b 0a 20 20 20 20 ubstring).{.
2ff0: 72 65 74 75 72 6e 20 28 73 74 72 73 74 72 28 73 return (strstr(s
3000: 74 72 69 6e 67 2c 20 73 75 62 73 74 72 69 6e 67 tring, substring
3010: 29 20 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a ) != NULL);.}...
3020: 2f 2a 0a 20 2a 20 46 69 6e 64 20 61 20 73 70 65 /*. * Find a spe
3030: 63 69 66 69 65 64 20 23 64 65 66 69 6e 65 20 62 cified #define b
3040: 79 20 6e 61 6d 65 2e 0a 20 2a 0a 20 2a 20 49 66 y name.. *. * If
3050: 20 74 68 65 20 6c 69 6e 65 20 69 73 20 27 23 64 the line is '#d
3060: 65 66 69 6e 65 20 54 43 4c 5f 56 45 52 53 49 4f efine TCL_VERSIO
3070: 4e 20 22 38 2e 35 22 27 2c 20 69 74 20 72 65 74 N "8.5"', it ret
3080: 75 72 6e 73 20 38 35 20 61 73 20 74 68 65 20 72 urns 85 as the r
3090: 65 73 75 6c 74 2e 0a 20 2a 2f 0a 0a 69 6e 74 0a esult.. */..int.
30a0: 47 72 65 70 46 6f 72 44 65 66 69 6e 65 28 0a 20 GrepForDefine(.
30b0: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 const char *f
30c0: 69 6c 65 2c 0a 20 20 20 20 63 6f 6e 73 74 20 63 ile,. const c
30d0: 68 61 72 20 2a 73 74 72 69 6e 67 29 0a 7b 0a 20 har *string).{.
30e0: 20 20 20 63 68 61 72 20 73 31 5b 35 31 5d 2c 20 char s1[51],
30f0: 73 32 5b 35 31 5d 2c 20 73 33 5b 35 31 5d 3b 0a s2[51], s3[51];.
3100: 20 20 20 20 46 49 4c 45 20 2a 66 20 3d 20 66 6f FILE *f = fo
3110: 70 65 6e 28 66 69 6c 65 2c 20 22 72 74 22 29 3b pen(file, "rt");
3120: 0a 0a 20 20 20 20 69 66 20 28 66 20 3d 3d 20 4e .. if (f == N
3130: 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 30 ULL) {..return 0
3140: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 64 6f 20 ;. }.. do
3150: 7b 0a 09 69 6e 74 20 72 20 3d 20 66 73 63 61 6e {..int r = fscan
3160: 66 28 66 2c 20 22 25 35 30 73 22 2c 20 73 31 29 f(f, "%50s", s1)
3170: 3b 0a 0a 09 69 66 20 28 72 20 3d 3d 20 31 20 26 ;...if (r == 1 &
3180: 26 20 21 73 74 72 63 6d 70 28 73 31 2c 20 22 23 & !strcmp(s1, "#
3190: 64 65 66 69 6e 65 22 29 29 20 7b 0a 09 20 20 20 define")) {..
31a0: 20 2f 2a 0a 09 20 20 20 20 20 2a 20 47 65 74 20 /*.. * Get
31b0: 6e 65 78 74 20 74 77 6f 20 77 6f 72 64 73 2e 0a next two words..
31c0: 09 20 20 20 20 20 2a 2f 0a 0a 09 20 20 20 20 72 . */... r
31d0: 20 3d 20 66 73 63 61 6e 66 28 66 2c 20 22 25 35 = fscanf(f, "%5
31e0: 30 73 20 25 35 30 73 22 2c 20 73 32 2c 20 73 33 0s %50s", s2, s3
31f0: 29 3b 0a 09 20 20 20 20 69 66 20 28 72 20 21 3d );.. if (r !=
3200: 20 32 29 20 7b 0a 09 09 63 6f 6e 74 69 6e 75 65 2) {...continue
3210: 3b 0a 09 20 20 20 20 7d 0a 0a 09 20 20 20 20 2f ;.. }... /
3220: 2a 0a 09 20 20 20 20 20 2a 20 49 73 20 74 68 65 *.. * Is the
3230: 20 66 69 72 73 74 20 77 6f 72 64 20 77 68 61 74 first word what
3240: 20 77 65 27 72 65 20 6c 6f 6f 6b 69 6e 67 20 66 we're looking f
3250: 6f 72 3f 0a 09 20 20 20 20 20 2a 2f 0a 0a 09 20 or?.. */...
3260: 20 20 20 69 66 20 28 21 73 74 72 63 6d 70 28 73 if (!strcmp(s
3270: 32 2c 20 73 74 72 69 6e 67 29 29 20 7b 0a 09 09 2, string)) {...
3280: 64 6f 75 62 6c 65 20 64 31 3b 0a 0a 09 09 66 63 double d1;....fc
3290: 6c 6f 73 65 28 66 29 3b 0a 0a 09 09 2f 2a 0a 09 lose(f);..../*..
32a0: 09 20 2a 20 41 64 64 20 31 20 70 61 73 74 20 66 . * Add 1 past f
32b0: 69 72 73 74 20 64 6f 75 62 6c 65 20 71 75 6f 74 irst double quot
32c0: 65 20 63 68 61 72 2e 20 22 38 2e 35 22 0a 09 09 e char. "8.5"...
32d0: 20 2a 2f 0a 0a 09 09 64 31 20 3d 20 61 74 6f 66 */....d1 = atof
32e0: 28 73 33 20 2b 20 31 29 3b 09 09 20 20 2f 2a 20 (s3 + 1);.. /*
32f0: 20 20 20 38 2e 35 20 20 2a 2f 0a 09 09 77 68 69 8.5 */...whi
3300: 6c 65 20 28 66 6c 6f 6f 72 28 64 31 29 20 21 3d le (floor(d1) !=
3310: 20 64 31 29 20 7b 0a 09 09 20 20 20 20 64 31 20 d1) {... d1
3320: 2a 3d 20 31 30 2e 30 3b 0a 09 09 7d 0a 09 09 72 *= 10.0;...}...r
3330: 65 74 75 72 6e 20 28 28 69 6e 74 29 20 64 31 29 eturn ((int) d1)
3340: 3b 09 09 20 20 2f 2a 20 20 20 20 38 35 20 20 20 ;.. /* 85
3350: 2a 2f 0a 09 20 20 20 20 7d 0a 09 7d 0a 20 20 20 */.. }..}.
3360: 20 7d 20 77 68 69 6c 65 20 28 21 66 65 6f 66 28 } while (!feof(
3370: 66 29 29 3b 0a 0a 20 20 20 20 66 63 6c 6f 73 65 f));.. fclose
3380: 28 66 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 (f);. return
3390: 30 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74 0;.}.../*. * Get
33a0: 56 65 72 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 20 VersionFromFile
33b0: 2d 2d 0a 20 2a 20 09 4c 6f 6f 6b 73 20 66 6f 72 --. * .Looks for
33c0: 20 61 20 6d 61 74 63 68 20 73 74 72 69 6e 67 20 a match string
33d0: 69 6e 20 61 20 66 69 6c 65 20 61 6e 64 20 74 68 in a file and th
33e0: 65 6e 20 72 65 74 75 72 6e 73 20 74 68 65 20 76 en returns the v
33f0: 65 72 73 69 6f 6e 0a 20 2a 20 09 66 6f 6c 6c 6f ersion. * .follo
3400: 77 69 6e 67 20 74 68 65 20 6d 61 74 63 68 20 77 wing the match w
3410: 68 65 72 65 20 61 20 76 65 72 73 69 6f 6e 20 69 here a version i
3420: 73 20 61 6e 79 74 68 69 6e 67 20 61 63 63 65 70 s anything accep
3430: 74 61 62 6c 65 20 74 6f 0a 20 2a 20 09 70 61 63 table to. * .pac
3440: 6b 61 67 65 20 70 72 6f 76 69 64 65 20 6f 72 20 kage provide or
3450: 70 61 63 6b 61 67 65 20 69 66 6e 65 65 64 65 64 package ifneeded
3460: 2e 0a 20 2a 2f 0a 0a 63 6f 6e 73 74 20 63 68 61 .. */..const cha
3470: 72 20 2a 0a 47 65 74 56 65 72 73 69 6f 6e 46 72 r *.GetVersionFr
3480: 6f 6d 46 69 6c 65 28 0a 20 20 20 20 63 6f 6e 73 omFile(. cons
3490: 74 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d 65 t char *filename
34a0: 2c 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 ,. const char
34b0: 20 2a 6d 61 74 63 68 29 0a 7b 0a 20 20 20 20 73 *match).{. s
34c0: 69 7a 65 5f 74 20 63 62 42 75 66 66 65 72 20 3d ize_t cbBuffer =
34d0: 20 31 30 30 3b 0a 20 20 20 20 73 74 61 74 69 63 100;. static
34e0: 20 63 68 61 72 20 73 7a 42 75 66 66 65 72 5b 31 char szBuffer[1
34f0: 30 30 5d 3b 0a 20 20 20 20 63 68 61 72 20 2a 73 00];. char *s
3500: 7a 52 65 73 75 6c 74 20 3d 20 4e 55 4c 4c 3b 0a zResult = NULL;.
3510: 20 20 20 20 46 49 4c 45 20 2a 66 70 20 3d 20 66 FILE *fp = f
3520: 6f 70 65 6e 28 66 69 6c 65 6e 61 6d 65 2c 20 22 open(filename, "
3530: 72 74 22 29 3b 0a 0a 20 20 20 20 69 66 20 28 66 rt");.. if (f
3540: 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 2f 2a p != NULL) {../*
3550: 0a 09 20 2a 20 52 65 61 64 20 64 61 74 61 20 75 .. * Read data u
3560: 6e 74 69 6c 20 77 65 20 73 65 65 20 6f 75 72 20 ntil we see our
3570: 6d 61 74 63 68 20 73 74 72 69 6e 67 2e 0a 09 20 match string...
3580: 2a 2f 0a 0a 09 77 68 69 6c 65 20 28 66 67 65 74 */...while (fget
3590: 73 28 73 7a 42 75 66 66 65 72 2c 20 63 62 42 75 s(szBuffer, cbBu
35a0: 66 66 65 72 2c 20 66 70 29 20 21 3d 20 4e 55 4c ffer, fp) != NUL
35b0: 4c 29 20 7b 0a 09 20 20 20 20 4c 50 53 54 52 20 L) {.. LPSTR
35c0: 70 2c 20 71 3b 0a 0a 09 20 20 20 20 70 20 3d 20 p, q;... p =
35d0: 73 74 72 73 74 72 28 73 7a 42 75 66 66 65 72 2c strstr(szBuffer,
35e0: 20 6d 61 74 63 68 29 3b 0a 09 20 20 20 20 69 66 match);.. if
35f0: 20 28 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 (p != NULL) {..
3600: 09 2f 2a 0a 09 09 20 2a 20 53 6b 69 70 20 74 6f ./*... * Skip to
3610: 20 66 69 72 73 74 20 64 69 67 69 74 2e 0a 09 09 first digit....
3620: 20 2a 2f 0a 0a 09 09 77 68 69 6c 65 20 28 2a 70 */....while (*p
3630: 20 26 26 20 21 69 73 64 69 67 69 74 28 2a 70 29 && !isdigit(*p)
3640: 29 20 7b 0a 09 09 20 20 20 20 2b 2b 70 3b 0a 09 ) {... ++p;..
3650: 09 7d 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20 46 69 .}..../*... * Fi
3660: 6e 64 20 65 6e 64 69 6e 67 20 77 68 69 74 65 73 nd ending whites
3670: 70 61 63 65 2e 0a 09 09 20 2a 2f 0a 0a 09 09 71 pace.... */....q
3680: 20 3d 20 70 3b 0a 09 09 77 68 69 6c 65 20 28 2a = p;...while (*
3690: 71 20 26 26 20 28 69 73 61 6c 6e 75 6d 28 2a 71 q && (isalnum(*q
36a0: 29 20 7c 7c 20 2a 71 20 3d 3d 20 27 2e 27 29 29 ) || *q == '.'))
36b0: 20 7b 0a 09 09 20 20 20 20 2b 2b 71 3b 0a 09 09 {... ++q;...
36c0: 7d 0a 0a 09 09 6d 65 6d 63 70 79 28 73 7a 42 75 }....memcpy(szBu
36d0: 66 66 65 72 2c 20 70 2c 20 71 20 2d 20 70 29 3b ffer, p, q - p);
36e0: 0a 09 09 73 7a 42 75 66 66 65 72 5b 71 2d 70 5d ...szBuffer[q-p]
36f0: 20 3d 20 30 3b 0a 09 09 73 7a 52 65 73 75 6c 74 = 0;...szResult
3700: 20 3d 20 73 7a 42 75 66 66 65 72 3b 0a 09 09 62 = szBuffer;...b
3710: 72 65 61 6b 3b 0a 09 20 20 20 20 7d 0a 09 7d 0a reak;.. }..}.
3720: 09 66 63 6c 6f 73 65 28 66 70 29 3b 0a 20 20 20 .fclose(fp);.
3730: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 73 7a }. return sz
3740: 52 65 73 75 6c 74 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 Result;.}.../*.
3750: 2a 20 4c 69 73 74 20 68 65 6c 70 65 72 73 20 66 * List helpers f
3760: 6f 72 20 74 68 65 20 53 75 62 73 74 69 74 75 74 or the Substitut
3770: 65 46 69 6c 65 20 66 75 6e 63 74 69 6f 6e 0a 20 eFile function.
3780: 2a 2f 0a 0a 74 79 70 65 64 65 66 20 73 74 72 75 */..typedef stru
3790: 63 74 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 7b ct list_item_t {
37a0: 0a 20 20 20 20 73 74 72 75 63 74 20 6c 69 73 74 . struct list
37b0: 5f 69 74 65 6d 5f 74 20 2a 6e 65 78 74 50 74 72 _item_t *nextPtr
37c0: 3b 0a 20 20 20 20 63 68 61 72 20 2a 20 6b 65 79 ;. char * key
37d0: 3b 0a 20 20 20 20 63 68 61 72 20 2a 20 76 61 6c ;. char * val
37e0: 75 65 3b 0a 7d 20 6c 69 73 74 5f 69 74 65 6d 5f ue;.} list_item_
37f0: 74 3b 0a 0a 2f 2a 20 69 6e 73 65 72 74 20 61 20 t;../* insert a
3800: 6c 69 73 74 20 69 74 65 6d 20 69 6e 74 6f 20 74 list item into t
3810: 68 65 20 6c 69 73 74 20 28 6c 69 73 74 20 6d 61 he list (list ma
3820: 79 20 62 65 20 6e 75 6c 6c 29 20 2a 2f 0a 73 74 y be null) */.st
3830: 61 74 69 63 20 6c 69 73 74 5f 69 74 65 6d 5f 74 atic list_item_t
3840: 20 2a 0a 6c 69 73 74 5f 69 6e 73 65 72 74 28 6c *.list_insert(l
3850: 69 73 74 5f 69 74 65 6d 5f 74 20 2a 2a 6c 69 73 ist_item_t **lis
3860: 74 50 74 72 50 74 72 2c 20 63 6f 6e 73 74 20 63 tPtrPtr, const c
3870: 68 61 72 20 2a 6b 65 79 2c 20 63 6f 6e 73 74 20 har *key, const
3880: 63 68 61 72 20 2a 76 61 6c 75 65 29 0a 7b 0a 20 char *value).{.
3890: 20 20 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a list_item_t *
38a0: 69 74 65 6d 50 74 72 20 3d 20 6d 61 6c 6c 6f 63 itemPtr = malloc
38b0: 28 73 69 7a 65 6f 66 28 6c 69 73 74 5f 69 74 65 (sizeof(list_ite
38c0: 6d 5f 74 29 29 3b 0a 20 20 20 20 69 66 20 28 69 m_t));. if (i
38d0: 74 65 6d 50 74 72 29 20 7b 0a 09 69 74 65 6d 50 temPtr) {..itemP
38e0: 74 72 2d 3e 6b 65 79 20 3d 20 73 74 72 64 75 70 tr->key = strdup
38f0: 28 6b 65 79 29 3b 0a 09 69 74 65 6d 50 74 72 2d (key);..itemPtr-
3900: 3e 76 61 6c 75 65 20 3d 20 73 74 72 64 75 70 28 >value = strdup(
3910: 76 61 6c 75 65 29 3b 0a 09 69 74 65 6d 50 74 72 value);..itemPtr
3920: 2d 3e 6e 65 78 74 50 74 72 20 3d 20 4e 55 4c 4c ->nextPtr = NULL
3930: 3b 0a 0a 09 77 68 69 6c 65 28 2a 6c 69 73 74 50 ;...while(*listP
3940: 74 72 50 74 72 29 20 7b 0a 09 20 20 20 20 6c 69 trPtr) {.. li
3950: 73 74 50 74 72 50 74 72 20 3d 20 26 28 2a 6c 69 stPtrPtr = &(*li
3960: 73 74 50 74 72 50 74 72 29 2d 3e 6e 65 78 74 50 stPtrPtr)->nextP
3970: 74 72 3b 0a 09 7d 0a 09 2a 6c 69 73 74 50 74 72 tr;..}..*listPtr
3980: 50 74 72 20 3d 20 69 74 65 6d 50 74 72 3b 0a 20 Ptr = itemPtr;.
3990: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
39a0: 69 74 65 6d 50 74 72 3b 0a 7d 0a 0a 73 74 61 74 itemPtr;.}..stat
39b0: 69 63 20 76 6f 69 64 0a 6c 69 73 74 5f 66 72 65 ic void.list_fre
39c0: 65 28 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 2a e(list_item_t **
39d0: 6c 69 73 74 50 74 72 50 74 72 29 0a 7b 0a 20 20 listPtrPtr).{.
39e0: 20 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 74 list_item_t *t
39f0: 6d 70 50 74 72 2c 20 2a 6c 69 73 74 50 74 72 20 mpPtr, *listPtr
3a00: 3d 20 2a 6c 69 73 74 50 74 72 50 74 72 3b 0a 20 = *listPtrPtr;.
3a10: 20 20 20 77 68 69 6c 65 20 28 6c 69 73 74 50 74 while (listPt
3a20: 72 29 20 7b 0a 09 74 6d 70 50 74 72 20 3d 20 6c r) {..tmpPtr = l
3a30: 69 73 74 50 74 72 3b 0a 09 6c 69 73 74 50 74 72 istPtr;..listPtr
3a40: 20 3d 20 6c 69 73 74 50 74 72 2d 3e 6e 65 78 74 = listPtr->next
3a50: 50 74 72 3b 0a 09 66 72 65 65 28 74 6d 70 50 74 Ptr;..free(tmpPt
3a60: 72 2d 3e 6b 65 79 29 3b 0a 09 66 72 65 65 28 74 r->key);..free(t
3a70: 6d 70 50 74 72 2d 3e 76 61 6c 75 65 29 3b 0a 09 mpPtr->value);..
3a80: 66 72 65 65 28 74 6d 70 50 74 72 29 3b 0a 20 20 free(tmpPtr);.
3a90: 20 20 7d 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 53 75 }.}.../*. * Su
3aa0: 62 73 74 69 74 75 74 65 46 69 6c 65 20 2d 2d 0a bstituteFile --.
3ab0: 20 2a 09 41 73 20 77 69 6e 64 6f 77 73 20 64 6f *.As windows do
3ac0: 65 73 6e 27 74 20 70 72 6f 76 69 64 65 20 61 6e esn't provide an
3ad0: 79 74 68 69 6e 67 20 75 73 65 66 75 6c 20 6c 69 ything useful li
3ae0: 6b 65 20 73 65 64 20 61 6e 64 20 69 74 27 73 20 ke sed and it's
3af0: 75 6e 72 65 6c 69 61 62 6c 65 0a 20 2a 09 74 6f unreliable. *.to
3b00: 20 75 73 65 20 74 68 65 20 74 63 6c 73 68 20 79 use the tclsh y
3b10: 6f 75 20 61 72 65 20 62 75 69 6c 64 69 6e 67 20 ou are building
3b20: 61 67 61 69 6e 73 74 20 28 63 6f 6e 73 69 64 65 against (conside
3b30: 72 20 78 2d 70 6c 61 74 66 6f 72 6d 20 62 75 69 r x-platform bui
3b40: 6c 64 73 20 2d 0a 20 2a 09 65 67 20 63 6f 6d 70 lds -. *.eg comp
3b50: 69 6c 69 6e 67 20 41 4d 44 36 34 20 74 61 72 67 iling AMD64 targ
3b60: 65 74 20 66 72 6f 6d 20 49 58 38 36 29 20 77 65 et from IX86) we
3b70: 20 70 72 6f 76 69 64 65 20 61 20 73 69 6d 70 6c provide a simpl
3b80: 65 20 73 75 62 73 74 69 74 75 74 69 6f 6e 0a 20 e substitution.
3b90: 2a 09 6f 70 74 69 6f 6e 20 68 65 72 65 20 74 6f *.option here to
3ba0: 20 68 61 6e 64 6c 65 20 61 75 74 6f 63 6f 6e 66 handle autoconf
3bb0: 20 73 74 79 6c 65 20 73 75 62 73 74 69 74 75 74 style substitut
3bc0: 69 6f 6e 73 2e 0a 20 2a 09 54 68 65 20 73 75 62 ions.. *.The sub
3bd0: 73 74 69 74 75 74 69 6f 6e 20 66 69 6c 65 20 69 stitution file i
3be0: 73 20 77 68 69 74 65 73 70 61 63 65 20 61 6e 64 s whitespace and
3bf0: 20 6c 69 6e 65 20 64 65 6c 69 6d 69 74 65 64 2e line delimited.
3c00: 20 54 68 65 20 66 69 6c 65 20 73 68 6f 75 6c 64 The file should
3c10: 0a 20 2a 09 63 6f 6e 73 69 73 74 20 6f 66 20 6c . *.consist of l
3c20: 69 6e 65 73 20 6d 61 74 63 68 69 6e 67 20 74 68 ines matching th
3c30: 65 20 72 65 67 75 6c 61 72 20 65 78 70 72 65 73 e regular expres
3c40: 73 69 6f 6e 3a 0a 20 2a 09 20 20 5c 73 2a 5c 53 sion:. *. \s*\S
3c50: 2b 5c 73 2b 5c 53 2a 24 0a 20 2a 0a 20 2a 09 55 +\s+\S*$. *. *.U
3c60: 73 61 67 65 20 69 73 20 73 6f 6d 65 74 68 69 6e sage is somethin
3c70: 67 20 6c 69 6b 65 3a 0a 20 2a 09 20 20 6e 6d 61 g like:. *. nma
3c80: 6b 65 68 6c 70 20 2d 53 20 3c 3c 20 24 2a 2a 20 kehlp -S << $**
3c90: 3e 20 24 40 0a 20 2a 20 20 20 20 20 20 20 20 40 > $@. * @
3ca0: 50 41 43 4b 41 47 45 5f 4e 41 4d 45 40 20 24 28 PACKAGE_NAME@ $(
3cb0: 50 41 43 4b 41 47 45 5f 4e 41 4d 45 29 0a 20 2a PACKAGE_NAME). *
3cc0: 20 20 20 20 20 20 20 20 40 50 41 43 4b 41 47 45 @PACKAGE
3cd0: 5f 56 45 52 53 49 4f 4e 40 20 24 28 50 41 43 4b _VERSION@ $(PACK
3ce0: 41 47 45 5f 56 45 52 53 49 4f 4e 29 0a 20 2a 20 AGE_VERSION). *
3cf0: 20 20 20 20 20 20 20 3c 3c 0a 20 2a 2f 0a 0a 69 <<. */..i
3d00: 6e 74 0a 53 75 62 73 74 69 74 75 74 65 46 69 6c nt.SubstituteFil
3d10: 65 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 e(. const cha
3d20: 72 20 2a 73 75 62 73 74 69 74 75 74 69 6f 6e 73 r *substitutions
3d30: 2c 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 ,. const char
3d40: 20 2a 66 69 6c 65 6e 61 6d 65 29 0a 7b 0a 20 20 *filename).{.
3d50: 20 20 73 69 7a 65 5f 74 20 63 62 42 75 66 66 65 size_t cbBuffe
3d60: 72 20 3d 20 31 30 32 34 3b 0a 20 20 20 20 73 74 r = 1024;. st
3d70: 61 74 69 63 20 63 68 61 72 20 73 7a 42 75 66 66 atic char szBuff
3d80: 65 72 5b 31 30 32 34 5d 2c 20 73 7a 43 6f 70 79 er[1024], szCopy
3d90: 5b 31 30 32 34 5d 3b 0a 20 20 20 20 63 68 61 72 [1024];. char
3da0: 20 2a 73 7a 52 65 73 75 6c 74 20 3d 20 4e 55 4c *szResult = NUL
3db0: 4c 3b 0a 20 20 20 20 6c 69 73 74 5f 69 74 65 6d L;. list_item
3dc0: 5f 74 20 2a 73 75 62 73 74 50 74 72 20 3d 20 4e _t *substPtr = N
3dd0: 55 4c 4c 3b 0a 20 20 20 20 46 49 4c 45 20 2a 66 ULL;. FILE *f
3de0: 70 2c 20 2a 73 70 3b 0a 0a 20 20 20 20 66 70 20 p, *sp;.. fp
3df0: 3d 20 66 6f 70 65 6e 28 66 69 6c 65 6e 61 6d 65 = fopen(filename
3e00: 2c 20 22 72 74 22 29 3b 0a 20 20 20 20 69 66 20 , "rt");. if
3e10: 28 66 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 0a (fp != NULL) {..
3e20: 09 2f 2a 0a 09 20 2a 20 42 75 69 6c 64 20 61 20 ./*.. * Build a
3e30: 6c 69 73 74 20 6f 66 20 73 75 62 73 74 75 74 69 list of substuti
3e40: 74 69 6f 6e 73 20 66 72 6f 6d 20 74 68 65 20 66 tions from the f
3e50: 69 72 73 74 20 66 69 6c 65 6e 61 6d 65 0a 09 20 irst filename..
3e60: 2a 2f 0a 0a 09 73 70 20 3d 20 66 6f 70 65 6e 28 */...sp = fopen(
3e70: 73 75 62 73 74 69 74 75 74 69 6f 6e 73 2c 20 22 substitutions, "
3e80: 72 74 22 29 3b 0a 09 69 66 20 28 73 70 20 21 3d rt");..if (sp !=
3e90: 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 77 68 NULL) {.. wh
3ea0: 69 6c 65 20 28 66 67 65 74 73 28 73 7a 42 75 66 ile (fgets(szBuf
3eb0: 66 65 72 2c 20 63 62 42 75 66 66 65 72 2c 20 73 fer, cbBuffer, s
3ec0: 70 29 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 p) != NULL) {...
3ed0: 63 68 61 72 20 2a 6b 73 2c 20 2a 6b 65 2c 20 2a char *ks, *ke, *
3ee0: 76 73 2c 20 2a 76 65 3b 0a 09 09 6b 73 20 3d 20 vs, *ve;...ks =
3ef0: 73 7a 42 75 66 66 65 72 3b 0a 09 09 77 68 69 6c szBuffer;...whil
3f00: 65 20 28 6b 73 20 26 26 20 2a 6b 73 20 26 26 20 e (ks && *ks &&
3f10: 69 73 73 70 61 63 65 28 2a 6b 73 29 29 20 2b 2b isspace(*ks)) ++
3f20: 6b 73 3b 0a 09 09 6b 65 20 3d 20 6b 73 3b 0a 09 ks;...ke = ks;..
3f30: 09 77 68 69 6c 65 20 28 6b 65 20 26 26 20 2a 6b .while (ke && *k
3f40: 65 20 26 26 20 21 69 73 73 70 61 63 65 28 2a 6b e && !isspace(*k
3f50: 65 29 29 20 2b 2b 6b 65 3b 0a 09 09 76 73 20 3d e)) ++ke;...vs =
3f60: 20 6b 65 3b 0a 09 09 77 68 69 6c 65 20 28 76 73 ke;...while (vs
3f70: 20 26 26 20 2a 76 73 20 26 26 20 69 73 73 70 61 && *vs && isspa
3f80: 63 65 28 2a 76 73 29 29 20 2b 2b 76 73 3b 0a 09 ce(*vs)) ++vs;..
3f90: 09 76 65 20 3d 20 76 73 3b 0a 09 09 77 68 69 6c .ve = vs;...whil
3fa0: 65 20 28 76 65 20 26 26 20 2a 76 65 20 26 26 20 e (ve && *ve &&
3fb0: 21 28 2a 76 65 20 3d 3d 20 27 5c 72 27 20 7c 7c !(*ve == '\r' ||
3fc0: 20 2a 76 65 20 3d 3d 20 27 5c 6e 27 29 29 20 2b *ve == '\n')) +
3fd0: 2b 76 65 3b 0a 09 09 2a 6b 65 20 3d 20 30 2c 20 +ve;...*ke = 0,
3fe0: 2a 76 65 20 3d 20 30 3b 0a 09 09 6c 69 73 74 5f *ve = 0;...list_
3ff0: 69 6e 73 65 72 74 28 26 73 75 62 73 74 50 74 72 insert(&substPtr
4000: 2c 20 6b 73 2c 20 76 73 29 3b 0a 09 20 20 20 20 , ks, vs);..
4010: 7d 0a 09 20 20 20 20 66 63 6c 6f 73 65 28 73 70 }.. fclose(sp
4020: 29 3b 0a 09 7d 0a 0a 09 2f 2a 20 64 65 62 75 67 );..}.../* debug
4030: 3a 20 64 75 6d 70 20 74 68 65 20 6c 69 73 74 20 : dump the list
4040: 2a 2f 0a 23 69 66 64 65 66 20 5f 44 45 42 55 47 */.#ifdef _DEBUG
4050: 0a 09 7b 0a 09 20 20 20 20 69 6e 74 20 6e 20 3d ..{.. int n =
4060: 20 30 3b 0a 09 20 20 20 20 6c 69 73 74 5f 69 74 0;.. list_it
4070: 65 6d 5f 74 20 2a 70 20 3d 20 4e 55 4c 4c 3b 0a em_t *p = NULL;.
4080: 09 20 20 20 20 66 6f 72 20 28 70 20 3d 20 73 75 . for (p = su
4090: 62 73 74 50 74 72 3b 20 70 20 21 3d 20 4e 55 4c bstPtr; p != NUL
40a0: 4c 3b 20 70 20 3d 20 70 2d 3e 6e 65 78 74 50 74 L; p = p->nextPt
40b0: 72 2c 20 2b 2b 6e 29 20 7b 0a 09 09 66 70 72 69 r, ++n) {...fpri
40c0: 6e 74 66 28 73 74 64 65 72 72 2c 20 22 25 20 33 ntf(stderr, "% 3
40d0: 64 20 27 25 73 27 20 3d 3e 20 27 25 73 27 5c 6e d '%s' => '%s'\n
40e0: 22 2c 20 6e 2c 20 70 2d 3e 6b 65 79 2c 20 70 2d ", n, p->key, p-
40f0: 3e 76 61 6c 75 65 29 3b 0a 09 20 20 20 20 7d 0a >value);.. }.
4100: 09 7d 0a 23 65 6e 64 69 66 0a 09 0a 09 2f 2a 0a .}.#endif..../*.
4110: 09 20 2a 20 52 75 6e 20 74 68 65 20 73 75 62 73 . * Run the subs
4120: 74 69 74 75 74 69 6f 6e 73 20 6f 76 65 72 20 65 titutions over e
4130: 61 63 68 20 6c 69 6e 65 20 6f 66 20 74 68 65 20 ach line of the
4140: 69 6e 70 75 74 0a 09 20 2a 2f 0a 09 0a 09 77 68 input.. */....wh
4150: 69 6c 65 20 28 66 67 65 74 73 28 73 7a 42 75 66 ile (fgets(szBuf
4160: 66 65 72 2c 20 63 62 42 75 66 66 65 72 2c 20 66 fer, cbBuffer, f
4170: 70 29 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 p) != NULL) {..
4180: 20 20 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a list_item_t *
4190: 70 20 3d 20 4e 55 4c 4c 3b 0a 09 20 20 20 20 66 p = NULL;.. f
41a0: 6f 72 20 28 70 20 3d 20 73 75 62 73 74 50 74 72 or (p = substPtr
41b0: 3b 20 70 20 21 3d 20 4e 55 4c 4c 3b 20 70 20 3d ; p != NULL; p =
41c0: 20 70 2d 3e 6e 65 78 74 50 74 72 29 20 7b 0a 09 p->nextPtr) {..
41d0: 09 63 68 61 72 20 2a 6d 20 3d 20 73 74 72 73 74 .char *m = strst
41e0: 72 28 73 7a 42 75 66 66 65 72 2c 20 70 2d 3e 6b r(szBuffer, p->k
41f0: 65 79 29 3b 0a 09 09 69 66 20 28 6d 29 20 7b 0a ey);...if (m) {.
4200: 09 09 20 20 20 20 63 68 61 72 20 2a 63 70 2c 20 .. char *cp,
4210: 2a 6f 70 2c 20 2a 73 70 3b 0a 09 09 20 20 20 20 *op, *sp;...
4220: 63 70 20 3d 20 73 7a 43 6f 70 79 3b 0a 09 09 20 cp = szCopy;...
4230: 20 20 20 6f 70 20 3d 20 73 7a 42 75 66 66 65 72 op = szBuffer
4240: 3b 0a 09 09 20 20 20 20 77 68 69 6c 65 20 28 6f ;... while (o
4250: 70 20 21 3d 20 6d 29 20 2a 63 70 2b 2b 20 3d 20 p != m) *cp++ =
4260: 2a 6f 70 2b 2b 3b 0a 09 09 20 20 20 20 73 70 20 *op++;... sp
4270: 3d 20 70 2d 3e 76 61 6c 75 65 3b 0a 09 09 20 20 = p->value;...
4280: 20 20 77 68 69 6c 65 20 28 73 70 20 26 26 20 2a while (sp && *
4290: 73 70 29 20 2a 63 70 2b 2b 20 3d 20 2a 73 70 2b sp) *cp++ = *sp+
42a0: 2b 3b 0a 09 09 20 20 20 20 6f 70 20 2b 3d 20 73 +;... op += s
42b0: 74 72 6c 65 6e 28 70 2d 3e 6b 65 79 29 3b 0a 09 trlen(p->key);..
42c0: 09 20 20 20 20 77 68 69 6c 65 20 28 2a 6f 70 29 . while (*op)
42d0: 20 2a 63 70 2b 2b 20 3d 20 2a 6f 70 2b 2b 3b 0a *cp++ = *op++;.
42e0: 09 09 20 20 20 20 2a 63 70 20 3d 20 30 3b 0a 09 .. *cp = 0;..
42f0: 09 20 20 20 20 6d 65 6d 63 70 79 28 73 7a 42 75 . memcpy(szBu
4300: 66 66 65 72 2c 20 73 7a 43 6f 70 79 2c 20 73 69 ffer, szCopy, si
4310: 7a 65 6f 66 28 73 7a 43 6f 70 79 29 29 3b 0a 09 zeof(szCopy));..
4320: 09 7d 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 70 .}.. }.. p
4330: 72 69 6e 74 66 28 73 7a 42 75 66 66 65 72 29 3b rintf(szBuffer);
4340: 0a 09 7d 0a 09 0a 09 6c 69 73 74 5f 66 72 65 65 ..}....list_free
4350: 28 26 73 75 62 73 74 50 74 72 29 3b 0a 20 20 20 (&substPtr);.
4360: 20 7d 0a 20 20 20 20 66 63 6c 6f 73 65 28 66 70 }. fclose(fp
4370: 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b );. return 0;
4380: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 4c 6f 63 61 6c 20 .}../*. * Local
4390: 76 61 72 69 61 62 6c 65 73 3a 0a 20 2a 20 20 20 variables:. *
43a0: 6d 6f 64 65 3a 20 63 0a 20 2a 20 20 20 63 2d 62 mode: c. * c-b
43b0: 61 73 69 63 2d 6f 66 66 73 65 74 3a 20 34 0a 20 asic-offset: 4.
43c0: 2a 20 20 20 66 69 6c 6c 2d 63 6f 6c 75 6d 6e 3a * fill-column:
43d0: 20 37 38 0a 20 2a 20 20 20 69 6e 64 65 6e 74 2d 78. * indent-
43e0: 74 61 62 73 2d 6d 6f 64 65 3a 20 74 0a 20 2a 20 tabs-mode: t. *
43f0: 20 20 74 61 62 2d 77 69 64 74 68 3a 20 38 0a 20 tab-width: 8.
4400: 2a 20 45 6e 64 3a 0a 20 2a 2f 0a * End:. */.