0000: 2f 2a 20 2d 2d 2d 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 0a ---------------.
0050: 20 2a 20 6e 6d 61 6b 65 68 6c 70 2e 63 20 2d 2d * nmakehlp.c --
0060: 0a 20 2a 0a 20 2a 09 54 68 69 73 20 69 73 20 75 . *. *.This is u
0070: 73 65 64 20 74 6f 20 66 69 78 20 6c 69 6d 69 74 sed to fix limit
0080: 61 74 69 6f 6e 73 20 77 69 74 68 69 6e 20 6e 6d ations within nm
0090: 61 6b 65 20 61 6e 64 20 74 68 65 20 65 6e 76 69 ake and the envi
00a0: 72 6f 6e 6d 65 6e 74 2e 0a 20 2a 0a 20 2a 20 43 ronment.. *. * C
00b0: 6f 70 79 72 69 67 68 74 20 28 63 29 20 32 30 30 opyright (c) 200
00c0: 32 20 62 79 20 44 61 76 69 64 20 47 72 61 76 65 2 by David Grave
00d0: 72 65 61 75 78 2e 0a 20 2a 20 43 6f 70 79 72 69 reaux.. * Copyri
00e0: 67 68 74 20 28 63 29 20 32 30 30 33 20 62 79 20 ght (c) 2003 by
00f0: 50 61 74 72 69 63 6b 20 54 68 6f 79 74 73 0a 20 Patrick Thoyts.
0100: 2a 0a 20 2a 20 53 65 65 20 74 68 65 20 66 69 6c *. * See the fil
0110: 65 20 22 6c 69 63 65 6e 73 65 2e 74 65 72 6d 73 e "license.terms
0120: 22 20 66 6f 72 20 69 6e 66 6f 72 6d 61 74 69 6f " for informatio
0130: 6e 20 6f 6e 20 75 73 61 67 65 20 61 6e 64 20 72 n on usage and r
0140: 65 64 69 73 74 72 69 62 75 74 69 6f 6e 0a 20 2a edistribution. *
0150: 20 6f 66 20 74 68 69 73 20 66 69 6c 65 2c 20 61 of this file, a
0160: 6e 64 20 66 6f 72 20 61 20 44 49 53 43 4c 41 49 nd for a DISCLAI
0170: 4d 45 52 20 4f 46 20 41 4c 4c 20 57 41 52 52 41 MER OF ALL WARRA
0180: 4e 54 49 45 53 2e 0a 20 2a 0a 20 2a 20 2d 2d 2d NTIES.. *. * ---
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 2d 0a 20 2a 20 52 43 53 ---------. * RCS
01e0: 3a 20 40 28 23 29 20 24 49 64 3a 20 6e 6d 61 6b : @(#) $Id: nmak
01f0: 65 68 6c 70 2e 63 2c 76 20 31 2e 31 20 32 30 30 ehlp.c,v 1.1 200
0200: 34 2f 31 32 2f 31 37 20 31 36 3a 30 32 3a 30 36 4/12/17 16:02:06
0210: 20 70 61 74 74 68 6f 79 74 73 20 45 78 70 20 24 patthoyts Exp $
0220: 0a 20 2a 20 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 2d ----------------
0270: 0a 20 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 3c 77 . */.#include <w
0280: 69 6e 64 6f 77 73 2e 68 3e 0a 23 69 6e 63 6c 75 indows.h>.#inclu
0290: 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 23 70 72 de <stdio.h>.#pr
02a0: 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 6c 69 agma comment (li
02b0: 62 2c 20 22 75 73 65 72 33 32 2e 6c 69 62 22 29 b, "user32.lib")
02c0: 0a 23 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 .#pragma comment
02d0: 20 28 6c 69 62 2c 20 22 6b 65 72 6e 65 6c 33 32 (lib, "kernel32
02e0: 2e 6c 69 62 22 29 0a 0a 2f 2a 20 70 72 6f 74 6f .lib")../* proto
02f0: 73 20 2a 2f 0a 69 6e 74 20 43 68 65 63 6b 46 6f s */.int CheckFo
0300: 72 43 6f 6d 70 69 6c 65 72 46 65 61 74 75 72 65 rCompilerFeature
0310: 20 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6f 70 (const char *op
0320: 74 69 6f 6e 29 3b 0a 69 6e 74 20 43 68 65 63 6b tion);.int Check
0330: 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 ForLinkerFeature
0340: 20 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6f 70 (const char *op
0350: 74 69 6f 6e 29 3b 0a 69 6e 74 20 49 73 49 6e 20 tion);.int IsIn
0360: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 72 (const char *str
0370: 69 6e 67 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 ing, const char
0380: 2a 73 75 62 73 74 72 69 6e 67 29 3b 0a 44 57 4f *substring);.DWO
0390: 52 44 20 57 49 4e 41 50 49 20 52 65 61 64 46 72 RD WINAPI ReadFr
03a0: 6f 6d 50 69 70 65 20 28 4c 50 56 4f 49 44 20 61 omPipe (LPVOID a
03b0: 72 67 73 29 3b 0a 69 6e 74 20 47 65 74 56 65 72 rgs);.int GetVer
03c0: 73 69 6f 6e 46 72 6f 6d 48 65 61 64 65 72 28 63 sionFromHeader(c
03d0: 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 6c 68 2c onst char *tclh,
03e0: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 74 6b 68 const char *tkh
03f0: 29 3b 0a 0a 2f 2a 20 67 6c 6f 62 61 6c 73 20 2a );../* globals *
0400: 2f 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 /.typedef struct
0410: 20 7b 0a 20 20 20 20 48 41 4e 44 4c 45 20 70 69 {. HANDLE pi
0420: 70 65 3b 0a 20 20 20 20 63 68 61 72 20 62 75 66 pe;. char buf
0430: 66 65 72 5b 31 30 30 30 5d 3b 0a 7d 20 70 69 70 fer[1000];.} pip
0440: 65 69 6e 66 6f 3b 0a 0a 70 69 70 65 69 6e 66 6f einfo;..pipeinfo
0450: 20 4f 75 74 20 3d 20 7b 49 4e 56 41 4c 49 44 5f Out = {INVALID_
0460: 48 41 4e 44 4c 45 5f 56 41 4c 55 45 2c 20 27 5c HANDLE_VALUE, '\
0470: 30 27 7d 3b 0a 70 69 70 65 69 6e 66 6f 20 45 72 0'};.pipeinfo Er
0480: 72 20 3d 20 7b 49 4e 56 41 4c 49 44 5f 48 41 4e r = {INVALID_HAN
0490: 44 4c 45 5f 56 41 4c 55 45 2c 20 27 5c 30 27 7d DLE_VALUE, '\0'}
04a0: 3b 0a 0a 0a 0a 2f 2a 20 65 78 69 74 63 6f 64 65 ;..../* exitcode
04b0: 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d s: 0 == no, 1 ==
04c0: 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 yes, 2 == error
04d0: 20 2a 2f 0a 69 6e 74 0a 6d 61 69 6e 20 28 69 6e */.int.main (in
04e0: 74 20 61 72 67 63 2c 20 63 68 61 72 20 2a 61 72 t argc, char *ar
04f0: 67 76 5b 5d 29 0a 7b 0a 20 20 20 20 63 68 61 72 gv[]).{. char
0500: 20 6d 73 67 5b 33 30 30 5d 3b 0a 20 20 20 20 44 msg[300];. D
0510: 57 4f 52 44 20 64 77 57 72 69 74 74 65 6e 3b 0a WORD dwWritten;.
0520: 20 20 20 20 69 6e 74 20 63 68 61 72 73 3b 0a 0a int chars;..
0530: 20 20 20 20 69 66 20 28 61 72 67 63 20 3e 20 31 if (argc > 1
0540: 20 26 26 20 2a 61 72 67 76 5b 31 5d 20 3d 3d 20 && *argv[1] ==
0550: 27 2d 27 29 20 7b 0a 09 73 77 69 74 63 68 20 28 '-') {..switch (
0560: 2a 28 61 72 67 76 5b 31 5d 2b 31 29 29 20 7b 0a *(argv[1]+1)) {.
0570: 09 63 61 73 65 20 27 63 27 3a 0a 09 20 20 20 20 .case 'c':..
0580: 69 66 20 28 61 72 67 63 20 21 3d 20 33 29 20 7b if (argc != 3) {
0590: 0a 09 09 63 68 61 72 73 20 3d 20 77 73 70 72 69 ...chars = wspri
05a0: 6e 74 66 28 6d 73 67 2c 20 22 75 73 61 67 65 3a ntf(msg, "usage:
05b0: 20 25 73 20 2d 63 20 3c 63 6f 6d 70 69 6c 65 72 %s -c <compiler
05c0: 20 6f 70 74 69 6f 6e 3e 5c 6e 22 0a 09 09 09 22 option>\n"...."
05d0: 54 65 73 74 73 20 66 6f 72 20 77 68 65 74 68 65 Tests for whethe
05e0: 72 20 63 6c 2e 65 78 65 20 73 75 70 70 6f 72 74 r cl.exe support
05f0: 73 20 61 6e 20 6f 70 74 69 6f 6e 5c 6e 22 0a 09 s an option\n"..
0600: 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 20 .."exitcodes: 0
0610: 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c == no, 1 == yes,
0620: 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c 20 2 == error\n",
0630: 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74 argv[0]);...Writ
0640: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64 eFile(GetStdHand
0650: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e le(STD_ERROR_HAN
0660: 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73 DLE), msg, chars
0670: 2c 20 26 64 77 57 72 69 74 74 65 6e 2c 20 4e 55 , &dwWritten, NU
0680: 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 32 3b LL);...return 2;
0690: 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 72 65 74 .. }.. ret
06a0: 75 72 6e 20 43 68 65 63 6b 46 6f 72 43 6f 6d 70 urn CheckForComp
06b0: 69 6c 65 72 46 65 61 74 75 72 65 28 61 72 67 76 ilerFeature(argv
06c0: 5b 32 5d 29 3b 0a 09 63 61 73 65 20 27 6c 27 3a [2]);..case 'l':
06d0: 0a 09 20 20 20 20 69 66 20 28 61 72 67 63 20 21 .. if (argc !
06e0: 3d 20 33 29 20 7b 0a 09 09 63 68 61 72 73 20 3d = 3) {...chars =
06f0: 20 77 73 70 72 69 6e 74 66 28 6d 73 67 2c 20 22 wsprintf(msg, "
0700: 75 73 61 67 65 3a 20 25 73 20 2d 6c 20 3c 6c 69 usage: %s -l <li
0710: 6e 6b 65 72 20 6f 70 74 69 6f 6e 3e 5c 6e 22 0a nker option>\n".
0720: 09 09 09 22 54 65 73 74 73 20 66 6f 72 20 77 68 ..."Tests for wh
0730: 65 74 68 65 72 20 6c 69 6e 6b 2e 65 78 65 20 73 ether link.exe s
0740: 75 70 70 6f 72 74 73 20 61 6e 20 6f 70 74 69 6f upports an optio
0750: 6e 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 n\n"...."exitcod
0760: 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d es: 0 == no, 1 =
0770: 3d 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f = yes, 2 == erro
0780: 72 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a r\n", argv[0]);.
0790: 09 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 ..WriteFile(GetS
07a0: 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 tdHandle(STD_ERR
07b0: 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c OR_HANDLE), msg,
07c0: 20 63 68 61 72 73 2c 20 26 64 77 57 72 69 74 74 chars, &dwWritt
07d0: 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 en, NULL);...ret
07e0: 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 urn 2;.. }..
07f0: 20 20 20 72 65 74 75 72 6e 20 43 68 65 63 6b 46 return CheckF
0800: 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 orLinkerFeature(
0810: 61 72 67 76 5b 32 5d 29 3b 0a 09 63 61 73 65 20 argv[2]);..case
0820: 27 66 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 'f':.. if (ar
0830: 67 63 20 3d 3d 20 32 29 20 7b 0a 09 09 63 68 61 gc == 2) {...cha
0840: 72 73 20 3d 20 77 73 70 72 69 6e 74 66 28 6d 73 rs = wsprintf(ms
0850: 67 2c 20 22 75 73 61 67 65 3a 20 25 73 20 2d 66 g, "usage: %s -f
0860: 20 3c 73 74 72 69 6e 67 3e 20 3c 73 75 62 73 74 <string> <subst
0870: 72 69 6e 67 3e 5c 6e 22 0a 09 09 20 20 20 20 22 ring>\n"... "
0880: 46 69 6e 64 20 61 20 73 75 62 73 74 72 69 6e 67 Find a substring
0890: 20 77 69 74 68 69 6e 20 61 6e 6f 74 68 65 72 5c within another\
08a0: 6e 22 0a 09 09 20 20 20 20 22 65 78 69 74 63 6f n"... "exitco
08b0: 64 65 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 des: 0 == no, 1
08c0: 3d 3d 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 == yes, 2 == err
08d0: 6f 72 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b or\n", argv[0]);
08e0: 0a 09 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 ...WriteFile(Get
08f0: 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 StdHandle(STD_ER
0900: 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 ROR_HANDLE), msg
0910: 2c 20 63 68 61 72 73 2c 20 26 64 77 57 72 69 74 , chars, &dwWrit
0920: 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 ten, NULL);...re
0930: 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 20 65 turn 2;.. } e
0940: 6c 73 65 20 69 66 20 28 61 72 67 63 20 3d 3d 20 lse if (argc ==
0950: 33 29 20 7b 0a 09 09 2f 2a 20 69 66 20 74 68 65 3) {.../* if the
0960: 20 73 74 72 69 6e 67 20 69 73 20 62 6c 61 6e 6b string is blank
0970: 2c 20 74 68 65 72 65 20 69 73 20 6e 6f 20 6d 61 , there is no ma
0980: 74 63 68 20 2a 2f 0a 09 09 72 65 74 75 72 6e 20 tch */...return
0990: 30 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 7b 0;.. } else {
09a0: 0a 09 09 72 65 74 75 72 6e 20 49 73 49 6e 28 61 ...return IsIn(a
09b0: 72 67 76 5b 32 5d 2c 20 61 72 67 76 5b 33 5d 29 rgv[2], argv[3])
09c0: 3b 0a 09 20 20 20 20 7d 0a 09 63 61 73 65 20 27 ;.. }..case '
09d0: 76 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 67 v':.. if (arg
09e0: 63 20 21 3d 20 34 29 20 7b 0a 09 09 63 68 61 72 c != 4) {...char
09f0: 73 20 3d 20 77 73 70 72 69 6e 74 66 28 6d 73 67 s = wsprintf(msg
0a00: 2c 20 22 75 73 61 67 65 3a 20 25 73 20 2d 76 20 , "usage: %s -v
0a10: 3c 74 63 6c 2e 68 3e 20 3c 74 6b 2e 68 3e 5c 6e <tcl.h> <tk.h>\n
0a20: 22 0a 09 09 20 20 20 20 22 53 65 61 72 63 68 20 "... "Search
0a30: 66 6f 72 20 76 65 72 73 69 6f 6e 73 20 66 72 6f for versions fro
0a40: 6d 20 74 68 65 20 74 63 6c 20 61 6e 64 20 74 6b m the tcl and tk
0a50: 20 68 65 61 64 65 72 73 2e 22 2c 0a 09 09 20 20 headers.",...
0a60: 20 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 argv[0]);...Wr
0a70: 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 iteFile(GetStdHa
0a80: 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 ndle(STD_ERROR_H
0a90: 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 ANDLE), msg, cha
0aa0: 72 73 2c 20 26 64 77 57 72 69 74 74 65 6e 2c 20 rs, &dwWritten,
0ab0: 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e 20 NULL);...return
0ac0: 30 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20 72 0;.. }.. r
0ad0: 65 74 75 72 6e 20 47 65 74 56 65 72 73 69 6f 6e eturn GetVersion
0ae0: 46 72 6f 6d 48 65 61 64 65 72 28 61 72 67 76 5b FromHeader(argv[
0af0: 32 5d 2c 20 61 72 67 76 5b 33 5d 29 3b 0a 09 7d 2], argv[3]);..}
0b00: 0a 20 20 20 20 7d 0a 20 20 20 20 63 68 61 72 73 . }. chars
0b10: 20 3d 20 77 73 70 72 69 6e 74 66 28 6d 73 67 2c = wsprintf(msg,
0b20: 20 22 75 73 61 67 65 3a 20 25 73 20 2d 63 7c 2d "usage: %s -c|-
0b30: 6c 7c 2d 66 20 2e 2e 2e 5c 6e 22 0a 09 20 20 20 l|-f ...\n"..
0b40: 20 22 54 68 69 73 20 69 73 20 61 20 6c 69 74 74 "This is a litt
0b50: 6c 65 20 68 65 6c 70 65 72 20 61 70 70 20 74 6f le helper app to
0b60: 20 65 71 75 61 6c 69 7a 65 20 73 68 65 6c 6c 20 equalize shell
0b70: 64 69 66 66 65 72 65 6e 63 65 73 20 62 65 74 77 differences betw
0b80: 65 65 6e 20 57 69 6e 4e 54 20 61 6e 64 5c 6e 22 een WinNT and\n"
0b90: 0a 09 20 20 20 20 22 57 69 6e 39 78 20 61 6e 64 .. "Win9x and
0ba0: 20 67 65 74 20 6e 6d 61 6b 65 2e 65 78 65 20 74 get nmake.exe t
0bb0: 6f 20 61 63 63 6f 6d 70 6c 69 73 68 20 69 74 73 o accomplish its
0bc0: 20 6a 6f 62 2e 5c 6e 22 2c 0a 09 20 20 20 20 61 job.\n",.. a
0bd0: 72 67 76 5b 30 5d 29 3b 0a 20 20 20 20 57 72 69 rgv[0]);. Wri
0be0: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e teFile(GetStdHan
0bf0: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 dle(STD_ERROR_HA
0c00: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 NDLE), msg, char
0c10: 73 2c 20 26 64 77 57 72 69 74 74 65 6e 2c 20 4e s, &dwWritten, N
0c20: 55 4c 4c 29 3b 0a 20 20 20 20 72 65 74 75 72 6e ULL);. return
0c30: 20 32 3b 0a 7d 0a 0a 69 6e 74 0a 43 68 65 63 6b 2;.}..int.Check
0c40: 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65 61 74 75 ForCompilerFeatu
0c50: 72 65 20 28 63 6f 6e 73 74 20 63 68 61 72 20 2a re (const char *
0c60: 6f 70 74 69 6f 6e 29 0a 7b 0a 20 20 20 20 53 54 option).{. ST
0c70: 41 52 54 55 50 49 4e 46 4f 20 73 69 3b 0a 20 20 ARTUPINFO si;.
0c80: 20 20 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d PROCESS_INFORM
0c90: 41 54 49 4f 4e 20 70 69 3b 0a 20 20 20 20 53 45 ATION pi;. SE
0ca0: 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 CURITY_ATTRIBUTE
0cb0: 53 20 73 61 3b 0a 20 20 20 20 44 57 4f 52 44 20 S sa;. DWORD
0cc0: 74 68 72 65 61 64 49 44 3b 0a 20 20 20 20 63 68 threadID;. ch
0cd0: 61 72 20 6d 73 67 5b 33 30 30 5d 3b 0a 20 20 20 ar msg[300];.
0ce0: 20 42 4f 4f 4c 20 6f 6b 3b 0a 20 20 20 20 48 41 BOOL ok;. HA
0cf0: 4e 44 4c 45 20 68 50 72 6f 63 65 73 73 2c 20 68 NDLE hProcess, h
0d00: 2c 20 70 69 70 65 54 68 72 65 61 64 73 5b 32 5d , pipeThreads[2]
0d10: 3b 0a 20 20 20 20 63 68 61 72 20 63 6d 64 6c 69 ;. char cmdli
0d20: 6e 65 5b 31 30 30 5d 3b 0a 0a 20 20 20 20 68 50 ne[100];.. hP
0d30: 72 6f 63 65 73 73 20 3d 20 47 65 74 43 75 72 72 rocess = GetCurr
0d40: 65 6e 74 50 72 6f 63 65 73 73 28 29 3b 0a 0a 20 entProcess();..
0d50: 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 26 70 ZeroMemory(&p
0d60: 69 2c 20 73 69 7a 65 6f 66 28 50 52 4f 43 45 53 i, sizeof(PROCES
0d70: 53 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 29 29 3b S_INFORMATION));
0d80: 0a 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 . ZeroMemory(
0d90: 26 73 69 2c 20 73 69 7a 65 6f 66 28 53 54 41 52 &si, sizeof(STAR
0da0: 54 55 50 49 4e 46 4f 29 29 3b 0a 20 20 20 20 73 TUPINFO));. s
0db0: 69 2e 63 62 20 3d 20 73 69 7a 65 6f 66 28 53 54 i.cb = sizeof(ST
0dc0: 41 52 54 55 50 49 4e 46 4f 29 3b 0a 20 20 20 20 ARTUPINFO);.
0dd0: 73 69 2e 64 77 46 6c 61 67 73 20 20 20 3d 20 53 si.dwFlags = S
0de0: 54 41 52 54 46 5f 55 53 45 53 54 44 48 41 4e 44 TARTF_USESTDHAND
0df0: 4c 45 53 3b 0a 20 20 20 20 73 69 2e 68 53 74 64 LES;. si.hStd
0e00: 49 6e 70 75 74 20 3d 20 49 4e 56 41 4c 49 44 5f Input = INVALID_
0e10: 48 41 4e 44 4c 45 5f 56 41 4c 55 45 3b 0a 0a 20 HANDLE_VALUE;..
0e20: 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 26 73 ZeroMemory(&s
0e30: 61 2c 20 73 69 7a 65 6f 66 28 53 45 43 55 52 49 a, sizeof(SECURI
0e40: 54 59 5f 41 54 54 52 49 42 55 54 45 53 29 29 3b TY_ATTRIBUTES));
0e50: 0a 20 20 20 20 73 61 2e 6e 4c 65 6e 67 74 68 20 . sa.nLength
0e60: 3d 20 73 69 7a 65 6f 66 28 53 45 43 55 52 49 54 = sizeof(SECURIT
0e70: 59 5f 41 54 54 52 49 42 55 54 45 53 29 3b 0a 20 Y_ATTRIBUTES);.
0e80: 20 20 20 73 61 2e 6c 70 53 65 63 75 72 69 74 79 sa.lpSecurity
0e90: 44 65 73 63 72 69 70 74 6f 72 20 3d 20 4e 55 4c Descriptor = NUL
0ea0: 4c 3b 0a 20 20 20 20 73 61 2e 62 49 6e 68 65 72 L;. sa.bInher
0eb0: 69 74 48 61 6e 64 6c 65 20 3d 20 46 41 4c 53 45 itHandle = FALSE
0ec0: 3b 0a 0a 20 20 20 20 2f 2a 20 63 72 65 61 74 65 ;.. /* create
0ed0: 20 61 20 6e 6f 6e 2d 69 6e 68 65 72 69 74 69 62 a non-inheritib
0ee0: 6c 65 20 70 69 70 65 2e 20 2a 2f 0a 20 20 20 20 le pipe. */.
0ef0: 43 72 65 61 74 65 50 69 70 65 28 26 4f 75 74 2e CreatePipe(&Out.
0f00: 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 pipe, &h, &sa, 0
0f10: 29 3b 0a 0a 20 20 20 20 2f 2a 20 64 75 70 65 20 );.. /* dupe
0f20: 74 68 65 20 77 72 69 74 65 20 73 69 64 65 2c 20 the write side,
0f30: 6d 61 6b 65 20 69 74 20 69 6e 68 65 72 69 74 69 make it inheriti
0f40: 62 6c 65 2c 20 61 6e 64 20 63 6c 6f 73 65 20 74 ble, and close t
0f50: 68 65 20 6f 72 69 67 69 6e 61 6c 2e 20 2a 2f 0a he original. */.
0f60: 20 20 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e DuplicateHan
0f70: 64 6c 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c dle(hProcess, h,
0f80: 20 68 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 hProcess, &si.h
0f90: 53 74 64 4f 75 74 70 75 74 2c 20 0a 09 20 20 20 StdOutput, ..
0fa0: 20 30 2c 20 54 52 55 45 2c 20 44 55 50 4c 49 43 0, TRUE, DUPLIC
0fb0: 41 54 45 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 ATE_SAME_ACCESS
0fc0: 7c 20 44 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 | DUPLICATE_CLOS
0fd0: 45 5f 53 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 E_SOURCE);..
0fe0: 2f 2a 20 53 61 6d 65 20 61 73 20 61 62 6f 76 65 /* Same as above
0ff0: 2c 20 62 75 74 20 66 6f 72 20 74 68 65 20 65 72 , but for the er
1000: 72 6f 72 20 73 69 64 65 2e 20 2a 2f 0a 20 20 20 ror side. */.
1010: 20 43 72 65 61 74 65 50 69 70 65 28 26 45 72 72 CreatePipe(&Err
1020: 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 .pipe, &h, &sa,
1030: 30 29 3b 0a 20 20 20 20 44 75 70 6c 69 63 61 74 0);. Duplicat
1040: 65 48 61 6e 64 6c 65 28 68 50 72 6f 63 65 73 73 eHandle(hProcess
1050: 2c 20 68 2c 20 68 50 72 6f 63 65 73 73 2c 20 26 , h, hProcess, &
1060: 73 69 2e 68 53 74 64 45 72 72 6f 72 2c 20 0a 09 si.hStdError, ..
1070: 20 20 20 20 30 2c 20 54 52 55 45 2c 20 44 55 50 0, TRUE, DUP
1080: 4c 49 43 41 54 45 5f 53 41 4d 45 5f 41 43 43 45 LICATE_SAME_ACCE
1090: 53 53 20 7c 20 44 55 50 4c 49 43 41 54 45 5f 43 SS | DUPLICATE_C
10a0: 4c 4f 53 45 5f 53 4f 55 52 43 45 29 3b 0a 0a 20 LOSE_SOURCE);..
10b0: 20 20 20 2f 2a 20 62 61 73 65 20 63 6f 6d 6d 61 /* base comma
10c0: 6e 64 20 6c 69 6e 65 20 2a 2f 0a 20 20 20 20 73 nd line */. s
10d0: 74 72 63 70 79 28 63 6d 64 6c 69 6e 65 2c 20 22 trcpy(cmdline, "
10e0: 63 6c 2e 65 78 65 20 2d 6e 6f 6c 6f 67 6f 20 2d cl.exe -nologo -
10f0: 63 20 2d 54 43 20 2d 46 64 74 65 6d 70 20 22 29 c -TC -Fdtemp ")
1100: 3b 0a 20 20 20 20 2f 2a 20 61 70 70 65 6e 64 20 ;. /* append
1110: 6f 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 our option for t
1120: 65 73 74 69 6e 67 20 2a 2f 0a 20 20 20 20 73 74 esting */. st
1130: 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 6f 70 rcat(cmdline, op
1140: 74 69 6f 6e 29 3b 0a 20 20 20 20 2f 2a 20 66 69 tion);. /* fi
1150: 6c 65 6e 61 6d 65 20 74 6f 20 63 6f 6d 70 69 6c lename to compil
1160: 65 2c 20 77 68 69 63 68 20 65 78 69 73 74 73 2c e, which exists,
1170: 20 62 75 74 20 69 73 20 6e 6f 74 68 69 6e 67 20 but is nothing
1180: 61 6e 64 20 65 6d 70 74 79 2e 20 2a 2f 0a 20 20 and empty. */.
1190: 20 20 73 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 strcat(cmdline
11a0: 2c 20 22 20 6e 75 6c 22 29 3b 0a 0a 20 20 20 20 , " nul");..
11b0: 6f 6b 20 3d 20 43 72 65 61 74 65 50 72 6f 63 65 ok = CreateProce
11c0: 73 73 28 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 ss(.. NULL,.
11d0: 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 6e 61 6d /* Module nam
11e0: 65 2e 20 2a 2f 0a 09 20 20 20 20 63 6d 64 6c 69 e. */.. cmdli
11f0: 6e 65 2c 09 20 20 20 20 2f 2a 20 43 6f 6d 6d 61 ne,. /* Comma
1200: 6e 64 20 6c 69 6e 65 2e 20 2a 2f 0a 09 20 20 20 nd line. */..
1210: 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 50 72 NULL,. /* Pr
1220: 6f 63 65 73 73 20 68 61 6e 64 6c 65 20 6e 6f 74 ocess handle not
1230: 20 69 6e 68 65 72 69 74 61 62 6c 65 2e 20 2a 2f inheritable. */
1240: 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 .. NULL,.
1250: 2f 2a 20 54 68 72 65 61 64 20 68 61 6e 64 6c 65 /* Thread handle
1260: 20 6e 6f 74 20 69 6e 68 65 72 69 74 61 62 6c 65 not inheritable
1270: 2e 20 2a 2f 0a 09 20 20 20 20 54 52 55 45 2c 09 . */.. TRUE,.
1280: 20 20 20 20 2f 2a 20 79 65 73 2c 20 69 6e 68 65 /* yes, inhe
1290: 72 69 74 20 68 61 6e 64 6c 65 73 2e 20 2a 2f 0a rit handles. */.
12a0: 09 20 20 20 20 44 45 54 41 43 48 45 44 5f 50 52 . DETACHED_PR
12b0: 4f 43 45 53 53 2c 20 2f 2a 20 4e 6f 20 63 6f 6e OCESS, /* No con
12c0: 73 6f 6c 65 20 66 6f 72 20 79 6f 75 2e 20 2a 2f sole for you. */
12d0: 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 .. NULL,.
12e0: 2f 2a 20 55 73 65 20 70 61 72 65 6e 74 27 73 20 /* Use parent's
12f0: 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 62 6c 6f 63 environment bloc
1300: 6b 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c k. */.. NULL,
1310: 09 20 20 20 20 2f 2a 20 55 73 65 20 70 61 72 65 . /* Use pare
1320: 6e 74 27 73 20 73 74 61 72 74 69 6e 67 20 64 69 nt's starting di
1330: 72 65 63 74 6f 72 79 2e 20 2a 2f 0a 09 20 20 20 rectory. */..
1340: 20 26 73 69 2c 09 20 20 20 20 2f 2a 20 50 6f 69 &si,. /* Poi
1350: 6e 74 65 72 20 74 6f 20 53 54 41 52 54 55 50 49 nter to STARTUPI
1360: 4e 46 4f 20 73 74 72 75 63 74 75 72 65 2e 20 2a NFO structure. *
1370: 2f 0a 09 20 20 20 20 26 70 69 29 3b 09 20 20 20 /.. &pi);.
1380: 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20 50 /* Pointer to P
1390: 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54 49 ROCESS_INFORMATI
13a0: 4f 4e 20 73 74 72 75 63 74 75 72 65 2e 20 2a 2f ON structure. */
13b0: 0a 0a 20 20 20 20 69 66 20 28 21 6f 6b 29 20 7b .. if (!ok) {
13c0: 0a 09 44 57 4f 52 44 20 65 72 72 20 3d 20 47 65 ..DWORD err = Ge
13d0: 74 4c 61 73 74 45 72 72 6f 72 28 29 3b 0a 09 69 tLastError();..i
13e0: 6e 74 20 63 68 61 72 73 20 3d 20 77 73 70 72 69 nt chars = wspri
13f0: 6e 74 66 28 6d 73 67 2c 20 22 54 72 69 65 64 20 ntf(msg, "Tried
1400: 74 6f 20 6c 61 75 6e 63 68 3a 20 5c 22 25 73 5c to launch: \"%s\
1410: 22 2c 20 62 75 74 20 67 6f 74 20 65 72 72 6f 72 ", but got error
1420: 20 5b 25 75 5d 3a 20 22 2c 20 63 6d 64 6c 69 6e [%u]: ", cmdlin
1430: 65 2c 20 65 72 72 29 3b 0a 0a 09 46 6f 72 6d 61 e, err);...Forma
1440: 74 4d 65 73 73 61 67 65 28 46 4f 52 4d 41 54 5f tMessage(FORMAT_
1450: 4d 45 53 53 41 47 45 5f 46 52 4f 4d 5f 53 59 53 MESSAGE_FROM_SYS
1460: 54 45 4d 20 7c 20 46 4f 52 4d 41 54 5f 4d 45 53 TEM | FORMAT_MES
1470: 53 41 47 45 5f 49 47 4e 4f 52 45 5f 49 4e 53 45 SAGE_IGNORE_INSE
1480: 52 54 53 20 7c 0a 09 09 46 4f 52 4d 41 54 5f 4d RTS |...FORMAT_M
1490: 45 53 53 41 47 45 5f 4d 41 58 5f 57 49 44 54 48 ESSAGE_MAX_WIDTH
14a0: 5f 4d 41 53 4b 2c 20 30 4c 2c 20 65 72 72 2c 20 _MASK, 0L, err,
14b0: 30 2c 20 28 4c 50 56 4f 49 44 29 20 26 6d 73 67 0, (LPVOID) &msg
14c0: 5b 63 68 61 72 73 5d 2c 0a 09 09 28 33 30 30 2d [chars],...(300-
14d0: 63 68 61 72 73 29 2c 20 30 29 3b 0a 09 57 72 69 chars), 0);..Wri
14e0: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e teFile(GetStdHan
14f0: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 dle(STD_ERROR_HA
1500: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 73 74 72 6c NDLE), msg, strl
1510: 65 6e 28 6d 73 67 29 2c 20 26 65 72 72 2c 20 4e en(msg), &err, N
1520: 55 4c 4c 29 3b 0a 09 72 65 74 75 72 6e 20 32 3b ULL);..return 2;
1530: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 63 . }.. /* c
1540: 6c 6f 73 65 20 6f 75 72 20 72 65 66 65 72 65 6e lose our referen
1550: 63 65 73 20 74 6f 20 74 68 65 20 77 72 69 74 65 ces to the write
1560: 20 68 61 6e 64 6c 65 73 20 74 68 61 74 20 68 61 handles that ha
1570: 76 65 20 6e 6f 77 20 62 65 65 6e 20 69 6e 68 65 ve now been inhe
1580: 72 69 74 65 64 2e 20 2a 2f 0a 20 20 20 20 43 6c rited. */. Cl
1590: 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 53 74 oseHandle(si.hSt
15a0: 64 4f 75 74 70 75 74 29 3b 0a 20 20 20 20 43 6c dOutput);. Cl
15b0: 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e 68 53 74 oseHandle(si.hSt
15c0: 64 45 72 72 6f 72 29 3b 0a 0a 20 20 20 20 57 61 dError);.. Wa
15d0: 69 74 46 6f 72 49 6e 70 75 74 49 64 6c 65 28 70 itForInputIdle(p
15e0: 69 2e 68 50 72 6f 63 65 73 73 2c 20 35 30 30 30 i.hProcess, 5000
15f0: 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 );. CloseHand
1600: 6c 65 28 70 69 2e 68 54 68 72 65 61 64 29 3b 0a le(pi.hThread);.
1610: 0a 20 20 20 20 2f 2a 20 73 74 61 72 74 20 74 68 . /* start th
1620: 65 20 70 69 70 65 20 72 65 61 64 65 72 20 74 68 e pipe reader th
1630: 72 65 61 64 73 2e 20 2a 2f 0a 20 20 20 20 70 69 reads. */. pi
1640: 70 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20 43 peThreads[0] = C
1650: 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c reateThread(NULL
1660: 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 , 0, ReadFromPip
1670: 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68 72 e, &Out, 0, &thr
1680: 65 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70 65 eadID);. pipe
1690: 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72 65 Threads[1] = Cre
16a0: 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c 20 ateThread(NULL,
16b0: 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65 2c 0, ReadFromPipe,
16c0: 20 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65 61 &Err, 0, &threa
16d0: 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 20 62 6c dID);.. /* bl
16e0: 6f 63 6b 20 77 61 69 74 69 6e 67 20 66 6f 72 20 ock waiting for
16f0: 74 68 65 20 70 72 6f 63 65 73 73 20 74 6f 20 65 the process to e
1700: 6e 64 2e 20 2a 2f 0a 20 20 20 20 57 61 69 74 46 nd. */. WaitF
1710: 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 orSingleObject(p
1720: 69 2e 68 50 72 6f 63 65 73 73 2c 20 49 4e 46 49 i.hProcess, INFI
1730: 4e 49 54 45 29 3b 0a 20 20 20 20 43 6c 6f 73 65 NITE);. Close
1740: 48 61 6e 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 Handle(pi.hProce
1750: 73 73 29 3b 0a 0a 20 20 20 20 2f 2a 20 63 6c 65 ss);.. /* cle
1760: 61 6e 20 75 70 20 74 65 6d 70 6f 72 61 72 79 20 an up temporary
1770: 66 69 6c 65 73 20 62 65 66 6f 72 65 20 72 65 74 files before ret
1780: 75 72 6e 69 6e 67 20 2a 2f 0a 20 20 20 20 44 65 urning */. De
1790: 6c 65 74 65 46 69 6c 65 28 22 74 65 6d 70 2e 69 leteFile("temp.i
17a0: 64 62 22 29 3b 0a 20 20 20 20 44 65 6c 65 74 65 db");. Delete
17b0: 46 69 6c 65 28 22 74 65 6d 70 2e 70 64 62 22 29 File("temp.pdb")
17c0: 3b 0a 0a 20 20 20 20 2f 2a 20 77 61 69 74 20 66 ;.. /* wait f
17d0: 6f 72 20 6f 75 72 20 70 69 70 65 20 74 6f 20 67 or our pipe to g
17e0: 65 74 20 64 6f 6e 65 20 72 65 61 64 69 6e 67 2c et done reading,
17f0: 20 73 68 6f 75 6c 64 20 69 74 20 62 65 20 61 20 should it be a
1800: 6c 69 74 74 6c 65 20 73 6c 6f 77 2e 20 2a 2f 0a little slow. */.
1810: 20 20 20 20 57 61 69 74 46 6f 72 4d 75 6c 74 69 WaitForMulti
1820: 70 6c 65 4f 62 6a 65 63 74 73 28 32 2c 20 70 69 pleObjects(2, pi
1830: 70 65 54 68 72 65 61 64 73 2c 20 54 52 55 45 2c peThreads, TRUE,
1840: 20 35 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 500);. Close
1850: 48 61 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 Handle(pipeThrea
1860: 64 73 5b 30 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 ds[0]);. Clos
1870: 65 48 61 6e 64 6c 65 28 70 69 70 65 54 68 72 65 eHandle(pipeThre
1880: 61 64 73 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a ads[1]);.. /*
1890: 20 6c 6f 6f 6b 20 66 6f 72 20 74 68 65 20 63 6f look for the co
18a0: 6d 6d 61 6e 64 6c 69 6e 65 20 77 61 72 6e 69 6e mmandline warnin
18b0: 67 20 63 6f 64 65 20 69 6e 20 62 6f 74 68 20 73 g code in both s
18c0: 74 72 65 61 6d 73 2e 20 2a 2f 0a 20 20 20 20 72 treams. */. r
18d0: 65 74 75 72 6e 20 21 28 73 74 72 73 74 72 28 4f eturn !(strstr(O
18e0: 75 74 2e 62 75 66 66 65 72 2c 20 22 44 34 30 30 ut.buffer, "D400
18f0: 32 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 20 73 2") != NULL || s
1900: 74 72 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 trstr(Err.buffer
1910: 2c 20 22 44 34 30 30 32 22 29 20 21 3d 20 4e 55 , "D4002") != NU
1920: 4c 4c 29 3b 0a 7d 0a 0a 69 6e 74 0a 43 68 65 63 LL);.}..int.Chec
1930: 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72 kForLinkerFeatur
1940: 65 20 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6f e (const char *o
1950: 70 74 69 6f 6e 29 0a 7b 0a 20 20 20 20 53 54 41 ption).{. STA
1960: 52 54 55 50 49 4e 46 4f 20 73 69 3b 0a 20 20 20 RTUPINFO si;.
1970: 20 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 PROCESS_INFORMA
1980: 54 49 4f 4e 20 70 69 3b 0a 20 20 20 20 53 45 43 TION pi;. SEC
1990: 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53 URITY_ATTRIBUTES
19a0: 20 73 61 3b 0a 20 20 20 20 44 57 4f 52 44 20 74 sa;. DWORD t
19b0: 68 72 65 61 64 49 44 3b 0a 20 20 20 20 63 68 61 hreadID;. cha
19c0: 72 20 6d 73 67 5b 33 30 30 5d 3b 0a 20 20 20 20 r msg[300];.
19d0: 42 4f 4f 4c 20 6f 6b 3b 0a 20 20 20 20 48 41 4e BOOL ok;. HAN
19e0: 44 4c 45 20 68 50 72 6f 63 65 73 73 2c 20 68 2c DLE hProcess, h,
19f0: 20 70 69 70 65 54 68 72 65 61 64 73 5b 32 5d 3b pipeThreads[2];
1a00: 0a 20 20 20 20 63 68 61 72 20 63 6d 64 6c 69 6e . char cmdlin
1a10: 65 5b 31 30 30 5d 3b 0a 0a 20 20 20 20 68 50 72 e[100];.. hPr
1a20: 6f 63 65 73 73 20 3d 20 47 65 74 43 75 72 72 65 ocess = GetCurre
1a30: 6e 74 50 72 6f 63 65 73 73 28 29 3b 0a 0a 20 20 ntProcess();..
1a40: 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 26 70 69 ZeroMemory(&pi
1a50: 2c 20 73 69 7a 65 6f 66 28 50 52 4f 43 45 53 53 , sizeof(PROCESS
1a60: 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 29 29 3b 0a _INFORMATION));.
1a70: 20 20 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 26 ZeroMemory(&
1a80: 73 69 2c 20 73 69 7a 65 6f 66 28 53 54 41 52 54 si, sizeof(START
1a90: 55 50 49 4e 46 4f 29 29 3b 0a 20 20 20 20 73 69 UPINFO));. si
1aa0: 2e 63 62 20 3d 20 73 69 7a 65 6f 66 28 53 54 41 .cb = sizeof(STA
1ab0: 52 54 55 50 49 4e 46 4f 29 3b 0a 20 20 20 20 73 RTUPINFO);. s
1ac0: 69 2e 64 77 46 6c 61 67 73 20 20 20 3d 20 53 54 i.dwFlags = ST
1ad0: 41 52 54 46 5f 55 53 45 53 54 44 48 41 4e 44 4c ARTF_USESTDHANDL
1ae0: 45 53 3b 0a 20 20 20 20 73 69 2e 68 53 74 64 49 ES;. si.hStdI
1af0: 6e 70 75 74 20 3d 20 49 4e 56 41 4c 49 44 5f 48 nput = INVALID_H
1b00: 41 4e 44 4c 45 5f 56 41 4c 55 45 3b 0a 0a 20 20 ANDLE_VALUE;..
1b10: 20 20 5a 65 72 6f 4d 65 6d 6f 72 79 28 26 73 61 ZeroMemory(&sa
1b20: 2c 20 73 69 7a 65 6f 66 28 53 45 43 55 52 49 54 , sizeof(SECURIT
1b30: 59 5f 41 54 54 52 49 42 55 54 45 53 29 29 3b 0a Y_ATTRIBUTES));.
1b40: 20 20 20 20 73 61 2e 6e 4c 65 6e 67 74 68 20 3d sa.nLength =
1b50: 20 73 69 7a 65 6f 66 28 53 45 43 55 52 49 54 59 sizeof(SECURITY
1b60: 5f 41 54 54 52 49 42 55 54 45 53 29 3b 0a 20 20 _ATTRIBUTES);.
1b70: 20 20 73 61 2e 6c 70 53 65 63 75 72 69 74 79 44 sa.lpSecurityD
1b80: 65 73 63 72 69 70 74 6f 72 20 3d 20 4e 55 4c 4c escriptor = NULL
1b90: 3b 0a 20 20 20 20 73 61 2e 62 49 6e 68 65 72 69 ;. sa.bInheri
1ba0: 74 48 61 6e 64 6c 65 20 3d 20 54 52 55 45 3b 0a tHandle = TRUE;.
1bb0: 0a 20 20 20 20 2f 2a 20 63 72 65 61 74 65 20 61 . /* create a
1bc0: 20 6e 6f 6e 2d 69 6e 68 65 72 69 74 69 62 6c 65 non-inheritible
1bd0: 20 70 69 70 65 2e 20 2a 2f 0a 20 20 20 20 43 72 pipe. */. Cr
1be0: 65 61 74 65 50 69 70 65 28 26 4f 75 74 2e 70 69 eatePipe(&Out.pi
1bf0: 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 3b pe, &h, &sa, 0);
1c00: 0a 0a 20 20 20 20 2f 2a 20 64 75 70 65 20 74 68 .. /* dupe th
1c10: 65 20 77 72 69 74 65 20 73 69 64 65 2c 20 6d 61 e write side, ma
1c20: 6b 65 20 69 74 20 69 6e 68 65 72 69 74 69 62 6c ke it inheritibl
1c30: 65 2c 20 61 6e 64 20 63 6c 6f 73 65 20 74 68 65 e, and close the
1c40: 20 6f 72 69 67 69 6e 61 6c 2e 20 2a 2f 0a 20 20 original. */.
1c50: 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c DuplicateHandl
1c60: 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68 e(hProcess, h, h
1c70: 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74 Process, &si.hSt
1c80: 64 4f 75 74 70 75 74 2c 20 0a 09 20 20 20 20 30 dOutput, .. 0
1c90: 2c 20 54 52 55 45 2c 20 44 55 50 4c 49 43 41 54 , TRUE, DUPLICAT
1ca0: 45 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 E_SAME_ACCESS |
1cb0: 44 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f DUPLICATE_CLOSE_
1cc0: 53 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a SOURCE);.. /*
1cd0: 20 53 61 6d 65 20 61 73 20 61 62 6f 76 65 2c 20 Same as above,
1ce0: 62 75 74 20 66 6f 72 20 74 68 65 20 65 72 72 6f but for the erro
1cf0: 72 20 73 69 64 65 2e 20 2a 2f 0a 20 20 20 20 43 r side. */. C
1d00: 72 65 61 74 65 50 69 70 65 28 26 45 72 72 2e 70 reatePipe(&Err.p
1d10: 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20 30 29 ipe, &h, &sa, 0)
1d20: 3b 0a 20 20 20 20 44 75 70 6c 69 63 61 74 65 48 ;. DuplicateH
1d30: 61 6e 64 6c 65 28 68 50 72 6f 63 65 73 73 2c 20 andle(hProcess,
1d40: 68 2c 20 68 50 72 6f 63 65 73 73 2c 20 26 73 69 h, hProcess, &si
1d50: 2e 68 53 74 64 45 72 72 6f 72 2c 20 0a 09 20 20 .hStdError, ..
1d60: 20 20 30 2c 20 54 52 55 45 2c 20 44 55 50 4c 49 0, TRUE, DUPLI
1d70: 43 41 54 45 5f 53 41 4d 45 5f 41 43 43 45 53 53 CATE_SAME_ACCESS
1d80: 20 7c 20 44 55 50 4c 49 43 41 54 45 5f 43 4c 4f | DUPLICATE_CLO
1d90: 53 45 5f 53 4f 55 52 43 45 29 3b 0a 0a 20 20 20 SE_SOURCE);..
1da0: 20 2f 2a 20 62 61 73 65 20 63 6f 6d 6d 61 6e 64 /* base command
1db0: 20 6c 69 6e 65 20 2a 2f 0a 20 20 20 20 73 74 72 line */. str
1dc0: 63 70 79 28 63 6d 64 6c 69 6e 65 2c 20 22 6c 69 cpy(cmdline, "li
1dd0: 6e 6b 2e 65 78 65 20 2d 6e 6f 6c 6f 67 6f 20 22 nk.exe -nologo "
1de0: 29 3b 0a 20 20 20 20 2f 2a 20 61 70 70 65 6e 64 );. /* append
1df0: 20 6f 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 our option for
1e00: 74 65 73 74 69 6e 67 20 2a 2f 0a 20 20 20 20 73 testing */. s
1e10: 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 6f trcat(cmdline, o
1e20: 70 74 69 6f 6e 29 3b 0a 20 20 20 20 2f 2a 20 66 ption);. /* f
1e30: 69 6c 65 6e 61 6d 65 20 74 6f 20 63 6f 6d 70 69 ilename to compi
1e40: 6c 65 2c 20 77 68 69 63 68 20 65 78 69 73 74 73 le, which exists
1e50: 2c 20 62 75 74 20 69 73 20 6e 6f 74 68 69 6e 67 , but is nothing
1e60: 20 61 6e 64 20 65 6d 70 74 79 2e 20 2a 2f 0a 2f and empty. */./
1e70: 2f 20 20 20 20 73 74 72 63 61 74 28 63 6d 64 6c / strcat(cmdl
1e80: 69 6e 65 2c 20 22 20 6e 75 6c 22 29 3b 0a 0a 20 ine, " nul");..
1e90: 20 20 20 6f 6b 20 3d 20 43 72 65 61 74 65 50 72 ok = CreatePr
1ea0: 6f 63 65 73 73 28 0a 09 20 20 20 20 4e 55 4c 4c ocess(.. NULL
1eb0: 2c 09 20 20 20 20 2f 2a 20 4d 6f 64 75 6c 65 20 ,. /* Module
1ec0: 6e 61 6d 65 2e 20 2a 2f 0a 09 20 20 20 20 63 6d name. */.. cm
1ed0: 64 6c 69 6e 65 2c 09 20 20 20 20 2f 2a 20 43 6f dline,. /* Co
1ee0: 6d 6d 61 6e 64 20 6c 69 6e 65 2e 20 2a 2f 0a 09 mmand line. */..
1ef0: 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a NULL,. /*
1f00: 20 50 72 6f 63 65 73 73 20 68 61 6e 64 6c 65 20 Process handle
1f10: 6e 6f 74 20 69 6e 68 65 72 69 74 61 62 6c 65 2e not inheritable.
1f20: 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 */.. NULL,.
1f30: 20 20 20 2f 2a 20 54 68 72 65 61 64 20 68 61 6e /* Thread han
1f40: 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 74 61 dle not inherita
1f50: 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 54 52 55 ble. */.. TRU
1f60: 45 2c 09 20 20 20 20 2f 2a 20 79 65 73 2c 20 69 E,. /* yes, i
1f70: 6e 68 65 72 69 74 20 68 61 6e 64 6c 65 73 2e 20 nherit handles.
1f80: 2a 2f 0a 09 20 20 20 20 44 45 54 41 43 48 45 44 */.. DETACHED
1f90: 5f 50 52 4f 43 45 53 53 2c 20 2f 2a 20 4e 6f 20 _PROCESS, /* No
1fa0: 63 6f 6e 73 6f 6c 65 20 66 6f 72 20 79 6f 75 2e console for you.
1fb0: 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20 */.. NULL,.
1fc0: 20 20 20 2f 2a 20 55 73 65 20 70 61 72 65 6e 74 /* Use parent
1fd0: 27 73 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 20 62 's environment b
1fe0: 6c 6f 63 6b 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 lock. */.. NU
1ff0: 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 70 LL,. /* Use p
2000: 61 72 65 6e 74 27 73 20 73 74 61 72 74 69 6e 67 arent's starting
2010: 20 64 69 72 65 63 74 6f 72 79 2e 20 2a 2f 0a 09 directory. */..
2020: 20 20 20 20 26 73 69 2c 09 20 20 20 20 2f 2a 20 &si,. /*
2030: 50 6f 69 6e 74 65 72 20 74 6f 20 53 54 41 52 54 Pointer to START
2040: 55 50 49 4e 46 4f 20 73 74 72 75 63 74 75 72 65 UPINFO structure
2050: 2e 20 2a 2f 0a 09 20 20 20 20 26 70 69 29 3b 09 . */.. &pi);.
2060: 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 /* Pointer t
2070: 6f 20 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d o PROCESS_INFORM
2080: 41 54 49 4f 4e 20 73 74 72 75 63 74 75 72 65 2e ATION structure.
2090: 20 2a 2f 0a 0a 20 20 20 20 69 66 20 28 21 6f 6b */.. if (!ok
20a0: 29 20 7b 0a 09 44 57 4f 52 44 20 65 72 72 20 3d ) {..DWORD err =
20b0: 20 47 65 74 4c 61 73 74 45 72 72 6f 72 28 29 3b GetLastError();
20c0: 0a 09 69 6e 74 20 63 68 61 72 73 20 3d 20 77 73 ..int chars = ws
20d0: 70 72 69 6e 74 66 28 6d 73 67 2c 20 22 54 72 69 printf(msg, "Tri
20e0: 65 64 20 74 6f 20 6c 61 75 6e 63 68 3a 20 5c 22 ed to launch: \"
20f0: 25 73 5c 22 2c 20 62 75 74 20 67 6f 74 20 65 72 %s\", but got er
2100: 72 6f 72 20 5b 25 75 5d 3a 20 22 2c 20 63 6d 64 ror [%u]: ", cmd
2110: 6c 69 6e 65 2c 20 65 72 72 29 3b 0a 0a 09 46 6f line, err);...Fo
2120: 72 6d 61 74 4d 65 73 73 61 67 65 28 46 4f 52 4d rmatMessage(FORM
2130: 41 54 5f 4d 45 53 53 41 47 45 5f 46 52 4f 4d 5f AT_MESSAGE_FROM_
2140: 53 59 53 54 45 4d 20 7c 20 46 4f 52 4d 41 54 5f SYSTEM | FORMAT_
2150: 4d 45 53 53 41 47 45 5f 49 47 4e 4f 52 45 5f 49 MESSAGE_IGNORE_I
2160: 4e 53 45 52 54 53 20 7c 0a 09 09 46 4f 52 4d 41 NSERTS |...FORMA
2170: 54 5f 4d 45 53 53 41 47 45 5f 4d 41 58 5f 57 49 T_MESSAGE_MAX_WI
2180: 44 54 48 5f 4d 41 53 4b 2c 20 30 4c 2c 20 65 72 DTH_MASK, 0L, er
2190: 72 2c 20 30 2c 20 28 4c 50 56 4f 49 44 29 20 26 r, 0, (LPVOID) &
21a0: 6d 73 67 5b 63 68 61 72 73 5d 2c 0a 09 09 28 33 msg[chars],...(3
21b0: 30 30 2d 63 68 61 72 73 29 2c 20 30 29 3b 0a 09 00-chars), 0);..
21c0: 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 WriteFile(GetStd
21d0: 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 Handle(STD_ERROR
21e0: 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 73 _HANDLE), msg, s
21f0: 74 72 6c 65 6e 28 6d 73 67 29 2c 20 26 65 72 72 trlen(msg), &err
2200: 2c 20 4e 55 4c 4c 29 3b 0a 09 72 65 74 75 72 6e , NULL);..return
2210: 20 32 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2;. }.. /
2220: 2a 20 63 6c 6f 73 65 20 6f 75 72 20 72 65 66 65 * close our refe
2230: 72 65 6e 63 65 73 20 74 6f 20 74 68 65 20 77 72 rences to the wr
2240: 69 74 65 20 68 61 6e 64 6c 65 73 20 74 68 61 74 ite handles that
2250: 20 68 61 76 65 20 6e 6f 77 20 62 65 65 6e 20 69 have now been i
2260: 6e 68 65 72 69 74 65 64 2e 20 2a 2f 0a 20 20 20 nherited. */.
2270: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e CloseHandle(si.
2280: 68 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20 20 hStdOutput);.
2290: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69 2e CloseHandle(si.
22a0: 68 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20 20 hStdError);..
22b0: 20 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64 6c WaitForInputIdl
22c0: 65 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 35 e(pi.hProcess, 5
22d0: 30 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 000);. CloseH
22e0: 61 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61 64 andle(pi.hThread
22f0: 29 3b 0a 0a 20 20 20 20 2f 2a 20 73 74 61 72 74 );.. /* start
2300: 20 74 68 65 20 70 69 70 65 20 72 65 61 64 65 72 the pipe reader
2310: 20 74 68 72 65 61 64 73 2e 20 2a 2f 0a 20 20 20 threads. */.
2320: 20 70 69 70 65 54 68 72 65 61 64 73 5b 30 5d 20 pipeThreads[0]
2330: 3d 20 43 72 65 61 74 65 54 68 72 65 61 64 28 4e = CreateThread(N
2340: 55 4c 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d ULL, 0, ReadFrom
2350: 50 69 70 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 Pipe, &Out, 0, &
2360: 74 68 72 65 61 64 49 44 29 3b 0a 20 20 20 20 70 threadID);. p
2370: 69 70 65 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 ipeThreads[1] =
2380: 43 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c CreateThread(NUL
2390: 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 L, 0, ReadFromPi
23a0: 70 65 2c 20 26 45 72 72 2c 20 30 2c 20 26 74 68 pe, &Err, 0, &th
23b0: 72 65 61 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a readID);.. /*
23c0: 20 62 6c 6f 63 6b 20 77 61 69 74 69 6e 67 20 66 block waiting f
23d0: 6f 72 20 74 68 65 20 70 72 6f 63 65 73 73 20 74 or the process t
23e0: 6f 20 65 6e 64 2e 20 2a 2f 0a 20 20 20 20 57 61 o end. */. Wa
23f0: 69 74 46 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 63 itForSingleObjec
2400: 74 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 49 t(pi.hProcess, I
2410: 4e 46 49 4e 49 54 45 29 3b 0a 20 20 20 20 43 6c NFINITE);. Cl
2420: 6f 73 65 48 61 6e 64 6c 65 28 70 69 2e 68 50 72 oseHandle(pi.hPr
2430: 6f 63 65 73 73 29 3b 0a 0a 20 20 20 20 2f 2a 20 ocess);.. /*
2440: 77 61 69 74 20 66 6f 72 20 6f 75 72 20 70 69 70 wait for our pip
2450: 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20 72 65 e to get done re
2460: 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20 69 74 ading, should it
2470: 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73 6c 6f be a little slo
2480: 77 2e 20 2a 2f 0a 20 20 20 20 57 61 69 74 46 6f w. */. WaitFo
2490: 72 4d 75 6c 74 69 70 6c 65 4f 62 6a 65 63 74 73 rMultipleObjects
24a0: 28 32 2c 20 70 69 70 65 54 68 72 65 61 64 73 2c (2, pipeThreads,
24b0: 20 54 52 55 45 2c 20 35 30 30 29 3b 0a 20 20 20 TRUE, 500);.
24c0: 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 70 CloseHandle(pip
24d0: 65 54 68 72 65 61 64 73 5b 30 5d 29 3b 0a 20 20 eThreads[0]);.
24e0: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 70 69 CloseHandle(pi
24f0: 70 65 54 68 72 65 61 64 73 5b 31 5d 29 3b 0a 0a peThreads[1]);..
2500: 20 20 20 20 2f 2a 20 6c 6f 6f 6b 20 66 6f 72 20 /* look for
2510: 74 68 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 the commandline
2520: 77 61 72 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 warning code in
2530: 74 68 65 20 73 74 64 65 72 72 20 73 74 72 65 61 the stderr strea
2540: 6d 2e 20 2a 2f 0a 20 20 20 20 72 65 74 75 72 6e m. */. return
2550: 20 21 28 73 74 72 73 74 72 28 4f 75 74 2e 62 75 !(strstr(Out.bu
2560: 66 66 65 72 2c 20 22 4c 4e 4b 31 31 31 37 22 29 ffer, "LNK1117")
2570: 20 21 3d 20 4e 55 4c 4c 20 7c 7c 20 73 74 72 73 != NULL || strs
2580: 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20 22 tr(Err.buffer, "
2590: 4c 4e 4b 31 31 31 37 22 29 20 21 3d 20 4e 55 4c LNK1117") != NUL
25a0: 4c 29 3b 0a 7d 0a 0a 44 57 4f 52 44 20 57 49 4e L);.}..DWORD WIN
25b0: 41 50 49 0a 52 65 61 64 46 72 6f 6d 50 69 70 65 API.ReadFromPipe
25c0: 20 28 4c 50 56 4f 49 44 20 61 72 67 73 29 0a 7b (LPVOID args).{
25d0: 0a 20 20 20 20 70 69 70 65 69 6e 66 6f 20 2a 70 . pipeinfo *p
25e0: 69 20 3d 20 28 70 69 70 65 69 6e 66 6f 20 2a 29 i = (pipeinfo *)
25f0: 20 61 72 67 73 3b 0a 20 20 20 20 63 68 61 72 20 args;. char
2600: 2a 6c 61 73 74 42 75 66 20 3d 20 70 69 2d 3e 62 *lastBuf = pi->b
2610: 75 66 66 65 72 3b 0a 20 20 20 20 44 57 4f 52 44 uffer;. DWORD
2620: 20 64 77 52 65 61 64 3b 0a 20 20 20 20 42 4f 4f dwRead;. BOO
2630: 4c 20 6f 6b 3b 0a 0a 61 67 61 69 6e 3a 0a 20 20 L ok;..again:.
2640: 20 20 6f 6b 20 3d 20 52 65 61 64 46 69 6c 65 28 ok = ReadFile(
2650: 70 69 2d 3e 70 69 70 65 2c 20 6c 61 73 74 42 75 pi->pipe, lastBu
2660: 66 2c 20 32 35 2c 20 26 64 77 52 65 61 64 2c 20 f, 25, &dwRead,
2670: 30 4c 29 3b 0a 20 20 20 20 69 66 20 28 21 6f 6b 0L);. if (!ok
2680: 20 7c 7c 20 64 77 52 65 61 64 20 3d 3d 20 30 29 || dwRead == 0)
2690: 20 7b 0a 09 43 6c 6f 73 65 48 61 6e 64 6c 65 28 {..CloseHandle(
26a0: 70 69 2d 3e 70 69 70 65 29 3b 0a 09 72 65 74 75 pi->pipe);..retu
26b0: 72 6e 20 30 3b 0a 20 20 20 20 7d 0a 20 20 20 20 rn 0;. }.
26c0: 6c 61 73 74 42 75 66 20 2b 3d 20 64 77 52 65 61 lastBuf += dwRea
26d0: 64 3b 0a 20 20 20 20 67 6f 74 6f 20 61 67 61 69 d;. goto agai
26e0: 6e 3b 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 30 n;.. return 0
26f0: 3b 20 20 2f 2a 20 6d 61 6b 65 73 20 74 68 65 20 ; /* makes the
2700: 63 6f 6d 70 69 6c 65 72 20 68 61 70 70 79 20 2a compiler happy *
2710: 2f 0a 7d 0a 0a 69 6e 74 0a 49 73 49 6e 20 28 63 /.}..int.IsIn (c
2720: 6f 6e 73 74 20 63 68 61 72 20 2a 73 74 72 69 6e onst char *strin
2730: 67 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 g, const char *s
2740: 75 62 73 74 72 69 6e 67 29 0a 7b 0a 20 20 20 20 ubstring).{.
2750: 72 65 74 75 72 6e 20 28 73 74 72 73 74 72 28 73 return (strstr(s
2760: 74 72 69 6e 67 2c 20 73 75 62 73 74 72 69 6e 67 tring, substring
2770: 29 20 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 0a 09 ) != NULL);.}...
2780: 0a 73 74 61 74 69 63 20 64 6f 75 62 6c 65 0a 52 .static double.R
2790: 65 61 64 56 65 72 73 69 6f 6e 46 72 6f 6d 48 65 eadVersionFromHe
27a0: 61 64 65 72 28 63 6f 6e 73 74 20 63 68 61 72 20 ader(const char
27b0: 2a 66 69 6c 65 2c 20 63 6f 6e 73 74 20 63 68 61 *file, const cha
27c0: 72 20 2a 6d 61 63 72 6f 29 0a 7b 0a 20 20 20 20 r *macro).{.
27d0: 64 6f 75 62 6c 65 20 64 20 3d 20 30 2e 30 3b 0a double d = 0.0;.
27e0: 20 20 20 20 43 48 41 52 20 73 7a 42 75 66 66 65 CHAR szBuffe
27f0: 72 5b 31 30 30 5d 3b 0a 20 20 20 20 4c 50 53 54 r[100];. LPST
2800: 52 20 70 3b 0a 20 20 20 20 44 57 4f 52 44 20 63 R p;. DWORD c
2810: 62 42 75 66 66 65 72 20 3d 20 31 30 30 3b 0a 20 bBuffer = 100;.
2820: 20 20 20 46 49 4c 45 20 2a 66 70 20 3d 20 66 6f FILE *fp = fo
2830: 70 65 6e 28 66 69 6c 65 2c 20 22 72 22 29 3b 0a pen(file, "r");.
2840: 20 20 20 20 69 66 20 28 66 70 20 21 3d 20 4e 55 if (fp != NU
2850: 4c 4c 29 20 7b 0a 09 77 68 69 6c 65 20 28 66 67 LL) {..while (fg
2860: 65 74 73 28 73 7a 42 75 66 66 65 72 2c 20 63 62 ets(szBuffer, cb
2870: 42 75 66 66 65 72 2c 20 66 70 29 20 21 3d 20 4e Buffer, fp) != N
2880: 55 4c 4c 29 20 7b 0a 09 20 20 20 20 69 66 20 28 ULL) {.. if (
2890: 28 70 20 3d 20 73 74 72 73 74 72 28 73 7a 42 75 (p = strstr(szBu
28a0: 66 66 65 72 2c 20 6d 61 63 72 6f 29 29 20 21 3d ffer, macro)) !=
28b0: 20 4e 55 4c 4c 29 20 7b 0a 09 09 77 68 69 6c 65 NULL) {...while
28c0: 20 28 2a 70 20 26 26 20 21 69 73 64 69 67 69 74 (*p && !isdigit
28d0: 28 2a 70 29 29 20 2b 2b 70 3b 0a 09 09 64 20 3d (*p)) ++p;...d =
28e0: 20 73 74 72 74 6f 64 28 70 2c 20 4e 55 4c 4c 29 strtod(p, NULL)
28f0: 3b 0a 09 09 62 72 65 61 6b 3b 0a 09 20 20 20 20 ;...break;..
2900: 7d 0a 09 7d 0a 09 66 63 6c 6f 73 65 28 66 70 29 }..}..fclose(fp)
2910: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 ;. }. retu
2920: 72 6e 20 64 3b 0a 7d 0a 0a 69 6e 74 0a 47 65 74 rn d;.}..int.Get
2930: 56 65 72 73 69 6f 6e 46 72 6f 6d 48 65 61 64 65 VersionFromHeade
2940: 72 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 74 63 r(const char *tc
2950: 6c 68 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a lh, const char *
2960: 74 6b 68 29 0a 7b 0a 20 20 20 20 64 6f 75 62 6c tkh).{. doubl
2970: 65 20 64 54 63 6c 20 3d 20 30 2e 30 2c 20 64 54 e dTcl = 0.0, dT
2980: 6b 20 3d 20 30 2e 30 3b 0a 20 20 20 20 0a 20 20 k = 0.0;. .
2990: 20 20 69 66 20 28 74 63 6c 68 20 21 3d 20 4e 55 if (tclh != NU
29a0: 4c 4c 29 0a 09 64 54 63 6c 20 3d 20 52 65 61 64 LL)..dTcl = Read
29b0: 56 65 72 73 69 6f 6e 46 72 6f 6d 48 65 61 64 65 VersionFromHeade
29c0: 72 28 74 63 6c 68 2c 20 22 54 43 4c 5f 56 45 52 r(tclh, "TCL_VER
29d0: 53 49 4f 4e 22 29 3b 0a 20 20 20 20 69 66 20 28 SION");. if (
29e0: 74 6b 68 20 21 3d 20 4e 55 4c 4c 29 0a 09 64 54 tkh != NULL)..dT
29f0: 6b 20 3d 20 52 65 61 64 56 65 72 73 69 6f 6e 46 k = ReadVersionF
2a00: 72 6f 6d 48 65 61 64 65 72 28 74 6b 68 2c 20 22 romHeader(tkh, "
2a10: 54 4b 5f 56 45 52 53 49 4f 4e 22 29 3b 0a 0a 20 TK_VERSION");..
2a20: 20 20 20 69 66 20 28 64 54 63 6c 20 3e 20 30 20 if (dTcl > 0
2a30: 7c 7c 20 64 54 6b 20 3e 20 30 29 20 7b 0a 09 46 || dTk > 0) {..F
2a40: 49 4c 45 20 2a 6f 66 70 20 3d 20 66 6f 70 65 6e ILE *ofp = fopen
2a50: 28 22 76 65 72 73 69 6f 6e 2e 76 63 22 2c 20 22 ("version.vc", "
2a60: 77 22 29 3b 0a 09 69 66 20 28 64 54 63 6c 20 3e w");..if (dTcl >
2a70: 20 30 29 0a 09 20 20 20 20 66 70 72 69 6e 74 66 0).. fprintf
2a80: 28 6f 66 70 2c 20 22 54 43 4c 5f 44 4f 54 56 45 (ofp, "TCL_DOTVE
2a90: 52 53 49 4f 4e 5c 74 3d 20 25 30 2e 31 66 5c 6e RSION\t= %0.1f\n
2aa0: 54 43 4c 5f 56 45 52 53 49 4f 4e 5c 74 3d 20 25 TCL_VERSION\t= %
2ab0: 75 5c 6e 22 2c 0a 09 09 20 20 20 20 64 54 63 6c u\n",... dTcl
2ac0: 2c 20 28 69 6e 74 29 28 64 54 63 6c 20 2a 20 31 , (int)(dTcl * 1
2ad0: 30 2e 30 29 29 3b 0a 09 69 66 20 28 64 54 6b 20 0.0));..if (dTk
2ae0: 3e 20 30 29 0a 09 20 20 20 20 66 70 72 69 6e 74 > 0).. fprint
2af0: 66 28 6f 66 70 2c 20 22 54 4b 5f 44 4f 54 56 45 f(ofp, "TK_DOTVE
2b00: 52 53 49 4f 4e 5c 74 3d 20 25 30 2e 31 66 5c 6e RSION\t= %0.1f\n
2b10: 54 4b 5f 56 45 52 53 49 4f 4e 5c 74 3d 20 25 75 TK_VERSION\t= %u
2b20: 5c 6e 22 2c 0a 09 09 20 20 20 20 64 54 6b 2c 20 \n",... dTk,
2b30: 28 69 6e 74 29 28 64 54 6b 20 2a 20 31 30 2e 30 (int)(dTk * 10.0
2b40: 29 29 3b 0a 09 66 63 6c 6f 73 65 28 6f 66 70 29 ));..fclose(ofp)
2b50: 3b 0a 09 72 65 74 75 72 6e 20 30 3b 0a 20 20 20 ;..return 0;.
2b60: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 31 3b }. return 1;
2b70: 0a 7d 0a .}.