Hex Artifact Content

Artifact ec8608e4afa90ecd495aa101860067c560c85af6ee817f91a4c11362dc0b5f3f:


0000: 2f 2a 0a 20 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  /*. * ----------
0010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0040: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0050: 2d 2d 0a 20 2a 20 6e 6d 61 6b 65 68 6c 70 2e 63  --. * nmakehlp.c
0060: 20 2d 2d 0a 20 2a 0a 20 2a 09 54 68 69 73 20 69   --. *. *.This i
0070: 73 20 75 73 65 64 20 74 6f 20 66 69 78 20 6c 69  s used to fix li
0080: 6d 69 74 61 74 69 6f 6e 73 20 77 69 74 68 69 6e  mitations within
0090: 20 6e 6d 61 6b 65 20 61 6e 64 20 74 68 65 20 65   nmake and the e
00a0: 6e 76 69 72 6f 6e 6d 65 6e 74 2e 0a 20 2a 0a 20  nvironment.. *. 
00b0: 2a 20 43 6f 70 79 72 69 67 68 74 20 28 63 29 20  * Copyright (c) 
00c0: 32 30 30 32 20 44 61 76 69 64 20 47 72 61 76 65  2002 David Grave
00d0: 72 65 61 75 78 2e 0a 20 2a 20 43 6f 70 79 72 69  reaux.. * Copyri
00e0: 67 68 74 20 28 63 29 20 32 30 30 36 20 50 61 74  ght (c) 2006 Pat
00f0: 20 54 68 6f 79 74 73 0a 20 2a 0a 20 2a 20 53 65   Thoyts. *. * Se
0100: 65 20 74 68 65 20 66 69 6c 65 20 22 6c 69 63 65  e the file "lice
0110: 6e 73 65 2e 74 65 72 6d 73 22 20 66 6f 72 20 69  nse.terms" for i
0120: 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 75 73  nformation on us
0130: 61 67 65 20 61 6e 64 20 72 65 64 69 73 74 72 69  age and redistri
0140: 62 75 74 69 6f 6e 20 6f 66 0a 20 2a 20 74 68 69  bution of. * thi
0150: 73 20 66 69 6c 65 2c 20 61 6e 64 20 66 6f 72 20  s file, and for 
0160: 61 20 44 49 53 43 4c 41 49 4d 45 52 20 4f 46 20  a DISCLAIMER OF 
0170: 41 4c 4c 20 57 41 52 52 41 4e 54 49 45 53 2e 0a  ALL WARRANTIES..
0180: 20 2a 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   * -------------
0190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
01a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
01b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
01c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
01d0: 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 5f 43 52   */..#define _CR
01e0: 54 5f 53 45 43 55 52 45 5f 4e 4f 5f 44 45 50 52  T_SECURE_NO_DEPR
01f0: 45 43 41 54 45 0a 23 69 6e 63 6c 75 64 65 20 3c  ECATE.#include <
0200: 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 69 66 64 65  windows.h>.#ifde
0210: 66 20 5f 4d 53 43 5f 56 45 52 0a 23 70 72 61 67  f _MSC_VER.#prag
0220: 6d 61 20 63 6f 6d 6d 65 6e 74 20 28 6c 69 62 2c  ma comment (lib,
0230: 20 22 75 73 65 72 33 32 2e 6c 69 62 22 29 0a 23   "user32.lib").#
0240: 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74 20 28  pragma comment (
0250: 6c 69 62 2c 20 22 6b 65 72 6e 65 6c 33 32 2e 6c  lib, "kernel32.l
0260: 69 62 22 29 0a 23 65 6e 64 69 66 0a 23 69 6e 63  ib").#endif.#inc
0270: 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 3e 0a 0a  lude <stdio.h>..
0280: 2f 2a 0a 20 2a 20 54 68 69 73 20 6c 69 62 72 61  /*. * This libra
0290: 72 79 20 69 73 20 72 65 71 75 69 72 65 64 20 66  ry is required f
02a0: 6f 72 20 78 36 34 20 62 75 69 6c 64 73 20 77 69  or x64 builds wi
02b0: 74 68 20 5f 73 6f 6d 65 5f 20 76 65 72 73 69 6f  th _some_ versio
02c0: 6e 73 20 6f 66 20 4d 53 56 43 0a 20 2a 2f 0a 23  ns of MSVC. */.#
02d0: 69 66 20 64 65 66 69 6e 65 64 28 5f 4d 5f 49 41  if defined(_M_IA
02e0: 36 34 29 20 7c 7c 20 64 65 66 69 6e 65 64 28 5f  64) || defined(_
02f0: 4d 5f 41 4d 44 36 34 29 0a 23 69 66 20 5f 4d 53  M_AMD64).#if _MS
0300: 43 5f 56 45 52 20 3e 3d 20 31 34 30 30 20 26 26  C_VER >= 1400 &&
0310: 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 35 30 30   _MSC_VER < 1500
0320: 0a 23 70 72 61 67 6d 61 20 63 6f 6d 6d 65 6e 74  .#pragma comment
0330: 28 6c 69 62 2c 20 22 62 75 66 66 65 72 6f 76 65  (lib, "bufferove
0340: 72 66 6c 6f 77 55 22 29 0a 23 65 6e 64 69 66 0a  rflowU").#endif.
0350: 23 65 6e 64 69 66 0a 0a 2f 2a 20 49 53 4f 20 68  #endif../* ISO h
0360: 61 63 6b 20 66 6f 72 20 64 75 6d 62 20 56 43 2b  ack for dumb VC+
0370: 2b 20 2a 2f 0a 23 69 66 20 64 65 66 69 6e 65 64  + */.#if defined
0380: 28 5f 57 49 4e 33 32 29 20 26 26 20 64 65 66 69  (_WIN32) && defi
0390: 6e 65 64 28 5f 4d 53 43 5f 56 45 52 29 20 26 26  ned(_MSC_VER) &&
03a0: 20 5f 4d 53 43 5f 56 45 52 20 3c 20 31 39 30 30   _MSC_VER < 1900
03b0: 0a 23 64 65 66 69 6e 65 20 20 20 73 6e 70 72 69  .#define   snpri
03c0: 6e 74 66 09 5f 73 6e 70 72 69 6e 74 66 0a 23 65  ntf._snprintf.#e
03d0: 6e 64 69 66 0a 0a 0a 2f 2a 20 70 72 6f 74 6f 73  ndif.../* protos
03e0: 20 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 20   */..static int 
03f0: 43 68 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72  CheckForCompiler
0400: 46 65 61 74 75 72 65 28 63 6f 6e 73 74 20 63 68  Feature(const ch
0410: 61 72 20 2a 6f 70 74 69 6f 6e 29 3b 0a 73 74 61  ar *option);.sta
0420: 74 69 63 20 69 6e 74 20 43 68 65 63 6b 46 6f 72  tic int CheckFor
0430: 4c 69 6e 6b 65 72 46 65 61 74 75 72 65 28 63 68  LinkerFeature(ch
0440: 61 72 20 2a 2a 6f 70 74 69 6f 6e 73 2c 20 69 6e  ar **options, in
0450: 74 20 63 6f 75 6e 74 29 3b 0a 73 74 61 74 69 63  t count);.static
0460: 20 69 6e 74 20 49 73 49 6e 28 63 6f 6e 73 74 20   int IsIn(const 
0470: 63 68 61 72 20 2a 73 74 72 69 6e 67 2c 20 63 6f  char *string, co
0480: 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73 74 72  nst char *substr
0490: 69 6e 67 29 3b 0a 73 74 61 74 69 63 20 69 6e 74  ing);.static int
04a0: 20 53 75 62 73 74 69 74 75 74 65 46 69 6c 65 28   SubstituteFile(
04b0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 73 75 62 73  const char *subs
04c0: 74 73 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  ts, const char *
04d0: 66 69 6c 65 6e 61 6d 65 29 3b 0a 73 74 61 74 69  filename);.stati
04e0: 63 20 69 6e 74 20 51 75 61 6c 69 66 79 50 61 74  c int QualifyPat
04f0: 68 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 70 61  h(const char *pa
0500: 74 68 29 3b 0a 73 74 61 74 69 63 20 69 6e 74 20  th);.static int 
0510: 4c 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79  LocateDependency
0520: 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 6b 65 79  (const char *key
0530: 66 69 6c 65 29 3b 0a 73 74 61 74 69 63 20 63 6f  file);.static co
0540: 6e 73 74 20 63 68 61 72 20 2a 47 65 74 56 65 72  nst char *GetVer
0550: 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 63 6f 6e  sionFromFile(con
0560: 73 74 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d  st char *filenam
0570: 65 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 6d  e, const char *m
0580: 61 74 63 68 2c 20 69 6e 74 20 6e 75 6d 64 6f 74  atch, int numdot
0590: 73 29 3b 0a 73 74 61 74 69 63 20 44 57 4f 52 44  s);.static DWORD
05a0: 20 57 49 4e 41 50 49 20 52 65 61 64 46 72 6f 6d   WINAPI ReadFrom
05b0: 50 69 70 65 28 4c 50 56 4f 49 44 20 61 72 67 73  Pipe(LPVOID args
05c0: 29 3b 0a 0a 2f 2a 20 67 6c 6f 62 61 6c 73 20 2a  );../* globals *
05d0: 2f 0a 0a 23 64 65 66 69 6e 65 20 43 48 55 4e 4b  /..#define CHUNK
05e0: 09 32 35 0a 23 64 65 66 69 6e 65 20 53 54 41 54  .25.#define STAT
05f0: 49 43 42 55 46 46 45 52 53 49 5a 45 20 20 20 20  ICBUFFERSIZE    
0600: 31 30 30 30 0a 74 79 70 65 64 65 66 20 73 74 72  1000.typedef str
0610: 75 63 74 20 7b 0a 20 20 20 20 48 41 4e 44 4c 45  uct {.    HANDLE
0620: 20 70 69 70 65 3b 0a 20 20 20 20 63 68 61 72 20   pipe;.    char 
0630: 62 75 66 66 65 72 5b 53 54 41 54 49 43 42 55 46  buffer[STATICBUF
0640: 46 45 52 53 49 5a 45 5d 3b 0a 7d 20 70 69 70 65  FERSIZE];.} pipe
0650: 69 6e 66 6f 3b 0a 0a 70 69 70 65 69 6e 66 6f 20  info;..pipeinfo 
0660: 4f 75 74 20 3d 20 7b 49 4e 56 41 4c 49 44 5f 48  Out = {INVALID_H
0670: 41 4e 44 4c 45 5f 56 41 4c 55 45 2c 20 22 22 7d  ANDLE_VALUE, ""}
0680: 3b 0a 70 69 70 65 69 6e 66 6f 20 45 72 72 20 3d  ;.pipeinfo Err =
0690: 20 7b 49 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45   {INVALID_HANDLE
06a0: 5f 56 41 4c 55 45 2c 20 22 22 7d 3b 0a 0c 0a 2f  _VALUE, ""};.../
06b0: 2a 0a 20 2a 20 65 78 69 74 63 6f 64 65 73 3a 20  *. * exitcodes: 
06c0: 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65  0 == no, 1 == ye
06d0: 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 0a 20 2a  s, 2 == error. *
06e0: 2f 0a 0a 69 6e 74 0a 6d 61 69 6e 28 0a 20 20 20  /..int.main(.   
06f0: 20 69 6e 74 20 61 72 67 63 2c 0a 20 20 20 20 63   int argc,.    c
0700: 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a 7b 0a 20  har *argv[]).{. 
0710: 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30 30 5d     char msg[300]
0720: 3b 0a 20 20 20 20 44 57 4f 52 44 20 64 77 57 72  ;.    DWORD dwWr
0730: 69 74 74 65 6e 3b 0a 20 20 20 20 69 6e 74 20 63  itten;.    int c
0740: 68 61 72 73 3b 0a 20 20 20 20 63 6f 6e 73 74 20  hars;.    const 
0750: 63 68 61 72 20 2a 73 3b 0a 0a 20 20 20 20 2f 2a  char *s;..    /*
0760: 0a 20 20 20 20 20 2a 20 4d 61 6b 65 20 73 75 72  .     * Make sur
0770: 65 20 63 68 69 6c 64 72 65 6e 20 28 63 6c 2e 65  e children (cl.e
0780: 78 65 20 61 6e 64 20 6c 69 6e 6b 2e 65 78 65 29  xe and link.exe)
0790: 20 61 72 65 20 6b 65 70 74 20 71 75 69 65 74 2e   are kept quiet.
07a0: 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 53 65  .     */..    Se
07b0: 74 45 72 72 6f 72 4d 6f 64 65 28 53 45 4d 5f 46  tErrorMode(SEM_F
07c0: 41 49 4c 43 52 49 54 49 43 41 4c 45 52 52 4f 52  AILCRITICALERROR
07d0: 53 20 7c 20 53 45 4d 5f 4e 4f 4f 50 45 4e 46 49  S | SEM_NOOPENFI
07e0: 4c 45 45 52 52 4f 52 42 4f 58 29 3b 0a 0a 20 20  LEERRORBOX);..  
07f0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 4d 61 6b 65    /*.     * Make
0800: 20 73 75 72 65 20 74 68 65 20 63 6f 6d 70 69 6c   sure the compil
0810: 65 72 20 61 6e 64 20 6c 69 6e 6b 65 72 20 61 72  er and linker ar
0820: 65 6e 27 74 20 65 66 66 65 63 74 65 64 20 62 79  en't effected by
0830: 20 74 68 65 20 6f 75 74 73 69 64 65 20 77 6f 72   the outside wor
0840: 6c 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20  ld..     */..   
0850: 20 53 65 74 45 6e 76 69 72 6f 6e 6d 65 6e 74 56   SetEnvironmentV
0860: 61 72 69 61 62 6c 65 28 22 43 4c 22 2c 20 22 22  ariable("CL", ""
0870: 29 3b 0a 20 20 20 20 53 65 74 45 6e 76 69 72 6f  );.    SetEnviro
0880: 6e 6d 65 6e 74 56 61 72 69 61 62 6c 65 28 22 4c  nmentVariable("L
0890: 49 4e 4b 22 2c 20 22 22 29 3b 0a 0a 20 20 20 20  INK", "");..    
08a0: 69 66 20 28 61 72 67 63 20 3e 20 31 20 26 26 20  if (argc > 1 && 
08b0: 2a 61 72 67 76 5b 31 5d 20 3d 3d 20 27 2d 27 29  *argv[1] == '-')
08c0: 20 7b 0a 09 73 77 69 74 63 68 20 28 2a 28 61 72   {..switch (*(ar
08d0: 67 76 5b 31 5d 2b 31 29 29 20 7b 0a 09 63 61 73  gv[1]+1)) {..cas
08e0: 65 20 27 63 27 3a 0a 09 20 20 20 20 69 66 20 28  e 'c':..    if (
08f0: 61 72 67 63 20 21 3d 20 33 29 20 7b 0a 09 09 63  argc != 3) {...c
0900: 68 61 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28  hars = snprintf(
0910: 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29  msg, sizeof(msg)
0920: 20 2d 20 31 2c 0a 09 09 09 22 75 73 61 67 65 3a   - 1,...."usage:
0930: 20 25 73 20 2d 63 20 3c 63 6f 6d 70 69 6c 65 72   %s -c <compiler
0940: 20 6f 70 74 69 6f 6e 3e 5c 6e 22 0a 09 09 09 22   option>\n"...."
0950: 54 65 73 74 73 20 66 6f 72 20 77 68 65 74 68 65  Tests for whethe
0960: 72 20 63 6c 2e 65 78 65 20 73 75 70 70 6f 72 74  r cl.exe support
0970: 73 20 61 6e 20 6f 70 74 69 6f 6e 5c 6e 22 0a 09  s an option\n"..
0980: 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 20  .."exitcodes: 0 
0990: 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c  == no, 1 == yes,
09a0: 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c 20   2 == error\n", 
09b0: 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74  argv[0]);...Writ
09c0: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64  eFile(GetStdHand
09d0: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e  le(STD_ERROR_HAN
09e0: 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73  DLE), msg, chars
09f0: 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c  ,....&dwWritten,
0a00: 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e   NULL);...return
0a10: 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20 20   2;..    }..    
0a20: 72 65 74 75 72 6e 20 43 68 65 63 6b 46 6f 72 43  return CheckForC
0a30: 6f 6d 70 69 6c 65 72 46 65 61 74 75 72 65 28 61  ompilerFeature(a
0a40: 72 67 76 5b 32 5d 29 3b 0a 09 63 61 73 65 20 27  rgv[2]);..case '
0a50: 6c 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72 67  l':..    if (arg
0a60: 63 20 3c 20 33 29 20 7b 0a 09 09 63 68 61 72 73  c < 3) {...chars
0a70: 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c   = snprintf(msg,
0a80: 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31   sizeof(msg) - 1
0a90: 2c 0a 09 09 09 22 75 73 61 67 65 3a 20 25 73 20  ,...."usage: %s 
0aa0: 2d 6c 20 3c 6c 69 6e 6b 65 72 20 6f 70 74 69 6f  -l <linker optio
0ab0: 6e 3e 20 3f 3c 6d 61 6e 64 61 74 6f 72 79 20 6f  n> ?<mandatory o
0ac0: 70 74 69 6f 6e 3e 20 2e 2e 2e 3f 5c 6e 22 0a 09  ption> ...?\n"..
0ad0: 09 09 22 54 65 73 74 73 20 66 6f 72 20 77 68 65  .."Tests for whe
0ae0: 74 68 65 72 20 6c 69 6e 6b 2e 65 78 65 20 73 75  ther link.exe su
0af0: 70 70 6f 72 74 73 20 61 6e 20 6f 70 74 69 6f 6e  pports an option
0b00: 5c 6e 22 0a 09 09 09 22 65 78 69 74 63 6f 64 65  \n"...."exitcode
0b10: 73 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d  s: 0 == no, 1 ==
0b20: 20 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72   yes, 2 == error
0b30: 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09  \n", argv[0]);..
0b40: 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74  .WriteFile(GetSt
0b50: 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f  dHandle(STD_ERRO
0b60: 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20  R_HANDLE), msg, 
0b70: 63 68 61 72 73 2c 0a 09 09 09 26 64 77 57 72 69  chars,....&dwWri
0b80: 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72  tten, NULL);...r
0b90: 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20 7d 0a  eturn 2;..    }.
0ba0: 09 20 20 20 20 72 65 74 75 72 6e 20 43 68 65 63  .    return Chec
0bb0: 6b 46 6f 72 4c 69 6e 6b 65 72 46 65 61 74 75 72  kForLinkerFeatur
0bc0: 65 28 26 61 72 67 76 5b 32 5d 2c 20 61 72 67 63  e(&argv[2], argc
0bd0: 2d 32 29 3b 0a 09 63 61 73 65 20 27 66 27 3a 0a  -2);..case 'f':.
0be0: 09 20 20 20 20 69 66 20 28 61 72 67 63 20 3d 3d  .    if (argc ==
0bf0: 20 32 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20   2) {...chars = 
0c00: 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69  snprintf(msg, si
0c10: 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09  zeof(msg) - 1,..
0c20: 09 09 22 75 73 61 67 65 3a 20 25 73 20 2d 66 20  .."usage: %s -f 
0c30: 3c 73 74 72 69 6e 67 3e 20 3c 73 75 62 73 74 72  <string> <substr
0c40: 69 6e 67 3e 5c 6e 22 0a 09 09 09 22 46 69 6e 64  ing>\n"...."Find
0c50: 20 61 20 73 75 62 73 74 72 69 6e 67 20 77 69 74   a substring wit
0c60: 68 69 6e 20 61 6e 6f 74 68 65 72 5c 6e 22 0a 09  hin another\n"..
0c70: 09 09 22 65 78 69 74 63 6f 64 65 73 3a 20 30 20  .."exitcodes: 0 
0c80: 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20 79 65 73 2c  == no, 1 == yes,
0c90: 20 32 20 3d 3d 20 65 72 72 6f 72 5c 6e 22 2c 20   2 == error\n", 
0ca0: 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69 74  argv[0]);...Writ
0cb0: 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e 64  eFile(GetStdHand
0cc0: 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41 4e  le(STD_ERROR_HAN
0cd0: 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72 73  DLE), msg, chars
0ce0: 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e 2c  ,....&dwWritten,
0cf0: 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72 6e   NULL);...return
0d00: 20 32 3b 0a 09 20 20 20 20 7d 20 65 6c 73 65 20   2;..    } else 
0d10: 69 66 20 28 61 72 67 63 20 3d 3d 20 33 29 20 7b  if (argc == 3) {
0d20: 0a 09 09 2f 2a 0a 09 09 20 2a 20 49 66 20 74 68  .../*... * If th
0d30: 65 20 73 74 72 69 6e 67 20 69 73 20 62 6c 61 6e  e string is blan
0d40: 6b 2c 20 74 68 65 72 65 20 69 73 20 6e 6f 20 6d  k, there is no m
0d50: 61 74 63 68 2e 0a 09 09 20 2a 2f 0a 0a 09 09 72  atch.... */....r
0d60: 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20  eturn 0;..    } 
0d70: 65 6c 73 65 20 7b 0a 09 09 72 65 74 75 72 6e 20  else {...return 
0d80: 49 73 49 6e 28 61 72 67 76 5b 32 5d 2c 20 61 72  IsIn(argv[2], ar
0d90: 67 76 5b 33 5d 29 3b 0a 09 20 20 20 20 7d 0a 09  gv[3]);..    }..
0da0: 63 61 73 65 20 27 73 27 3a 0a 09 20 20 20 20 69  case 's':..    i
0db0: 66 20 28 61 72 67 63 20 3d 3d 20 32 29 20 7b 0a  f (argc == 2) {.
0dc0: 09 09 63 68 61 72 73 20 3d 20 73 6e 70 72 69 6e  ..chars = snprin
0dd0: 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f 66 28 6d  tf(msg, sizeof(m
0de0: 73 67 29 20 2d 20 31 2c 0a 09 09 09 22 75 73 61  sg) - 1,...."usa
0df0: 67 65 3a 20 25 73 20 2d 73 20 3c 73 75 62 73 74  ge: %s -s <subst
0e00: 69 74 75 74 69 6f 6e 73 20 66 69 6c 65 3e 20 3c  itutions file> <
0e10: 66 69 6c 65 3e 5c 6e 22 0a 09 09 09 22 50 65 72  file>\n"...."Per
0e20: 66 6f 72 6d 20 61 20 73 65 74 20 6f 66 20 73 74  form a set of st
0e30: 72 69 6e 67 20 6d 61 70 20 74 79 70 65 20 73 75  ring map type su
0e40: 62 73 74 75 74 69 74 69 6f 6e 73 20 6f 6e 20 61  bstutitions on a
0e50: 20 66 69 6c 65 5c 6e 22 0a 09 09 09 22 65 78 69   file\n"...."exi
0e60: 74 63 6f 64 65 73 3a 20 30 5c 6e 22 2c 0a 09 09  tcodes: 0\n",...
0e70: 09 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57 72 69  .argv[0]);...Wri
0e80: 74 65 46 69 6c 65 28 47 65 74 53 74 64 48 61 6e  teFile(GetStdHan
0e90: 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f 48 41  dle(STD_ERROR_HA
0ea0: 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68 61 72  NDLE), msg, char
0eb0: 73 2c 0a 09 09 09 26 64 77 57 72 69 74 74 65 6e  s,....&dwWritten
0ec0: 2c 20 4e 55 4c 4c 29 3b 0a 09 09 72 65 74 75 72  , NULL);...retur
0ed0: 6e 20 32 3b 0a 09 20 20 20 20 7d 0a 09 20 20 20  n 2;..    }..   
0ee0: 20 72 65 74 75 72 6e 20 53 75 62 73 74 69 74 75   return Substitu
0ef0: 74 65 46 69 6c 65 28 61 72 67 76 5b 32 5d 2c 20  teFile(argv[2], 
0f00: 61 72 67 76 5b 33 5d 29 3b 0a 09 63 61 73 65 20  argv[3]);..case 
0f10: 27 56 27 3a 0a 09 20 20 20 20 69 66 20 28 61 72  'V':..    if (ar
0f20: 67 63 20 21 3d 20 34 29 20 7b 0a 09 09 63 68 61  gc != 4) {...cha
0f30: 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73  rs = snprintf(ms
0f40: 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d  g, sizeof(msg) -
0f50: 20 31 2c 0a 09 09 20 20 20 20 22 75 73 61 67 65   1,...    "usage
0f60: 3a 20 25 73 20 2d 56 20 66 69 6c 65 6e 61 6d 65  : %s -V filename
0f70: 20 6d 61 74 63 68 73 74 72 69 6e 67 5c 6e 22 0a   matchstring\n".
0f80: 09 09 20 20 20 20 22 45 78 74 72 61 63 74 20 61  ..    "Extract a
0f90: 20 76 65 72 73 69 6f 6e 20 66 72 6f 6d 20 61 20   version from a 
0fa0: 66 69 6c 65 3a 5c 6e 22 0a 09 09 20 20 20 20 22  file:\n"...    "
0fb0: 65 67 3a 20 70 6b 67 49 6e 64 65 78 2e 74 63 6c  eg: pkgIndex.tcl
0fc0: 20 5c 22 70 61 63 6b 61 67 65 20 69 66 6e 65 65   \"package ifnee
0fd0: 64 65 64 20 68 74 74 70 5c 22 22 2c 0a 09 09 20  ded http\"",... 
0fe0: 20 20 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09 57     argv[0]);...W
0ff0: 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64 48  riteFile(GetStdH
1000: 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52 5f  andle(STD_ERROR_
1010: 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63 68  HANDLE), msg, ch
1020: 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57 72  ars,...    &dwWr
1030: 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09 09  itten, NULL);...
1040: 72 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d  return 0;..    }
1050: 0a 09 20 20 20 20 73 20 3d 20 47 65 74 56 65 72  ..    s = GetVer
1060: 73 69 6f 6e 46 72 6f 6d 46 69 6c 65 28 61 72 67  sionFromFile(arg
1070: 76 5b 32 5d 2c 20 61 72 67 76 5b 33 5d 2c 20 2a  v[2], argv[3], *
1080: 28 61 72 67 76 5b 31 5d 2b 32 29 20 2d 20 27 30  (argv[1]+2) - '0
1090: 27 29 3b 0a 09 20 20 20 20 69 66 20 28 73 20 26  ');..    if (s &
10a0: 26 20 2a 73 29 20 7b 0a 09 09 70 72 69 6e 74 66  & *s) {...printf
10b0: 28 22 25 73 5c 6e 22 2c 20 73 29 3b 0a 09 09 72  ("%s\n", s);...r
10c0: 65 74 75 72 6e 20 30 3b 0a 09 20 20 20 20 7d 20  eturn 0;..    } 
10d0: 65 6c 73 65 0a 09 09 72 65 74 75 72 6e 20 31 3b  else...return 1;
10e0: 20 2f 2a 20 56 65 72 73 69 6f 6e 20 6e 6f 74 20   /* Version not 
10f0: 66 6f 75 6e 64 2e 20 52 65 74 75 72 6e 20 6e 6f  found. Return no
1100: 6e 2d 30 20 65 78 69 74 20 63 6f 64 65 20 2a 2f  n-0 exit code */
1110: 0a 0a 09 63 61 73 65 20 27 51 27 3a 0a 09 20 20  ...case 'Q':..  
1120: 20 20 69 66 20 28 61 72 67 63 20 21 3d 20 33 29    if (argc != 3)
1130: 20 7b 0a 09 09 63 68 61 72 73 20 3d 20 73 6e 70   {...chars = snp
1140: 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a 65 6f  rintf(msg, sizeo
1150: 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 09 20 20  f(msg) - 1,...  
1160: 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 51 20    "usage: %s -Q 
1170: 70 61 74 68 5c 6e 22 0a 09 09 20 20 20 20 22 45  path\n"...    "E
1180: 6d 69 74 20 74 68 65 20 66 75 6c 6c 79 20 71 75  mit the fully qu
1190: 61 6c 69 66 69 65 64 20 70 61 74 68 5c 6e 22 0a  alified path\n".
11a0: 09 09 20 20 20 20 22 65 78 69 74 63 6f 64 65 73  ..    "exitcodes
11b0: 3a 20 30 20 3d 3d 20 6e 6f 2c 20 31 20 3d 3d 20  : 0 == no, 1 == 
11c0: 79 65 73 2c 20 32 20 3d 3d 20 65 72 72 6f 72 5c  yes, 2 == error\
11d0: 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09 09  n", argv[0]);...
11e0: 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74 64  WriteFile(GetStd
11f0: 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f 52  Handle(STD_ERROR
1200: 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20 63  _HANDLE), msg, c
1210: 68 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77 57  hars,...    &dwW
1220: 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a 09  ritten, NULL);..
1230: 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20 20  .return 2;..    
1240: 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 51 75  }..    return Qu
1250: 61 6c 69 66 79 50 61 74 68 28 61 72 67 76 5b 32  alifyPath(argv[2
1260: 5d 29 3b 0a 0a 09 63 61 73 65 20 27 4c 27 3a 0a  ]);...case 'L':.
1270: 09 20 20 20 20 69 66 20 28 61 72 67 63 20 21 3d  .    if (argc !=
1280: 20 33 29 20 7b 0a 09 09 63 68 61 72 73 20 3d 20   3) {...chars = 
1290: 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69  snprintf(msg, si
12a0: 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09  zeof(msg) - 1,..
12b0: 09 20 20 20 20 22 75 73 61 67 65 3a 20 25 73 20  .    "usage: %s 
12c0: 2d 4c 20 6b 65 79 70 61 74 68 5c 6e 22 0a 09 09  -L keypath\n"...
12d0: 20 20 20 20 22 45 6d 69 74 20 74 68 65 20 66 75      "Emit the fu
12e0: 6c 6c 79 20 71 75 61 6c 69 66 69 65 64 20 70 61  lly qualified pa
12f0: 74 68 20 6f 66 20 64 69 72 65 63 74 6f 72 79 20  th of directory 
1300: 63 6f 6e 74 61 69 6e 69 6e 67 20 6b 65 79 70 61  containing keypa
1310: 74 68 5c 6e 22 0a 09 09 20 20 20 20 22 65 78 69  th\n"...    "exi
1320: 74 63 6f 64 65 73 3a 20 30 20 3d 3d 20 73 75 63  tcodes: 0 == suc
1330: 63 65 73 73 2c 20 31 20 3d 3d 20 6e 6f 74 20 66  cess, 1 == not f
1340: 6f 75 6e 64 2c 20 32 20 3d 3d 20 65 72 72 6f 72  ound, 2 == error
1350: 5c 6e 22 2c 20 61 72 67 76 5b 30 5d 29 3b 0a 09  \n", argv[0]);..
1360: 09 57 72 69 74 65 46 69 6c 65 28 47 65 74 53 74  .WriteFile(GetSt
1370: 64 48 61 6e 64 6c 65 28 53 54 44 5f 45 52 52 4f  dHandle(STD_ERRO
1380: 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73 67 2c 20  R_HANDLE), msg, 
1390: 63 68 61 72 73 2c 0a 09 09 20 20 20 20 26 64 77  chars,...    &dw
13a0: 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b 0a  Written, NULL);.
13b0: 09 09 72 65 74 75 72 6e 20 32 3b 0a 09 20 20 20  ..return 2;..   
13c0: 20 7d 0a 09 20 20 20 20 72 65 74 75 72 6e 20 4c   }..    return L
13d0: 6f 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 28  ocateDependency(
13e0: 61 72 67 76 5b 32 5d 29 3b 0a 09 7d 0a 20 20 20  argv[2]);..}.   
13f0: 20 7d 0a 20 20 20 20 63 68 61 72 73 20 3d 20 73   }.    chars = s
1400: 6e 70 72 69 6e 74 66 28 6d 73 67 2c 20 73 69 7a  nprintf(msg, siz
1410: 65 6f 66 28 6d 73 67 29 20 2d 20 31 2c 0a 09 20  eof(msg) - 1,.. 
1420: 20 20 20 22 75 73 61 67 65 3a 20 25 73 20 2d 63     "usage: %s -c
1430: 7c 2d 66 7c 2d 6c 7c 2d 51 7c 2d 73 7c 2d 56 20  |-f|-l|-Q|-s|-V 
1440: 2e 2e 2e 5c 6e 22 0a 09 20 20 20 20 22 54 68 69  ...\n"..    "Thi
1450: 73 20 69 73 20 61 20 6c 69 74 74 6c 65 20 68 65  s is a little he
1460: 6c 70 65 72 20 61 70 70 20 74 6f 20 65 71 75 61  lper app to equa
1470: 6c 69 7a 65 20 73 68 65 6c 6c 20 64 69 66 66 65  lize shell diffe
1480: 72 65 6e 63 65 73 20 62 65 74 77 65 65 6e 20 57  rences between W
1490: 69 6e 4e 54 20 61 6e 64 5c 6e 22 0a 09 20 20 20  inNT and\n"..   
14a0: 20 22 57 69 6e 39 78 20 61 6e 64 20 67 65 74 20   "Win9x and get 
14b0: 6e 6d 61 6b 65 2e 65 78 65 20 74 6f 20 61 63 63  nmake.exe to acc
14c0: 6f 6d 70 6c 69 73 68 20 69 74 73 20 6a 6f 62 2e  omplish its job.
14d0: 5c 6e 22 2c 0a 09 20 20 20 20 61 72 67 76 5b 30  \n",..    argv[0
14e0: 5d 29 3b 0a 20 20 20 20 57 72 69 74 65 46 69 6c  ]);.    WriteFil
14f0: 65 28 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53  e(GetStdHandle(S
1500: 54 44 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29  TD_ERROR_HANDLE)
1510: 2c 20 6d 73 67 2c 20 63 68 61 72 73 2c 20 26 64  , msg, chars, &d
1520: 77 57 72 69 74 74 65 6e 2c 20 4e 55 4c 4c 29 3b  wWritten, NULL);
1530: 0a 20 20 20 20 72 65 74 75 72 6e 20 32 3b 0a 7d  .    return 2;.}
1540: 0a 0c 0a 73 74 61 74 69 63 20 69 6e 74 0a 43 68  ...static int.Ch
1550: 65 63 6b 46 6f 72 43 6f 6d 70 69 6c 65 72 46 65  eckForCompilerFe
1560: 61 74 75 72 65 28 0a 20 20 20 20 63 6f 6e 73 74  ature(.    const
1570: 20 63 68 61 72 20 2a 6f 70 74 69 6f 6e 29 0a 7b   char *option).{
1580: 0a 20 20 20 20 53 54 41 52 54 55 50 49 4e 46 4f  .    STARTUPINFO
1590: 20 73 69 3b 0a 20 20 20 20 50 52 4f 43 45 53 53   si;.    PROCESS
15a0: 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 70 69 3b  _INFORMATION pi;
15b0: 0a 20 20 20 20 53 45 43 55 52 49 54 59 5f 41 54  .    SECURITY_AT
15c0: 54 52 49 42 55 54 45 53 20 73 61 3b 0a 20 20 20  TRIBUTES sa;.   
15d0: 20 44 57 4f 52 44 20 74 68 72 65 61 64 49 44 3b   DWORD threadID;
15e0: 0a 20 20 20 20 63 68 61 72 20 6d 73 67 5b 33 30  .    char msg[30
15f0: 30 5d 3b 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b  0];.    BOOL ok;
1600: 0a 20 20 20 20 48 41 4e 44 4c 45 20 68 50 72 6f  .    HANDLE hPro
1610: 63 65 73 73 2c 20 68 2c 20 70 69 70 65 54 68 72  cess, h, pipeThr
1620: 65 61 64 73 5b 32 5d 3b 0a 20 20 20 20 63 68 61  eads[2];.    cha
1630: 72 20 63 6d 64 6c 69 6e 65 5b 31 30 30 5d 3b 0a  r cmdline[100];.
1640: 0a 20 20 20 20 68 50 72 6f 63 65 73 73 20 3d 20  .    hProcess = 
1650: 47 65 74 43 75 72 72 65 6e 74 50 72 6f 63 65 73  GetCurrentProces
1660: 73 28 29 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74  s();..    memset
1670: 28 26 70 69 2c 20 30 2c 20 73 69 7a 65 6f 66 28  (&pi, 0, sizeof(
1680: 50 52 4f 43 45 53 53 5f 49 4e 46 4f 52 4d 41 54  PROCESS_INFORMAT
1690: 49 4f 4e 29 29 3b 0a 20 20 20 20 6d 65 6d 73 65  ION));.    memse
16a0: 74 28 26 73 69 2c 20 30 2c 20 73 69 7a 65 6f 66  t(&si, 0, sizeof
16b0: 28 53 54 41 52 54 55 50 49 4e 46 4f 29 29 3b 0a  (STARTUPINFO));.
16c0: 20 20 20 20 73 69 2e 63 62 20 3d 20 73 69 7a 65      si.cb = size
16d0: 6f 66 28 53 54 41 52 54 55 50 49 4e 46 4f 29 3b  of(STARTUPINFO);
16e0: 0a 20 20 20 20 73 69 2e 64 77 46 6c 61 67 73 20  .    si.dwFlags 
16f0: 20 20 3d 20 53 54 41 52 54 46 5f 55 53 45 53 54    = STARTF_USEST
1700: 44 48 41 4e 44 4c 45 53 3b 0a 20 20 20 20 73 69  DHANDLES;.    si
1710: 2e 68 53 74 64 49 6e 70 75 74 20 3d 20 49 4e 56  .hStdInput = INV
1720: 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41 4c 55  ALID_HANDLE_VALU
1730: 45 3b 0a 0a 20 20 20 20 6d 65 6d 73 65 74 28 26  E;..    memset(&
1740: 73 61 2c 20 30 2c 20 73 69 7a 65 6f 66 28 53 45  sa, 0, sizeof(SE
1750: 43 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45  CURITY_ATTRIBUTE
1760: 53 29 29 3b 0a 20 20 20 20 73 61 2e 6e 4c 65 6e  S));.    sa.nLen
1770: 67 74 68 20 3d 20 73 69 7a 65 6f 66 28 53 45 43  gth = sizeof(SEC
1780: 55 52 49 54 59 5f 41 54 54 52 49 42 55 54 45 53  URITY_ATTRIBUTES
1790: 29 3b 0a 20 20 20 20 73 61 2e 6c 70 53 65 63 75  );.    sa.lpSecu
17a0: 72 69 74 79 44 65 73 63 72 69 70 74 6f 72 20 3d  rityDescriptor =
17b0: 20 4e 55 4c 4c 3b 0a 20 20 20 20 73 61 2e 62 49   NULL;.    sa.bI
17c0: 6e 68 65 72 69 74 48 61 6e 64 6c 65 20 3d 20 46  nheritHandle = F
17d0: 41 4c 53 45 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20  ALSE;..    /*.  
17e0: 20 20 20 2a 20 43 72 65 61 74 65 20 61 20 6e 6f     * Create a no
17f0: 6e 2d 69 6e 68 65 72 69 74 61 62 6c 65 20 70 69  n-inheritable pi
1800: 70 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20  pe..     */..   
1810: 20 43 72 65 61 74 65 50 69 70 65 28 26 4f 75 74   CreatePipe(&Out
1820: 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c 20  .pipe, &h, &sa, 
1830: 30 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20  0);..    /*.    
1840: 20 2a 20 44 75 70 65 20 74 68 65 20 77 72 69 74   * Dupe the writ
1850: 65 20 73 69 64 65 2c 20 6d 61 6b 65 20 69 74 20  e side, make it 
1860: 69 6e 68 65 72 69 74 61 62 6c 65 2c 20 61 6e 64  inheritable, and
1870: 20 63 6c 6f 73 65 20 74 68 65 20 6f 72 69 67 69   close the origi
1880: 6e 61 6c 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20  nal..     */..  
1890: 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c    DuplicateHandl
18a0: 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68  e(hProcess, h, h
18b0: 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74  Process, &si.hSt
18c0: 64 4f 75 74 70 75 74 2c 20 30 2c 20 54 52 55 45  dOutput, 0, TRUE
18d0: 2c 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 45  ,..    DUPLICATE
18e0: 5f 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44  _SAME_ACCESS | D
18f0: 55 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53  UPLICATE_CLOSE_S
1900: 4f 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a  OURCE);..    /*.
1910: 20 20 20 20 20 2a 20 53 61 6d 65 20 61 73 20 61       * Same as a
1920: 62 6f 76 65 2c 20 62 75 74 20 66 6f 72 20 74 68  bove, but for th
1930: 65 20 65 72 72 6f 72 20 73 69 64 65 2e 0a 20 20  e error side..  
1940: 20 20 20 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74     */..    Creat
1950: 65 50 69 70 65 28 26 45 72 72 2e 70 69 70 65 2c  ePipe(&Err.pipe,
1960: 20 26 68 2c 20 26 73 61 2c 20 30 29 3b 0a 20 20   &h, &sa, 0);.  
1970: 20 20 44 75 70 6c 69 63 61 74 65 48 61 6e 64 6c    DuplicateHandl
1980: 65 28 68 50 72 6f 63 65 73 73 2c 20 68 2c 20 68  e(hProcess, h, h
1990: 50 72 6f 63 65 73 73 2c 20 26 73 69 2e 68 53 74  Process, &si.hSt
19a0: 64 45 72 72 6f 72 2c 20 30 2c 20 54 52 55 45 2c  dError, 0, TRUE,
19b0: 0a 09 20 20 20 20 44 55 50 4c 49 43 41 54 45 5f  ..    DUPLICATE_
19c0: 53 41 4d 45 5f 41 43 43 45 53 53 20 7c 20 44 55  SAME_ACCESS | DU
19d0: 50 4c 49 43 41 54 45 5f 43 4c 4f 53 45 5f 53 4f  PLICATE_CLOSE_SO
19e0: 55 52 43 45 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20  URCE);..    /*. 
19f0: 20 20 20 20 2a 20 42 61 73 65 20 63 6f 6d 6d 61      * Base comma
1a00: 6e 64 20 6c 69 6e 65 2e 0a 20 20 20 20 20 2a 2f  nd line..     */
1a10: 0a 0a 20 20 20 20 6c 73 74 72 63 70 79 28 63 6d  ..    lstrcpy(cm
1a20: 64 6c 69 6e 65 2c 20 22 63 6c 2e 65 78 65 20 2d  dline, "cl.exe -
1a30: 6e 6f 6c 6f 67 6f 20 2d 63 20 2d 54 43 20 2d 5a  nologo -c -TC -Z
1a40: 73 20 2d 58 20 2d 46 70 2e 5c 5c 5f 6a 75 6e 6b  s -X -Fp.\\_junk
1a50: 2e 70 63 68 20 22 29 3b 0a 0a 20 20 20 20 2f 2a  .pch ");..    /*
1a60: 0a 20 20 20 20 20 2a 20 41 70 70 65 6e 64 20 6f  .     * Append o
1a70: 75 72 20 6f 70 74 69 6f 6e 20 66 6f 72 20 74 65  ur option for te
1a80: 73 74 69 6e 67 0a 20 20 20 20 20 2a 2f 0a 0a 20  sting.     */.. 
1a90: 20 20 20 6c 73 74 72 63 61 74 28 63 6d 64 6c 69     lstrcat(cmdli
1aa0: 6e 65 2c 20 6f 70 74 69 6f 6e 29 3b 0a 0a 20 20  ne, option);..  
1ab0: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 46 69 6c 65    /*.     * File
1ac0: 6e 61 6d 65 20 74 6f 20 63 6f 6d 70 69 6c 65 2c  name to compile,
1ad0: 20 77 68 69 63 68 20 65 78 69 73 74 73 2c 20 62   which exists, b
1ae0: 75 74 20 69 73 20 6e 6f 74 68 69 6e 67 20 61 6e  ut is nothing an
1af0: 64 20 65 6d 70 74 79 2e 0a 20 20 20 20 20 2a 2f  d empty..     */
1b00: 0a 0a 20 20 20 20 6c 73 74 72 63 61 74 28 63 6d  ..    lstrcat(cm
1b10: 64 6c 69 6e 65 2c 20 22 20 2e 5c 5c 6e 75 6c 22  dline, " .\\nul"
1b20: 29 3b 0a 0a 20 20 20 20 6f 6b 20 3d 20 43 72 65  );..    ok = Cre
1b30: 61 74 65 50 72 6f 63 65 73 73 28 0a 09 20 20 20  ateProcess(..   
1b40: 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 4d 6f   NULL,.    /* Mo
1b50: 64 75 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a 09 20  dule name. */.. 
1b60: 20 20 20 63 6d 64 6c 69 6e 65 2c 09 20 20 20 20     cmdline,.    
1b70: 2f 2a 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e  /* Command line.
1b80: 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c 09 20   */..    NULL,. 
1b90: 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20 68 61     /* Process ha
1ba0: 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72 69 74  ndle not inherit
1bb0: 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20 4e 55  able. */..    NU
1bc0: 4c 4c 2c 09 20 20 20 20 2f 2a 20 54 68 72 65 61  LL,.    /* Threa
1bd0: 64 20 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68  d handle not inh
1be0: 65 72 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20  eritable. */..  
1bf0: 20 20 54 52 55 45 2c 09 20 20 20 20 2f 2a 20 79    TRUE,.    /* y
1c00: 65 73 2c 20 69 6e 68 65 72 69 74 20 68 61 6e 64  es, inherit hand
1c10: 6c 65 73 2e 20 2a 2f 0a 09 20 20 20 20 44 45 54  les. */..    DET
1c20: 41 43 48 45 44 5f 50 52 4f 43 45 53 53 2c 20 2f  ACHED_PROCESS, /
1c30: 2a 20 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66 6f 72  * No console for
1c40: 20 79 6f 75 2e 20 2a 2f 0a 09 20 20 20 20 4e 55   you. */..    NU
1c50: 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65 20 70  LL,.    /* Use p
1c60: 61 72 65 6e 74 27 73 20 65 6e 76 69 72 6f 6e 6d  arent's environm
1c70: 65 6e 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a 09 20  ent block. */.. 
1c80: 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20     NULL,.    /* 
1c90: 55 73 65 20 70 61 72 65 6e 74 27 73 20 73 74 61  Use parent's sta
1ca0: 72 74 69 6e 67 20 64 69 72 65 63 74 6f 72 79 2e  rting directory.
1cb0: 20 2a 2f 0a 09 20 20 20 20 26 73 69 2c 09 20 20   */..    &si,.  
1cc0: 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74 6f 20    /* Pointer to 
1cd0: 53 54 41 52 54 55 50 49 4e 46 4f 20 73 74 72 75  STARTUPINFO stru
1ce0: 63 74 75 72 65 2e 20 2a 2f 0a 09 20 20 20 20 26  cture. */..    &
1cf0: 70 69 29 3b 09 20 20 20 20 2f 2a 20 50 6f 69 6e  pi);.    /* Poin
1d00: 74 65 72 20 74 6f 20 50 52 4f 43 45 53 53 5f 49  ter to PROCESS_I
1d10: 4e 46 4f 52 4d 41 54 49 4f 4e 20 73 74 72 75 63  NFORMATION struc
1d20: 74 75 72 65 2e 20 2a 2f 0a 0a 20 20 20 20 69 66  ture. */..    if
1d30: 20 28 21 6f 6b 29 20 7b 0a 09 44 57 4f 52 44 20   (!ok) {..DWORD 
1d40: 65 72 72 20 3d 20 47 65 74 4c 61 73 74 45 72 72  err = GetLastErr
1d50: 6f 72 28 29 3b 0a 09 69 6e 74 20 63 68 61 72 73  or();..int chars
1d60: 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73 67 2c   = snprintf(msg,
1d70: 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d 20 31   sizeof(msg) - 1
1d80: 2c 0a 09 09 22 54 72 69 65 64 20 74 6f 20 6c 61  ,..."Tried to la
1d90: 75 6e 63 68 3a 20 5c 22 25 73 5c 22 2c 20 62 75  unch: \"%s\", bu
1da0: 74 20 67 6f 74 20 65 72 72 6f 72 20 5b 25 6c 75  t got error [%lu
1db0: 5d 3a 20 22 2c 20 63 6d 64 6c 69 6e 65 2c 20 65  ]: ", cmdline, e
1dc0: 72 72 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d 65 73  rr);...FormatMes
1dd0: 73 61 67 65 28 46 4f 52 4d 41 54 5f 4d 45 53 53  sage(FORMAT_MESS
1de0: 41 47 45 5f 46 52 4f 4d 5f 53 59 53 54 45 4d 7c  AGE_FROM_SYSTEM|
1df0: 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f 49  FORMAT_MESSAGE_I
1e00: 47 4e 4f 52 45 5f 49 4e 53 45 52 54 53 7c 0a 09  GNORE_INSERTS|..
1e10: 09 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45 5f  .FORMAT_MESSAGE_
1e20: 4d 41 58 5f 57 49 44 54 48 5f 4d 41 53 4b 2c 20  MAX_WIDTH_MASK, 
1e30: 30 4c 2c 20 65 72 72 2c 20 30 2c 20 28 4c 50 53  0L, err, 0, (LPS
1e40: 54 52 29 26 6d 73 67 5b 63 68 61 72 73 5d 2c 0a  TR)&msg[chars],.
1e50: 09 09 28 33 30 30 2d 63 68 61 72 73 29 2c 20 30  ..(300-chars), 0
1e60: 29 3b 0a 09 57 72 69 74 65 46 69 6c 65 28 47 65  );..WriteFile(Ge
1e70: 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44 5f 45  tStdHandle(STD_E
1e80: 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20 6d 73  RROR_HANDLE), ms
1e90: 67 2c 20 6c 73 74 72 6c 65 6e 28 6d 73 67 29 2c  g, lstrlen(msg),
1ea0: 20 26 65 72 72 2c 4e 55 4c 4c 29 3b 0a 09 72 65   &err,NULL);..re
1eb0: 74 75 72 6e 20 32 3b 0a 20 20 20 20 7d 0a 0a 20  turn 2;.    }.. 
1ec0: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 6c 6f     /*.     * Clo
1ed0: 73 65 20 6f 75 72 20 72 65 66 65 72 65 6e 63 65  se our reference
1ee0: 73 20 74 6f 20 74 68 65 20 77 72 69 74 65 20 68  s to the write h
1ef0: 61 6e 64 6c 65 73 20 74 68 61 74 20 68 61 76 65  andles that have
1f00: 20 6e 6f 77 20 62 65 65 6e 20 69 6e 68 65 72 69   now been inheri
1f10: 74 65 64 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20  ted..     */..  
1f20: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69    CloseHandle(si
1f30: 2e 68 53 74 64 4f 75 74 70 75 74 29 3b 0a 20 20  .hStdOutput);.  
1f40: 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65 28 73 69    CloseHandle(si
1f50: 2e 68 53 74 64 45 72 72 6f 72 29 3b 0a 0a 20 20  .hStdError);..  
1f60: 20 20 57 61 69 74 46 6f 72 49 6e 70 75 74 49 64    WaitForInputId
1f70: 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73 2c 20  le(pi.hProcess, 
1f80: 35 30 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65  5000);.    Close
1f90: 48 61 6e 64 6c 65 28 70 69 2e 68 54 68 72 65 61  Handle(pi.hThrea
1fa0: 64 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20  d);..    /*.    
1fb0: 20 2a 20 53 74 61 72 74 20 74 68 65 20 70 69 70   * Start the pip
1fc0: 65 20 72 65 61 64 65 72 20 74 68 72 65 61 64 73  e reader threads
1fd0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 70  ..     */..    p
1fe0: 69 70 65 54 68 72 65 61 64 73 5b 30 5d 20 3d 20  ipeThreads[0] = 
1ff0: 43 72 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c  CreateThread(NUL
2000: 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69  L, 0, ReadFromPi
2010: 70 65 2c 20 26 4f 75 74 2c 20 30 2c 20 26 74 68  pe, &Out, 0, &th
2020: 72 65 61 64 49 44 29 3b 0a 20 20 20 20 70 69 70  readID);.    pip
2030: 65 54 68 72 65 61 64 73 5b 31 5d 20 3d 20 43 72  eThreads[1] = Cr
2040: 65 61 74 65 54 68 72 65 61 64 28 4e 55 4c 4c 2c  eateThread(NULL,
2050: 20 30 2c 20 52 65 61 64 46 72 6f 6d 50 69 70 65   0, ReadFromPipe
2060: 2c 20 26 45 72 72 2c 20 30 2c 20 26 74 68 72 65  , &Err, 0, &thre
2070: 61 64 49 44 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20  adID);..    /*. 
2080: 20 20 20 20 2a 20 42 6c 6f 63 6b 20 77 61 69 74      * Block wait
2090: 69 6e 67 20 66 6f 72 20 74 68 65 20 70 72 6f 63  ing for the proc
20a0: 65 73 73 20 74 6f 20 65 6e 64 2e 0a 20 20 20 20  ess to end..    
20b0: 20 2a 2f 0a 0a 20 20 20 20 57 61 69 74 46 6f 72   */..    WaitFor
20c0: 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28 70 69 2e  SingleObject(pi.
20d0: 68 50 72 6f 63 65 73 73 2c 20 49 4e 46 49 4e 49  hProcess, INFINI
20e0: 54 45 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61  TE);.    CloseHa
20f0: 6e 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 73 73  ndle(pi.hProcess
2100: 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20  );..    /*.     
2110: 2a 20 57 61 69 74 20 66 6f 72 20 6f 75 72 20 70  * Wait for our p
2120: 69 70 65 20 74 6f 20 67 65 74 20 64 6f 6e 65 20  ipe to get done 
2130: 72 65 61 64 69 6e 67 2c 20 73 68 6f 75 6c 64 20  reading, should 
2140: 69 74 20 62 65 20 61 20 6c 69 74 74 6c 65 20 73  it be a little s
2150: 6c 6f 77 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20  low..     */..  
2160: 20 20 57 61 69 74 46 6f 72 4d 75 6c 74 69 70 6c    WaitForMultipl
2170: 65 4f 62 6a 65 63 74 73 28 32 2c 20 70 69 70 65  eObjects(2, pipe
2180: 54 68 72 65 61 64 73 2c 20 54 52 55 45 2c 20 35  Threads, TRUE, 5
2190: 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48 61  00);.    CloseHa
21a0: 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64 73  ndle(pipeThreads
21b0: 5b 30 5d 29 3b 0a 20 20 20 20 43 6c 6f 73 65 48  [0]);.    CloseH
21c0: 61 6e 64 6c 65 28 70 69 70 65 54 68 72 65 61 64  andle(pipeThread
21d0: 73 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20  s[1]);..    /*. 
21e0: 20 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f 72 20 74      * Look for t
21f0: 68 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e 65 20 77  he commandline w
2200: 61 72 6e 69 6e 67 20 63 6f 64 65 20 69 6e 20 62  arning code in b
2210: 6f 74 68 20 73 74 72 65 61 6d 73 2e 0a 20 20 20  oth streams..   
2220: 20 20 2a 20 20 2d 20 69 6e 20 4d 53 56 43 20 36    *  - in MSVC 6
2230: 20 26 20 37 20 77 65 20 67 65 74 20 44 34 30 30   & 7 we get D400
2240: 32 2c 20 69 6e 20 4d 53 56 43 20 38 20 77 65 20  2, in MSVC 8 we 
2250: 67 65 74 20 44 39 30 30 32 2e 0a 20 20 20 20 20  get D9002..     
2260: 2a 2f 0a 0a 20 20 20 20 72 65 74 75 72 6e 20 21  */..    return !
2270: 28 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66  (strstr(Out.buff
2280: 65 72 2c 20 22 44 34 30 30 32 22 29 20 21 3d 20  er, "D4002") != 
2290: 4e 55 4c 4c 0a 09 20 20 20 20 7c 7c 20 73 74 72  NULL..    || str
22a0: 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20  str(Err.buffer, 
22b0: 22 44 34 30 30 32 22 29 20 21 3d 20 4e 55 4c 4c  "D4002") != NULL
22c0: 0a 09 20 20 20 20 7c 7c 20 73 74 72 73 74 72 28  ..    || strstr(
22d0: 4f 75 74 2e 62 75 66 66 65 72 2c 20 22 44 39 30  Out.buffer, "D90
22e0: 30 32 22 29 20 21 3d 20 4e 55 4c 4c 0a 09 20 20  02") != NULL..  
22f0: 20 20 7c 7c 20 73 74 72 73 74 72 28 45 72 72 2e    || strstr(Err.
2300: 62 75 66 66 65 72 2c 20 22 44 39 30 30 32 22 29  buffer, "D9002")
2310: 20 21 3d 20 4e 55 4c 4c 0a 09 20 20 20 20 7c 7c   != NULL..    ||
2320: 20 73 74 72 73 74 72 28 4f 75 74 2e 62 75 66 66   strstr(Out.buff
2330: 65 72 2c 20 22 44 32 30 32 31 22 29 20 21 3d 20  er, "D2021") != 
2340: 4e 55 4c 4c 0a 09 20 20 20 20 7c 7c 20 73 74 72  NULL..    || str
2350: 73 74 72 28 45 72 72 2e 62 75 66 66 65 72 2c 20  str(Err.buffer, 
2360: 22 44 32 30 32 31 22 29 20 21 3d 20 4e 55 4c 4c  "D2021") != NULL
2370: 29 3b 0a 7d 0a 0c 0a 73 74 61 74 69 63 20 69 6e  );.}...static in
2380: 74 0a 43 68 65 63 6b 46 6f 72 4c 69 6e 6b 65 72  t.CheckForLinker
2390: 46 65 61 74 75 72 65 28 0a 20 20 20 20 63 68 61  Feature(.    cha
23a0: 72 20 2a 2a 6f 70 74 69 6f 6e 73 2c 0a 20 20 20  r **options,.   
23b0: 20 69 6e 74 20 63 6f 75 6e 74 29 0a 7b 0a 20 20   int count).{.  
23c0: 20 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 69    STARTUPINFO si
23d0: 3b 0a 20 20 20 20 50 52 4f 43 45 53 53 5f 49 4e  ;.    PROCESS_IN
23e0: 46 4f 52 4d 41 54 49 4f 4e 20 70 69 3b 0a 20 20  FORMATION pi;.  
23f0: 20 20 53 45 43 55 52 49 54 59 5f 41 54 54 52 49    SECURITY_ATTRI
2400: 42 55 54 45 53 20 73 61 3b 0a 20 20 20 20 44 57  BUTES sa;.    DW
2410: 4f 52 44 20 74 68 72 65 61 64 49 44 3b 0a 20 20  ORD threadID;.  
2420: 20 20 63 68 61 72 20 6d 73 67 5b 33 30 30 5d 3b    char msg[300];
2430: 0a 20 20 20 20 42 4f 4f 4c 20 6f 6b 3b 0a 20 20  .    BOOL ok;.  
2440: 20 20 48 41 4e 44 4c 45 20 68 50 72 6f 63 65 73    HANDLE hProces
2450: 73 2c 20 68 2c 20 70 69 70 65 54 68 72 65 61 64  s, h, pipeThread
2460: 73 5b 32 5d 3b 0a 20 20 20 20 69 6e 74 20 69 3b  s[2];.    int i;
2470: 0a 20 20 20 20 63 68 61 72 20 63 6d 64 6c 69 6e  .    char cmdlin
2480: 65 5b 32 35 35 5d 3b 0a 0a 20 20 20 20 68 50 72  e[255];..    hPr
2490: 6f 63 65 73 73 20 3d 20 47 65 74 43 75 72 72 65  ocess = GetCurre
24a0: 6e 74 50 72 6f 63 65 73 73 28 29 3b 0a 0a 20 20  ntProcess();..  
24b0: 20 20 6d 65 6d 73 65 74 28 26 70 69 2c 20 30 2c    memset(&pi, 0,
24c0: 20 73 69 7a 65 6f 66 28 50 52 4f 43 45 53 53 5f   sizeof(PROCESS_
24d0: 49 4e 46 4f 52 4d 41 54 49 4f 4e 29 29 3b 0a 20  INFORMATION));. 
24e0: 20 20 20 6d 65 6d 73 65 74 28 26 73 69 2c 20 30     memset(&si, 0
24f0: 2c 20 73 69 7a 65 6f 66 28 53 54 41 52 54 55 50  , sizeof(STARTUP
2500: 49 4e 46 4f 29 29 3b 0a 20 20 20 20 73 69 2e 63  INFO));.    si.c
2510: 62 20 3d 20 73 69 7a 65 6f 66 28 53 54 41 52 54  b = sizeof(START
2520: 55 50 49 4e 46 4f 29 3b 0a 20 20 20 20 73 69 2e  UPINFO);.    si.
2530: 64 77 46 6c 61 67 73 20 20 20 3d 20 53 54 41 52  dwFlags   = STAR
2540: 54 46 5f 55 53 45 53 54 44 48 41 4e 44 4c 45 53  TF_USESTDHANDLES
2550: 3b 0a 20 20 20 20 73 69 2e 68 53 74 64 49 6e 70  ;.    si.hStdInp
2560: 75 74 20 3d 20 49 4e 56 41 4c 49 44 5f 48 41 4e  ut = INVALID_HAN
2570: 44 4c 45 5f 56 41 4c 55 45 3b 0a 0a 20 20 20 20  DLE_VALUE;..    
2580: 6d 65 6d 73 65 74 28 26 73 61 2c 20 30 2c 20 73  memset(&sa, 0, s
2590: 69 7a 65 6f 66 28 53 45 43 55 52 49 54 59 5f 41  izeof(SECURITY_A
25a0: 54 54 52 49 42 55 54 45 53 29 29 3b 0a 20 20 20  TTRIBUTES));.   
25b0: 20 73 61 2e 6e 4c 65 6e 67 74 68 20 3d 20 73 69   sa.nLength = si
25c0: 7a 65 6f 66 28 53 45 43 55 52 49 54 59 5f 41 54  zeof(SECURITY_AT
25d0: 54 52 49 42 55 54 45 53 29 3b 0a 20 20 20 20 73  TRIBUTES);.    s
25e0: 61 2e 6c 70 53 65 63 75 72 69 74 79 44 65 73 63  a.lpSecurityDesc
25f0: 72 69 70 74 6f 72 20 3d 20 4e 55 4c 4c 3b 0a 20  riptor = NULL;. 
2600: 20 20 20 73 61 2e 62 49 6e 68 65 72 69 74 48 61     sa.bInheritHa
2610: 6e 64 6c 65 20 3d 20 54 52 55 45 3b 0a 0a 20 20  ndle = TRUE;..  
2620: 20 20 2f 2a 0a 20 20 20 20 20 2a 20 43 72 65 61    /*.     * Crea
2630: 74 65 20 61 20 6e 6f 6e 2d 69 6e 68 65 72 69 74  te a non-inherit
2640: 69 62 6c 65 20 70 69 70 65 2e 0a 20 20 20 20 20  ible pipe..     
2650: 2a 2f 0a 0a 20 20 20 20 43 72 65 61 74 65 50 69  */..    CreatePi
2660: 70 65 28 26 4f 75 74 2e 70 69 70 65 2c 20 26 68  pe(&Out.pipe, &h
2670: 2c 20 26 73 61 2c 20 30 29 3b 0a 0a 20 20 20 20  , &sa, 0);..    
2680: 2f 2a 0a 20 20 20 20 20 2a 20 44 75 70 65 20 74  /*.     * Dupe t
2690: 68 65 20 77 72 69 74 65 20 73 69 64 65 2c 20 6d  he write side, m
26a0: 61 6b 65 20 69 74 20 69 6e 68 65 72 69 74 61 62  ake it inheritab
26b0: 6c 65 2c 20 61 6e 64 20 63 6c 6f 73 65 20 74 68  le, and close th
26c0: 65 20 6f 72 69 67 69 6e 61 6c 2e 0a 20 20 20 20  e original..    
26d0: 20 2a 2f 0a 0a 20 20 20 20 44 75 70 6c 69 63 61   */..    Duplica
26e0: 74 65 48 61 6e 64 6c 65 28 68 50 72 6f 63 65 73  teHandle(hProces
26f0: 73 2c 20 68 2c 20 68 50 72 6f 63 65 73 73 2c 20  s, h, hProcess, 
2700: 26 73 69 2e 68 53 74 64 4f 75 74 70 75 74 2c 20  &si.hStdOutput, 
2710: 30 2c 20 54 52 55 45 2c 0a 09 20 20 20 20 44 55  0, TRUE,..    DU
2720: 50 4c 49 43 41 54 45 5f 53 41 4d 45 5f 41 43 43  PLICATE_SAME_ACC
2730: 45 53 53 20 7c 20 44 55 50 4c 49 43 41 54 45 5f  ESS | DUPLICATE_
2740: 43 4c 4f 53 45 5f 53 4f 55 52 43 45 29 3b 0a 0a  CLOSE_SOURCE);..
2750: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 53 61      /*.     * Sa
2760: 6d 65 20 61 73 20 61 62 6f 76 65 2c 20 62 75 74  me as above, but
2770: 20 66 6f 72 20 74 68 65 20 65 72 72 6f 72 20 73   for the error s
2780: 69 64 65 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20  ide..     */..  
2790: 20 20 43 72 65 61 74 65 50 69 70 65 28 26 45 72    CreatePipe(&Er
27a0: 72 2e 70 69 70 65 2c 20 26 68 2c 20 26 73 61 2c  r.pipe, &h, &sa,
27b0: 20 30 29 3b 0a 20 20 20 20 44 75 70 6c 69 63 61   0);.    Duplica
27c0: 74 65 48 61 6e 64 6c 65 28 68 50 72 6f 63 65 73  teHandle(hProces
27d0: 73 2c 20 68 2c 20 68 50 72 6f 63 65 73 73 2c 20  s, h, hProcess, 
27e0: 26 73 69 2e 68 53 74 64 45 72 72 6f 72 2c 20 30  &si.hStdError, 0
27f0: 2c 20 54 52 55 45 2c 0a 09 20 20 20 20 44 55 50  , TRUE,..    DUP
2800: 4c 49 43 41 54 45 5f 53 41 4d 45 5f 41 43 43 45  LICATE_SAME_ACCE
2810: 53 53 20 7c 20 44 55 50 4c 49 43 41 54 45 5f 43  SS | DUPLICATE_C
2820: 4c 4f 53 45 5f 53 4f 55 52 43 45 29 3b 0a 0a 20  LOSE_SOURCE);.. 
2830: 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 42 61 73     /*.     * Bas
2840: 65 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 2e 0a  e command line..
2850: 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 6c 73 74       */..    lst
2860: 72 63 70 79 28 63 6d 64 6c 69 6e 65 2c 20 22 6c  rcpy(cmdline, "l
2870: 69 6e 6b 2e 65 78 65 20 2d 6e 6f 6c 6f 67 6f 20  ink.exe -nologo 
2880: 22 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20  ");..    /*.    
2890: 20 2a 20 41 70 70 65 6e 64 20 6f 75 72 20 6f 70   * Append our op
28a0: 74 69 6f 6e 20 66 6f 72 20 74 65 73 74 69 6e 67  tion for testing
28b0: 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20 20 20 66  ..     */..    f
28c0: 6f 72 20 28 69 20 3d 20 30 3b 20 69 20 3c 20 63  or (i = 0; i < c
28d0: 6f 75 6e 74 3b 20 69 2b 2b 29 20 7b 0a 09 6c 73  ount; i++) {..ls
28e0: 74 72 63 61 74 28 63 6d 64 6c 69 6e 65 2c 20 22  trcat(cmdline, "
28f0: 20 5c 22 22 29 3b 0a 09 6c 73 74 72 63 61 74 28   \"");..lstrcat(
2900: 63 6d 64 6c 69 6e 65 2c 20 6f 70 74 69 6f 6e 73  cmdline, options
2910: 5b 69 5d 29 3b 0a 09 6c 73 74 72 63 61 74 28 63  [i]);..lstrcat(c
2920: 6d 64 6c 69 6e 65 2c 20 22 5c 22 22 29 3b 0a 20  mdline, "\"");. 
2930: 20 20 20 7d 0a 0a 20 20 20 20 6f 6b 20 3d 20 43     }..    ok = C
2940: 72 65 61 74 65 50 72 6f 63 65 73 73 28 0a 09 20  reateProcess(.. 
2950: 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20     NULL,.    /* 
2960: 4d 6f 64 75 6c 65 20 6e 61 6d 65 2e 20 2a 2f 0a  Module name. */.
2970: 09 20 20 20 20 63 6d 64 6c 69 6e 65 2c 09 20 20  .    cmdline,.  
2980: 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20 6c 69 6e    /* Command lin
2990: 65 2e 20 2a 2f 0a 09 20 20 20 20 4e 55 4c 4c 2c  e. */..    NULL,
29a0: 09 20 20 20 20 2f 2a 20 50 72 6f 63 65 73 73 20  .    /* Process 
29b0: 68 61 6e 64 6c 65 20 6e 6f 74 20 69 6e 68 65 72  handle not inher
29c0: 69 74 61 62 6c 65 2e 20 2a 2f 0a 09 20 20 20 20  itable. */..    
29d0: 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 54 68 72  NULL,.    /* Thr
29e0: 65 61 64 20 68 61 6e 64 6c 65 20 6e 6f 74 20 69  ead handle not i
29f0: 6e 68 65 72 69 74 61 62 6c 65 2e 20 2a 2f 0a 09  nheritable. */..
2a00: 20 20 20 20 54 52 55 45 2c 09 20 20 20 20 2f 2a      TRUE,.    /*
2a10: 20 79 65 73 2c 20 69 6e 68 65 72 69 74 20 68 61   yes, inherit ha
2a20: 6e 64 6c 65 73 2e 20 2a 2f 0a 09 20 20 20 20 44  ndles. */..    D
2a30: 45 54 41 43 48 45 44 5f 50 52 4f 43 45 53 53 2c  ETACHED_PROCESS,
2a40: 20 2f 2a 20 4e 6f 20 63 6f 6e 73 6f 6c 65 20 66   /* No console f
2a50: 6f 72 20 79 6f 75 2e 20 2a 2f 0a 09 20 20 20 20  or you. */..    
2a60: 4e 55 4c 4c 2c 09 20 20 20 20 2f 2a 20 55 73 65  NULL,.    /* Use
2a70: 20 70 61 72 65 6e 74 27 73 20 65 6e 76 69 72 6f   parent's enviro
2a80: 6e 6d 65 6e 74 20 62 6c 6f 63 6b 2e 20 2a 2f 0a  nment block. */.
2a90: 09 20 20 20 20 4e 55 4c 4c 2c 09 20 20 20 20 2f  .    NULL,.    /
2aa0: 2a 20 55 73 65 20 70 61 72 65 6e 74 27 73 20 73  * Use parent's s
2ab0: 74 61 72 74 69 6e 67 20 64 69 72 65 63 74 6f 72  tarting director
2ac0: 79 2e 20 2a 2f 0a 09 20 20 20 20 26 73 69 2c 09  y. */..    &si,.
2ad0: 20 20 20 20 2f 2a 20 50 6f 69 6e 74 65 72 20 74      /* Pointer t
2ae0: 6f 20 53 54 41 52 54 55 50 49 4e 46 4f 20 73 74  o STARTUPINFO st
2af0: 72 75 63 74 75 72 65 2e 20 2a 2f 0a 09 20 20 20  ructure. */..   
2b00: 20 26 70 69 29 3b 09 20 20 20 20 2f 2a 20 50 6f   &pi);.    /* Po
2b10: 69 6e 74 65 72 20 74 6f 20 50 52 4f 43 45 53 53  inter to PROCESS
2b20: 5f 49 4e 46 4f 52 4d 41 54 49 4f 4e 20 73 74 72  _INFORMATION str
2b30: 75 63 74 75 72 65 2e 20 2a 2f 0a 0a 20 20 20 20  ucture. */..    
2b40: 69 66 20 28 21 6f 6b 29 20 7b 0a 09 44 57 4f 52  if (!ok) {..DWOR
2b50: 44 20 65 72 72 20 3d 20 47 65 74 4c 61 73 74 45  D err = GetLastE
2b60: 72 72 6f 72 28 29 3b 0a 09 69 6e 74 20 63 68 61  rror();..int cha
2b70: 72 73 20 3d 20 73 6e 70 72 69 6e 74 66 28 6d 73  rs = snprintf(ms
2b80: 67 2c 20 73 69 7a 65 6f 66 28 6d 73 67 29 20 2d  g, sizeof(msg) -
2b90: 20 31 2c 0a 09 09 22 54 72 69 65 64 20 74 6f 20   1,..."Tried to 
2ba0: 6c 61 75 6e 63 68 3a 20 5c 22 25 73 5c 22 2c 20  launch: \"%s\", 
2bb0: 62 75 74 20 67 6f 74 20 65 72 72 6f 72 20 5b 25  but got error [%
2bc0: 6c 75 5d 3a 20 22 2c 20 63 6d 64 6c 69 6e 65 2c  lu]: ", cmdline,
2bd0: 20 65 72 72 29 3b 0a 0a 09 46 6f 72 6d 61 74 4d   err);...FormatM
2be0: 65 73 73 61 67 65 28 46 4f 52 4d 41 54 5f 4d 45  essage(FORMAT_ME
2bf0: 53 53 41 47 45 5f 46 52 4f 4d 5f 53 59 53 54 45  SSAGE_FROM_SYSTE
2c00: 4d 7c 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47 45  M|FORMAT_MESSAGE
2c10: 5f 49 47 4e 4f 52 45 5f 49 4e 53 45 52 54 53 7c  _IGNORE_INSERTS|
2c20: 0a 09 09 46 4f 52 4d 41 54 5f 4d 45 53 53 41 47  ...FORMAT_MESSAG
2c30: 45 5f 4d 41 58 5f 57 49 44 54 48 5f 4d 41 53 4b  E_MAX_WIDTH_MASK
2c40: 2c 20 30 4c 2c 20 65 72 72 2c 20 30 2c 20 28 4c  , 0L, err, 0, (L
2c50: 50 53 54 52 29 26 6d 73 67 5b 63 68 61 72 73 5d  PSTR)&msg[chars]
2c60: 2c 0a 09 09 28 33 30 30 2d 63 68 61 72 73 29 2c  ,...(300-chars),
2c70: 20 30 29 3b 0a 09 57 72 69 74 65 46 69 6c 65 28   0);..WriteFile(
2c80: 47 65 74 53 74 64 48 61 6e 64 6c 65 28 53 54 44  GetStdHandle(STD
2c90: 5f 45 52 52 4f 52 5f 48 41 4e 44 4c 45 29 2c 20  _ERROR_HANDLE), 
2ca0: 6d 73 67 2c 20 6c 73 74 72 6c 65 6e 28 6d 73 67  msg, lstrlen(msg
2cb0: 29 2c 20 26 65 72 72 2c 20 4e 55 4c 4c 29 3b 0a  ), &err, NULL);.
2cc0: 09 72 65 74 75 72 6e 20 32 3b 0a 20 20 20 20 7d  .return 2;.    }
2cd0: 0a 0a 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20  ..    /*.     * 
2ce0: 43 6c 6f 73 65 20 6f 75 72 20 72 65 66 65 72 65  Close our refere
2cf0: 6e 63 65 73 20 74 6f 20 74 68 65 20 77 72 69 74  nces to the writ
2d00: 65 20 68 61 6e 64 6c 65 73 20 74 68 61 74 20 68  e handles that h
2d10: 61 76 65 20 6e 6f 77 20 62 65 65 6e 20 69 6e 68  ave now been inh
2d20: 65 72 69 74 65 64 2e 0a 20 20 20 20 20 2a 2f 0a  erited..     */.
2d30: 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65  .    CloseHandle
2d40: 28 73 69 2e 68 53 74 64 4f 75 74 70 75 74 29 3b  (si.hStdOutput);
2d50: 0a 20 20 20 20 43 6c 6f 73 65 48 61 6e 64 6c 65  .    CloseHandle
2d60: 28 73 69 2e 68 53 74 64 45 72 72 6f 72 29 3b 0a  (si.hStdError);.
2d70: 0a 20 20 20 20 57 61 69 74 46 6f 72 49 6e 70 75  .    WaitForInpu
2d80: 74 49 64 6c 65 28 70 69 2e 68 50 72 6f 63 65 73  tIdle(pi.hProces
2d90: 73 2c 20 35 30 30 30 29 3b 0a 20 20 20 20 43 6c  s, 5000);.    Cl
2da0: 6f 73 65 48 61 6e 64 6c 65 28 70 69 2e 68 54 68  oseHandle(pi.hTh
2db0: 72 65 61 64 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20  read);..    /*. 
2dc0: 20 20 20 20 2a 20 53 74 61 72 74 20 74 68 65 20      * Start the 
2dd0: 70 69 70 65 20 72 65 61 64 65 72 20 74 68 72 65  pipe reader thre
2de0: 61 64 73 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20  ads..     */..  
2df0: 20 20 70 69 70 65 54 68 72 65 61 64 73 5b 30 5d    pipeThreads[0]
2e00: 20 3d 20 43 72 65 61 74 65 54 68 72 65 61 64 28   = CreateThread(
2e10: 4e 55 4c 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f  NULL, 0, ReadFro
2e20: 6d 50 69 70 65 2c 20 26 4f 75 74 2c 20 30 2c 20  mPipe, &Out, 0, 
2e30: 26 74 68 72 65 61 64 49 44 29 3b 0a 20 20 20 20  &threadID);.    
2e40: 70 69 70 65 54 68 72 65 61 64 73 5b 31 5d 20 3d  pipeThreads[1] =
2e50: 20 43 72 65 61 74 65 54 68 72 65 61 64 28 4e 55   CreateThread(NU
2e60: 4c 4c 2c 20 30 2c 20 52 65 61 64 46 72 6f 6d 50  LL, 0, ReadFromP
2e70: 69 70 65 2c 20 26 45 72 72 2c 20 30 2c 20 26 74  ipe, &Err, 0, &t
2e80: 68 72 65 61 64 49 44 29 3b 0a 0a 20 20 20 20 2f  hreadID);..    /
2e90: 2a 0a 20 20 20 20 20 2a 20 42 6c 6f 63 6b 20 77  *.     * Block w
2ea0: 61 69 74 69 6e 67 20 66 6f 72 20 74 68 65 20 70  aiting for the p
2eb0: 72 6f 63 65 73 73 20 74 6f 20 65 6e 64 2e 0a 20  rocess to end.. 
2ec0: 20 20 20 20 2a 2f 0a 0a 20 20 20 20 57 61 69 74      */..    Wait
2ed0: 46 6f 72 53 69 6e 67 6c 65 4f 62 6a 65 63 74 28  ForSingleObject(
2ee0: 70 69 2e 68 50 72 6f 63 65 73 73 2c 20 49 4e 46  pi.hProcess, INF
2ef0: 49 4e 49 54 45 29 3b 0a 20 20 20 20 43 6c 6f 73  INITE);.    Clos
2f00: 65 48 61 6e 64 6c 65 28 70 69 2e 68 50 72 6f 63  eHandle(pi.hProc
2f10: 65 73 73 29 3b 0a 0a 20 20 20 20 2f 2a 0a 20 20  ess);..    /*.  
2f20: 20 20 20 2a 20 57 61 69 74 20 66 6f 72 20 6f 75     * Wait for ou
2f30: 72 20 70 69 70 65 20 74 6f 20 67 65 74 20 64 6f  r pipe to get do
2f40: 6e 65 20 72 65 61 64 69 6e 67 2c 20 73 68 6f 75  ne reading, shou
2f50: 6c 64 20 69 74 20 62 65 20 61 20 6c 69 74 74 6c  ld it be a littl
2f60: 65 20 73 6c 6f 77 2e 0a 20 20 20 20 20 2a 2f 0a  e slow..     */.
2f70: 0a 20 20 20 20 57 61 69 74 46 6f 72 4d 75 6c 74  .    WaitForMult
2f80: 69 70 6c 65 4f 62 6a 65 63 74 73 28 32 2c 20 70  ipleObjects(2, p
2f90: 69 70 65 54 68 72 65 61 64 73 2c 20 54 52 55 45  ipeThreads, TRUE
2fa0: 2c 20 35 30 30 29 3b 0a 20 20 20 20 43 6c 6f 73  , 500);.    Clos
2fb0: 65 48 61 6e 64 6c 65 28 70 69 70 65 54 68 72 65  eHandle(pipeThre
2fc0: 61 64 73 5b 30 5d 29 3b 0a 20 20 20 20 43 6c 6f  ads[0]);.    Clo
2fd0: 73 65 48 61 6e 64 6c 65 28 70 69 70 65 54 68 72  seHandle(pipeThr
2fe0: 65 61 64 73 5b 31 5d 29 3b 0a 0a 20 20 20 20 2f  eads[1]);..    /
2ff0: 2a 0a 20 20 20 20 20 2a 20 4c 6f 6f 6b 20 66 6f  *.     * Look fo
3000: 72 20 74 68 65 20 63 6f 6d 6d 61 6e 64 6c 69 6e  r the commandlin
3010: 65 20 77 61 72 6e 69 6e 67 20 63 6f 64 65 20 69  e warning code i
3020: 6e 20 74 68 65 20 73 74 64 65 72 72 20 73 74 72  n the stderr str
3030: 65 61 6d 2e 0a 20 20 20 20 20 2a 2f 0a 0a 20 20  eam..     */..  
3040: 20 20 72 65 74 75 72 6e 20 21 28 73 74 72 73 74    return !(strst
3050: 72 28 4f 75 74 2e 62 75 66 66 65 72 2c 20 22 4c  r(Out.buffer, "L
3060: 4e 4b 31 31 31 37 22 29 20 21 3d 20 4e 55 4c 4c  NK1117") != NULL
3070: 20 7c 7c 0a 09 20 20 20 20 73 74 72 73 74 72 28   ||..    strstr(
3080: 45 72 72 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b  Err.buffer, "LNK
3090: 31 31 31 37 22 29 20 21 3d 20 4e 55 4c 4c 20 7c  1117") != NULL |
30a0: 7c 0a 09 20 20 20 20 73 74 72 73 74 72 28 4f 75  |..    strstr(Ou
30b0: 74 2e 62 75 66 66 65 72 2c 20 22 4c 4e 4b 34 30  t.buffer, "LNK40
30c0: 34 34 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a  44") != NULL ||.
30d0: 09 20 20 20 20 73 74 72 73 74 72 28 45 72 72 2e  .    strstr(Err.
30e0: 62 75 66 66 65 72 2c 20 22 4c 4e 4b 34 30 34 34  buffer, "LNK4044
30f0: 22 29 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 20  ") != NULL ||.. 
3100: 20 20 20 73 74 72 73 74 72 28 4f 75 74 2e 62 75     strstr(Out.bu
3110: 66 66 65 72 2c 20 22 4c 4e 4b 34 32 32 34 22 29  ffer, "LNK4224")
3120: 20 21 3d 20 4e 55 4c 4c 20 7c 7c 0a 09 20 20 20   != NULL ||..   
3130: 20 73 74 72 73 74 72 28 45 72 72 2e 62 75 66 66   strstr(Err.buff
3140: 65 72 2c 20 22 4c 4e 4b 34 32 32 34 22 29 20 21  er, "LNK4224") !
3150: 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a 0c 0a 73 74 61  = NULL);.}...sta
3160: 74 69 63 20 44 57 4f 52 44 20 57 49 4e 41 50 49  tic DWORD WINAPI
3170: 0a 52 65 61 64 46 72 6f 6d 50 69 70 65 28 0a 20  .ReadFromPipe(. 
3180: 20 20 20 4c 50 56 4f 49 44 20 61 72 67 73 29 0a     LPVOID args).
3190: 7b 0a 20 20 20 20 70 69 70 65 69 6e 66 6f 20 2a  {.    pipeinfo *
31a0: 70 69 20 3d 20 28 70 69 70 65 69 6e 66 6f 20 2a  pi = (pipeinfo *
31b0: 29 20 61 72 67 73 3b 0a 20 20 20 20 63 68 61 72  ) args;.    char
31c0: 20 2a 6c 61 73 74 42 75 66 20 3d 20 70 69 2d 3e   *lastBuf = pi->
31d0: 62 75 66 66 65 72 3b 0a 20 20 20 20 44 57 4f 52  buffer;.    DWOR
31e0: 44 20 64 77 52 65 61 64 3b 0a 20 20 20 20 42 4f  D dwRead;.    BO
31f0: 4f 4c 20 6f 6b 3b 0a 0a 20 20 61 67 61 69 6e 3a  OL ok;..  again:
3200: 0a 20 20 20 20 69 66 20 28 6c 61 73 74 42 75 66  .    if (lastBuf
3210: 20 2d 20 70 69 2d 3e 62 75 66 66 65 72 20 2b 20   - pi->buffer + 
3220: 43 48 55 4e 4b 20 3e 20 53 54 41 54 49 43 42 55  CHUNK > STATICBU
3230: 46 46 45 52 53 49 5a 45 29 20 7b 0a 09 43 6c 6f  FFERSIZE) {..Clo
3240: 73 65 48 61 6e 64 6c 65 28 70 69 2d 3e 70 69 70  seHandle(pi->pip
3250: 65 29 3b 0a 09 72 65 74 75 72 6e 20 28 44 57 4f  e);..return (DWO
3260: 52 44 29 2d 31 3b 0a 20 20 20 20 7d 0a 20 20 20  RD)-1;.    }.   
3270: 20 6f 6b 20 3d 20 52 65 61 64 46 69 6c 65 28 70   ok = ReadFile(p
3280: 69 2d 3e 70 69 70 65 2c 20 6c 61 73 74 42 75 66  i->pipe, lastBuf
3290: 2c 20 43 48 55 4e 4b 2c 20 26 64 77 52 65 61 64  , CHUNK, &dwRead
32a0: 2c 20 30 4c 29 3b 0a 20 20 20 20 69 66 20 28 21  , 0L);.    if (!
32b0: 6f 6b 20 7c 7c 20 64 77 52 65 61 64 20 3d 3d 20  ok || dwRead == 
32c0: 30 29 20 7b 0a 09 43 6c 6f 73 65 48 61 6e 64 6c  0) {..CloseHandl
32d0: 65 28 70 69 2d 3e 70 69 70 65 29 3b 0a 09 72 65  e(pi->pipe);..re
32e0: 74 75 72 6e 20 30 3b 0a 20 20 20 20 7d 0a 20 20  turn 0;.    }.  
32f0: 20 20 6c 61 73 74 42 75 66 20 2b 3d 20 64 77 52    lastBuf += dwR
3300: 65 61 64 3b 0a 20 20 20 20 67 6f 74 6f 20 61 67  ead;.    goto ag
3310: 61 69 6e 3b 0a 0a 20 20 20 20 72 65 74 75 72 6e  ain;..    return
3320: 20 30 3b 20 20 2f 2a 20 6d 61 6b 65 73 20 74 68   0;  /* makes th
3330: 65 20 63 6f 6d 70 69 6c 65 72 20 68 61 70 70 79  e compiler happy
3340: 20 2a 2f 0a 7d 0a 0c 0a 73 74 61 74 69 63 20 69   */.}...static i
3350: 6e 74 0a 49 73 49 6e 28 0a 20 20 20 20 63 6f 6e  nt.IsIn(.    con
3360: 73 74 20 63 68 61 72 20 2a 73 74 72 69 6e 67 2c  st char *string,
3370: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
3380: 2a 73 75 62 73 74 72 69 6e 67 29 0a 7b 0a 20 20  *substring).{.  
3390: 20 20 72 65 74 75 72 6e 20 28 73 74 72 73 74 72    return (strstr
33a0: 28 73 74 72 69 6e 67 2c 20 73 75 62 73 74 72 69  (string, substri
33b0: 6e 67 29 20 21 3d 20 4e 55 4c 4c 29 3b 0a 7d 0a  ng) != NULL);.}.
33c0: 0c 0a 2f 2a 0a 20 2a 20 47 65 74 56 65 72 73 69  ../*. * GetVersi
33d0: 6f 6e 46 72 6f 6d 46 69 6c 65 20 2d 2d 0a 20 2a  onFromFile --. *
33e0: 09 4c 6f 6f 6b 73 20 66 6f 72 20 61 20 6d 61 74  .Looks for a mat
33f0: 63 68 20 73 74 72 69 6e 67 20 69 6e 20 61 20 66  ch string in a f
3400: 69 6c 65 20 61 6e 64 20 74 68 65 6e 20 72 65 74  ile and then ret
3410: 75 72 6e 73 20 74 68 65 20 76 65 72 73 69 6f 6e  urns the version
3420: 0a 20 2a 09 66 6f 6c 6c 6f 77 69 6e 67 20 74 68  . *.following th
3430: 65 20 6d 61 74 63 68 20 77 68 65 72 65 20 61 20  e match where a 
3440: 76 65 72 73 69 6f 6e 20 69 73 20 61 6e 79 74 68  version is anyth
3450: 69 6e 67 20 61 63 63 65 70 74 61 62 6c 65 20 74  ing acceptable t
3460: 6f 0a 20 2a 09 70 61 63 6b 61 67 65 20 70 72 6f  o. *.package pro
3470: 76 69 64 65 20 6f 72 20 70 61 63 6b 61 67 65 20  vide or package 
3480: 69 66 6e 65 65 64 65 64 2e 0a 20 2a 2f 0a 0a 73  ifneeded.. */..s
3490: 74 61 74 69 63 20 63 6f 6e 73 74 20 63 68 61 72  tatic const char
34a0: 20 2a 0a 47 65 74 56 65 72 73 69 6f 6e 46 72 6f   *.GetVersionFro
34b0: 6d 46 69 6c 65 28 0a 20 20 20 20 63 6f 6e 73 74  mFile(.    const
34c0: 20 63 68 61 72 20 2a 66 69 6c 65 6e 61 6d 65 2c   char *filename,
34d0: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20  .    const char 
34e0: 2a 6d 61 74 63 68 2c 0a 20 20 20 20 69 6e 74 20  *match,.    int 
34f0: 6e 75 6d 64 6f 74 73 29 0a 7b 0a 20 20 20 20 73  numdots).{.    s
3500: 74 61 74 69 63 20 63 68 61 72 20 73 7a 42 75 66  tatic char szBuf
3510: 66 65 72 5b 31 30 30 5d 3b 0a 20 20 20 20 63 68  fer[100];.    ch
3520: 61 72 20 2a 73 7a 52 65 73 75 6c 74 20 3d 20 4e  ar *szResult = N
3530: 55 4c 4c 3b 0a 20 20 20 20 46 49 4c 45 20 2a 66  ULL;.    FILE *f
3540: 70 20 3d 20 66 6f 70 65 6e 28 66 69 6c 65 6e 61  p = fopen(filena
3550: 6d 65 2c 20 22 72 74 22 29 3b 0a 0a 20 20 20 20  me, "rt");..    
3560: 69 66 20 28 66 70 20 21 3d 20 4e 55 4c 4c 29 20  if (fp != NULL) 
3570: 7b 0a 09 2f 2a 0a 09 20 2a 20 52 65 61 64 20 64  {../*.. * Read d
3580: 61 74 61 20 75 6e 74 69 6c 20 77 65 20 73 65 65  ata until we see
3590: 20 6f 75 72 20 6d 61 74 63 68 20 73 74 72 69 6e   our match strin
35a0: 67 2e 0a 09 20 2a 2f 0a 0a 09 77 68 69 6c 65 20  g... */...while 
35b0: 28 66 67 65 74 73 28 73 7a 42 75 66 66 65 72 2c  (fgets(szBuffer,
35c0: 20 73 69 7a 65 6f 66 28 73 7a 42 75 66 66 65 72   sizeof(szBuffer
35d0: 29 2c 20 66 70 29 20 21 3d 20 4e 55 4c 4c 29 20  ), fp) != NULL) 
35e0: 7b 0a 09 20 20 20 20 4c 50 53 54 52 20 70 2c 20  {..    LPSTR p, 
35f0: 71 3b 0a 0a 09 20 20 20 20 70 20 3d 20 73 74 72  q;...    p = str
3600: 73 74 72 28 73 7a 42 75 66 66 65 72 2c 20 6d 61  str(szBuffer, ma
3610: 74 63 68 29 3b 0a 09 20 20 20 20 69 66 20 28 70  tch);..    if (p
3620: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 2f 2a   != NULL) {.../*
3630: 0a 09 09 20 2a 20 53 6b 69 70 20 74 6f 20 66 69  ... * Skip to fi
3640: 72 73 74 20 64 69 67 69 74 20 61 66 74 65 72 20  rst digit after 
3650: 74 68 65 20 6d 61 74 63 68 2e 0a 09 09 20 2a 2f  the match.... */
3660: 0a 0a 09 09 70 20 2b 3d 20 73 74 72 6c 65 6e 28  ....p += strlen(
3670: 6d 61 74 63 68 29 3b 0a 09 09 77 68 69 6c 65 20  match);...while 
3680: 28 2a 70 20 26 26 20 21 69 73 64 69 67 69 74 28  (*p && !isdigit(
3690: 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 29 2a  (unsigned char)*
36a0: 70 29 29 20 7b 0a 09 09 20 20 20 20 2b 2b 70 3b  p)) {...    ++p;
36b0: 0a 09 09 7d 0a 0a 09 09 2f 2a 0a 09 09 20 2a 20  ...}..../*... * 
36c0: 46 69 6e 64 20 65 6e 64 69 6e 67 20 77 68 69 74  Find ending whit
36d0: 65 73 70 61 63 65 2e 0a 09 09 20 2a 2f 0a 0a 09  espace.... */...
36e0: 09 71 20 3d 20 70 3b 0a 09 09 77 68 69 6c 65 20  .q = p;...while 
36f0: 28 2a 71 20 26 26 20 28 73 74 72 63 68 72 28 22  (*q && (strchr("
3700: 30 31 32 33 34 35 36 37 38 39 2e 61 62 22 2c 20  0123456789.ab", 
3710: 2a 71 29 29 20 26 26 20 28 28 28 21 73 74 72 63  *q)) && (((!strc
3720: 68 72 28 22 2e 61 62 22 2c 20 2a 71 29 0a 09 09  hr(".ab", *q)...
3730: 09 20 20 20 20 26 26 20 21 73 74 72 63 68 72 28  .    && !strchr(
3740: 22 61 62 22 2c 20 71 5b 2d 31 5d 29 29 20 7c 7c  "ab", q[-1])) ||
3750: 20 2d 2d 6e 75 6d 64 6f 74 73 29 29 29 20 7b 0a   --numdots))) {.
3760: 09 09 20 20 20 20 2b 2b 71 3b 0a 09 09 7d 0a 0a  ..    ++q;...}..
3770: 09 09 2a 71 20 3d 20 30 3b 0a 09 09 73 7a 52 65  ..*q = 0;...szRe
3780: 73 75 6c 74 20 3d 20 70 3b 0a 09 09 62 72 65 61  sult = p;...brea
3790: 6b 3b 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 66 63  k;..    }..}..fc
37a0: 6c 6f 73 65 28 66 70 29 3b 0a 20 20 20 20 7d 0a  lose(fp);.    }.
37b0: 20 20 20 20 72 65 74 75 72 6e 20 73 7a 52 65 73      return szRes
37c0: 75 6c 74 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 4c  ult;.}.../*. * L
37d0: 69 73 74 20 68 65 6c 70 65 72 73 20 66 6f 72 20  ist helpers for 
37e0: 74 68 65 20 53 75 62 73 74 69 74 75 74 65 46 69  the SubstituteFi
37f0: 6c 65 20 66 75 6e 63 74 69 6f 6e 0a 20 2a 2f 0a  le function. */.
3800: 0a 74 79 70 65 64 65 66 20 73 74 72 75 63 74 20  .typedef struct 
3810: 6c 69 73 74 5f 69 74 65 6d 5f 74 20 7b 0a 20 20  list_item_t {.  
3820: 20 20 73 74 72 75 63 74 20 6c 69 73 74 5f 69 74    struct list_it
3830: 65 6d 5f 74 20 2a 6e 65 78 74 50 74 72 3b 0a 20  em_t *nextPtr;. 
3840: 20 20 20 63 68 61 72 20 2a 20 6b 65 79 3b 0a 20     char * key;. 
3850: 20 20 20 63 68 61 72 20 2a 20 76 61 6c 75 65 3b     char * value;
3860: 0a 7d 20 6c 69 73 74 5f 69 74 65 6d 5f 74 3b 0a  .} list_item_t;.
3870: 0a 2f 2a 20 69 6e 73 65 72 74 20 61 20 6c 69 73  ./* insert a lis
3880: 74 20 69 74 65 6d 20 69 6e 74 6f 20 74 68 65 20  t item into the 
3890: 6c 69 73 74 20 28 6c 69 73 74 20 6d 61 79 20 62  list (list may b
38a0: 65 20 6e 75 6c 6c 29 20 2a 2f 0a 73 74 61 74 69  e null) */.stati
38b0: 63 20 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 0a  c list_item_t *.
38c0: 6c 69 73 74 5f 69 6e 73 65 72 74 28 6c 69 73 74  list_insert(list
38d0: 5f 69 74 65 6d 5f 74 20 2a 2a 6c 69 73 74 50 74  _item_t **listPt
38e0: 72 50 74 72 2c 20 63 6f 6e 73 74 20 63 68 61 72  rPtr, const char
38f0: 20 2a 6b 65 79 2c 20 63 6f 6e 73 74 20 63 68 61   *key, const cha
3900: 72 20 2a 76 61 6c 75 65 29 0a 7b 0a 20 20 20 20  r *value).{.    
3910: 6c 69 73 74 5f 69 74 65 6d 5f 74 20 2a 69 74 65  list_item_t *ite
3920: 6d 50 74 72 20 3d 20 28 6c 69 73 74 5f 69 74 65  mPtr = (list_ite
3930: 6d 5f 74 20 2a 29 6d 61 6c 6c 6f 63 28 73 69 7a  m_t *)malloc(siz
3940: 65 6f 66 28 6c 69 73 74 5f 69 74 65 6d 5f 74 29  eof(list_item_t)
3950: 29 3b 0a 20 20 20 20 69 66 20 28 69 74 65 6d 50  );.    if (itemP
3960: 74 72 29 20 7b 0a 09 69 74 65 6d 50 74 72 2d 3e  tr) {..itemPtr->
3970: 6b 65 79 20 3d 20 73 74 72 64 75 70 28 6b 65 79  key = strdup(key
3980: 29 3b 0a 09 69 74 65 6d 50 74 72 2d 3e 76 61 6c  );..itemPtr->val
3990: 75 65 20 3d 20 73 74 72 64 75 70 28 76 61 6c 75  ue = strdup(valu
39a0: 65 29 3b 0a 09 69 74 65 6d 50 74 72 2d 3e 6e 65  e);..itemPtr->ne
39b0: 78 74 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 0a 09  xtPtr = NULL;...
39c0: 77 68 69 6c 65 28 2a 6c 69 73 74 50 74 72 50 74  while(*listPtrPt
39d0: 72 29 20 7b 0a 09 20 20 20 20 6c 69 73 74 50 74  r) {..    listPt
39e0: 72 50 74 72 20 3d 20 26 28 2a 6c 69 73 74 50 74  rPtr = &(*listPt
39f0: 72 50 74 72 29 2d 3e 6e 65 78 74 50 74 72 3b 0a  rPtr)->nextPtr;.
3a00: 09 7d 0a 09 2a 6c 69 73 74 50 74 72 50 74 72 20  .}..*listPtrPtr 
3a10: 3d 20 69 74 65 6d 50 74 72 3b 0a 20 20 20 20 7d  = itemPtr;.    }
3a20: 0a 20 20 20 20 72 65 74 75 72 6e 20 69 74 65 6d  .    return item
3a30: 50 74 72 3b 0a 7d 0a 0a 73 74 61 74 69 63 20 76  Ptr;.}..static v
3a40: 6f 69 64 0a 6c 69 73 74 5f 66 72 65 65 28 6c 69  oid.list_free(li
3a50: 73 74 5f 69 74 65 6d 5f 74 20 2a 2a 6c 69 73 74  st_item_t **list
3a60: 50 74 72 50 74 72 29 0a 7b 0a 20 20 20 20 6c 69  PtrPtr).{.    li
3a70: 73 74 5f 69 74 65 6d 5f 74 20 2a 74 6d 70 50 74  st_item_t *tmpPt
3a80: 72 2c 20 2a 6c 69 73 74 50 74 72 20 3d 20 2a 6c  r, *listPtr = *l
3a90: 69 73 74 50 74 72 50 74 72 3b 0a 20 20 20 20 77  istPtrPtr;.    w
3aa0: 68 69 6c 65 20 28 6c 69 73 74 50 74 72 29 20 7b  hile (listPtr) {
3ab0: 0a 09 74 6d 70 50 74 72 20 3d 20 6c 69 73 74 50  ..tmpPtr = listP
3ac0: 74 72 3b 0a 09 6c 69 73 74 50 74 72 20 3d 20 6c  tr;..listPtr = l
3ad0: 69 73 74 50 74 72 2d 3e 6e 65 78 74 50 74 72 3b  istPtr->nextPtr;
3ae0: 0a 09 66 72 65 65 28 74 6d 70 50 74 72 2d 3e 6b  ..free(tmpPtr->k
3af0: 65 79 29 3b 0a 09 66 72 65 65 28 74 6d 70 50 74  ey);..free(tmpPt
3b00: 72 2d 3e 76 61 6c 75 65 29 3b 0a 09 66 72 65 65  r->value);..free
3b10: 28 74 6d 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a  (tmpPtr);.    }.
3b20: 7d 0a 0c 0a 2f 2a 0a 20 2a 20 53 75 62 73 74 69  }.../*. * Substi
3b30: 74 75 74 65 46 69 6c 65 20 2d 2d 0a 20 2a 09 41  tuteFile --. *.A
3b40: 73 20 77 69 6e 64 6f 77 73 20 64 6f 65 73 6e 27  s windows doesn'
3b50: 74 20 70 72 6f 76 69 64 65 20 61 6e 79 74 68 69  t provide anythi
3b60: 6e 67 20 75 73 65 66 75 6c 20 6c 69 6b 65 20 73  ng useful like s
3b70: 65 64 20 61 6e 64 20 69 74 27 73 20 75 6e 72 65  ed and it's unre
3b80: 6c 69 61 62 6c 65 0a 20 2a 09 74 6f 20 75 73 65  liable. *.to use
3b90: 20 74 68 65 20 74 63 6c 73 68 20 79 6f 75 20 61   the tclsh you a
3ba0: 72 65 20 62 75 69 6c 64 69 6e 67 20 61 67 61 69  re building agai
3bb0: 6e 73 74 20 28 63 6f 6e 73 69 64 65 72 20 78 2d  nst (consider x-
3bc0: 70 6c 61 74 66 6f 72 6d 20 62 75 69 6c 64 73 20  platform builds 
3bd0: 2d 0a 20 2a 09 65 2e 67 2e 20 63 6f 6d 70 69 6c  -. *.e.g. compil
3be0: 69 6e 67 20 41 4d 44 36 34 20 74 61 72 67 65 74  ing AMD64 target
3bf0: 20 66 72 6f 6d 20 49 58 38 36 29 20 77 65 20 70   from IX86) we p
3c00: 72 6f 76 69 64 65 20 61 20 73 69 6d 70 6c 65 20  rovide a simple 
3c10: 73 75 62 73 74 69 74 75 74 69 6f 6e 0a 20 2a 09  substitution. *.
3c20: 6f 70 74 69 6f 6e 20 68 65 72 65 20 74 6f 20 68  option here to h
3c30: 61 6e 64 6c 65 20 61 75 74 6f 63 6f 6e 66 20 73  andle autoconf s
3c40: 74 79 6c 65 20 73 75 62 73 74 69 74 75 74 69 6f  tyle substitutio
3c50: 6e 73 2e 0a 20 2a 09 54 68 65 20 73 75 62 73 74  ns.. *.The subst
3c60: 69 74 75 74 69 6f 6e 20 66 69 6c 65 20 69 73 20  itution file is 
3c70: 77 68 69 74 65 73 70 61 63 65 20 61 6e 64 20 6c  whitespace and l
3c80: 69 6e 65 20 64 65 6c 69 6d 69 74 65 64 2e 20 54  ine delimited. T
3c90: 68 65 20 66 69 6c 65 20 73 68 6f 75 6c 64 0a 20  he file should. 
3ca0: 2a 09 63 6f 6e 73 69 73 74 20 6f 66 20 6c 69 6e  *.consist of lin
3cb0: 65 73 20 6d 61 74 63 68 69 6e 67 20 74 68 65 20  es matching the 
3cc0: 72 65 67 75 6c 61 72 20 65 78 70 72 65 73 73 69  regular expressi
3cd0: 6f 6e 3a 0a 20 2a 09 20 20 5c 73 2a 5c 53 2b 5c  on:. *.  \s*\S+\
3ce0: 73 2b 5c 53 2a 24 0a 20 2a 0a 20 2a 09 55 73 61  s+\S*$. *. *.Usa
3cf0: 67 65 20 69 73 20 73 6f 6d 65 74 68 69 6e 67 20  ge is something 
3d00: 6c 69 6b 65 3a 0a 20 2a 09 20 20 6e 6d 61 6b 65  like:. *.  nmake
3d10: 68 6c 70 20 2d 53 20 3c 3c 20 24 2a 2a 20 3e 20  hlp -S << $** > 
3d20: 24 40 0a 20 2a 09 20 20 20 20 40 50 41 43 4b 41  $@. *.    @PACKA
3d30: 47 45 5f 4e 41 4d 45 40 20 24 28 50 41 43 4b 41  GE_NAME@ $(PACKA
3d40: 47 45 5f 4e 41 4d 45 29 0a 20 2a 09 20 20 20 20  GE_NAME). *.    
3d50: 40 50 41 43 4b 41 47 45 5f 56 45 52 53 49 4f 4e  @PACKAGE_VERSION
3d60: 40 20 24 28 50 41 43 4b 41 47 45 5f 56 45 52 53  @ $(PACKAGE_VERS
3d70: 49 4f 4e 29 0a 20 2a 09 20 20 20 20 3c 3c 0a 20  ION). *.    <<. 
3d80: 2a 2f 0a 0a 73 74 61 74 69 63 20 69 6e 74 0a 53  */..static int.S
3d90: 75 62 73 74 69 74 75 74 65 46 69 6c 65 28 0a 20  ubstituteFile(. 
3da0: 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 73     const char *s
3db0: 75 62 73 74 69 74 75 74 69 6f 6e 73 2c 0a 20 20  ubstitutions,.  
3dc0: 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 66 69    const char *fi
3dd0: 6c 65 6e 61 6d 65 29 0a 7b 0a 20 20 20 20 73 74  lename).{.    st
3de0: 61 74 69 63 20 63 68 61 72 20 73 7a 42 75 66 66  atic char szBuff
3df0: 65 72 5b 31 30 32 34 5d 2c 20 73 7a 43 6f 70 79  er[1024], szCopy
3e00: 5b 31 30 32 34 5d 3b 0a 20 20 20 20 6c 69 73 74  [1024];.    list
3e10: 5f 69 74 65 6d 5f 74 20 2a 73 75 62 73 74 50 74  _item_t *substPt
3e20: 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 46 49  r = NULL;.    FI
3e30: 4c 45 20 2a 66 70 2c 20 2a 73 70 3b 0a 0a 20 20  LE *fp, *sp;..  
3e40: 20 20 66 70 20 3d 20 66 6f 70 65 6e 28 66 69 6c    fp = fopen(fil
3e50: 65 6e 61 6d 65 2c 20 22 72 74 22 29 3b 0a 20 20  ename, "rt");.  
3e60: 20 20 69 66 20 28 66 70 20 21 3d 20 4e 55 4c 4c    if (fp != NULL
3e70: 29 20 7b 0a 0a 09 2f 2a 0a 09 20 2a 20 42 75 69  ) {.../*.. * Bui
3e80: 6c 64 20 61 20 6c 69 73 74 20 6f 66 20 73 75 62  ld a list of sub
3e90: 73 74 69 74 75 74 69 6f 6e 73 20 66 72 6f 6d 20  stitutions from 
3ea0: 74 68 65 20 66 69 72 73 74 20 66 69 6c 65 6e 61  the first filena
3eb0: 6d 65 0a 09 20 2a 2f 0a 0a 09 73 70 20 3d 20 66  me.. */...sp = f
3ec0: 6f 70 65 6e 28 73 75 62 73 74 69 74 75 74 69 6f  open(substitutio
3ed0: 6e 73 2c 20 22 72 74 22 29 3b 0a 09 69 66 20 28  ns, "rt");..if (
3ee0: 73 70 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20  sp != NULL) {.. 
3ef0: 20 20 20 77 68 69 6c 65 20 28 66 67 65 74 73 28     while (fgets(
3f00: 73 7a 42 75 66 66 65 72 2c 20 73 69 7a 65 6f 66  szBuffer, sizeof
3f10: 28 73 7a 42 75 66 66 65 72 29 2c 20 73 70 29 20  (szBuffer), sp) 
3f20: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 09 75 6e 73  != NULL) {...uns
3f30: 69 67 6e 65 64 20 63 68 61 72 20 2a 6b 73 2c 20  igned char *ks, 
3f40: 2a 6b 65 2c 20 2a 76 73 2c 20 2a 76 65 3b 0a 09  *ke, *vs, *ve;..
3f50: 09 6b 73 20 3d 20 28 75 6e 73 69 67 6e 65 64 20  .ks = (unsigned 
3f60: 63 68 61 72 2a 29 73 7a 42 75 66 66 65 72 3b 0a  char*)szBuffer;.
3f70: 09 09 77 68 69 6c 65 20 28 6b 73 20 26 26 20 2a  ..while (ks && *
3f80: 6b 73 20 26 26 20 69 73 73 70 61 63 65 28 2a 6b  ks && isspace(*k
3f90: 73 29 29 20 2b 2b 6b 73 3b 0a 09 09 6b 65 20 3d  s)) ++ks;...ke =
3fa0: 20 6b 73 3b 0a 09 09 77 68 69 6c 65 20 28 6b 65   ks;...while (ke
3fb0: 20 26 26 20 2a 6b 65 20 26 26 20 21 69 73 73 70   && *ke && !issp
3fc0: 61 63 65 28 2a 6b 65 29 29 20 2b 2b 6b 65 3b 0a  ace(*ke)) ++ke;.
3fd0: 09 09 76 73 20 3d 20 6b 65 3b 0a 09 09 77 68 69  ..vs = ke;...whi
3fe0: 6c 65 20 28 76 73 20 26 26 20 2a 76 73 20 26 26  le (vs && *vs &&
3ff0: 20 69 73 73 70 61 63 65 28 2a 76 73 29 29 20 2b   isspace(*vs)) +
4000: 2b 76 73 3b 0a 09 09 76 65 20 3d 20 76 73 3b 0a  +vs;...ve = vs;.
4010: 09 09 77 68 69 6c 65 20 28 76 65 20 26 26 20 2a  ..while (ve && *
4020: 76 65 20 26 26 20 21 28 2a 76 65 20 3d 3d 20 27  ve && !(*ve == '
4030: 5c 72 27 20 7c 7c 20 2a 76 65 20 3d 3d 20 27 5c  \r' || *ve == '\
4040: 6e 27 29 29 20 2b 2b 76 65 3b 0a 09 09 2a 6b 65  n')) ++ve;...*ke
4050: 20 3d 20 30 2c 20 2a 76 65 20 3d 20 30 3b 0a 09   = 0, *ve = 0;..
4060: 09 6c 69 73 74 5f 69 6e 73 65 72 74 28 26 73 75  .list_insert(&su
4070: 62 73 74 50 74 72 2c 20 28 63 68 61 72 2a 29 6b  bstPtr, (char*)k
4080: 73 2c 20 28 63 68 61 72 2a 29 76 73 29 3b 0a 09  s, (char*)vs);..
4090: 20 20 20 20 7d 0a 09 20 20 20 20 66 63 6c 6f 73      }..    fclos
40a0: 65 28 73 70 29 3b 0a 09 7d 0a 0a 09 2f 2a 20 64  e(sp);..}.../* d
40b0: 65 62 75 67 3a 20 64 75 6d 70 20 74 68 65 20 6c  ebug: dump the l
40c0: 69 73 74 20 2a 2f 0a 23 69 66 6e 64 65 66 20 4e  ist */.#ifndef N
40d0: 44 45 42 55 47 0a 09 7b 0a 09 20 20 20 20 69 6e  DEBUG..{..    in
40e0: 74 20 6e 20 3d 20 30 3b 0a 09 20 20 20 20 6c 69  t n = 0;..    li
40f0: 73 74 5f 69 74 65 6d 5f 74 20 2a 70 20 3d 20 4e  st_item_t *p = N
4100: 55 4c 4c 3b 0a 09 20 20 20 20 66 6f 72 20 28 70  ULL;..    for (p
4110: 20 3d 20 73 75 62 73 74 50 74 72 3b 20 70 20 21   = substPtr; p !
4120: 3d 20 4e 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e 6e  = NULL; p = p->n
4130: 65 78 74 50 74 72 2c 20 2b 2b 6e 29 20 7b 0a 09  extPtr, ++n) {..
4140: 09 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c  .fprintf(stderr,
4150: 20 22 25 20 33 64 20 27 25 73 27 20 3d 3e 20 27   "% 3d '%s' => '
4160: 25 73 27 5c 6e 22 2c 20 6e 2c 20 70 2d 3e 6b 65  %s'\n", n, p->ke
4170: 79 2c 20 70 2d 3e 76 61 6c 75 65 29 3b 0a 09 20  y, p->value);.. 
4180: 20 20 20 7d 0a 09 7d 0a 23 65 6e 64 69 66 0a 0a     }..}.#endif..
4190: 09 2f 2a 0a 09 20 2a 20 52 75 6e 20 74 68 65 20  ./*.. * Run the 
41a0: 73 75 62 73 74 69 74 75 74 69 6f 6e 73 20 6f 76  substitutions ov
41b0: 65 72 20 65 61 63 68 20 6c 69 6e 65 20 6f 66 20  er each line of 
41c0: 74 68 65 20 69 6e 70 75 74 0a 09 20 2a 2f 0a 0a  the input.. */..
41d0: 09 77 68 69 6c 65 20 28 66 67 65 74 73 28 73 7a  .while (fgets(sz
41e0: 42 75 66 66 65 72 2c 20 73 69 7a 65 6f 66 28 73  Buffer, sizeof(s
41f0: 7a 42 75 66 66 65 72 29 2c 20 66 70 29 20 21 3d  zBuffer), fp) !=
4200: 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 6c 69   NULL) {..    li
4210: 73 74 5f 69 74 65 6d 5f 74 20 2a 70 20 3d 20 4e  st_item_t *p = N
4220: 55 4c 4c 3b 0a 09 20 20 20 20 66 6f 72 20 28 70  ULL;..    for (p
4230: 20 3d 20 73 75 62 73 74 50 74 72 3b 20 70 20 21   = substPtr; p !
4240: 3d 20 4e 55 4c 4c 3b 20 70 20 3d 20 70 2d 3e 6e  = NULL; p = p->n
4250: 65 78 74 50 74 72 29 20 7b 0a 09 09 63 68 61 72  extPtr) {...char
4260: 20 2a 6d 20 3d 20 73 74 72 73 74 72 28 73 7a 42   *m = strstr(szB
4270: 75 66 66 65 72 2c 20 70 2d 3e 6b 65 79 29 3b 0a  uffer, p->key);.
4280: 09 09 69 66 20 28 6d 29 20 7b 0a 09 09 20 20 20  ..if (m) {...   
4290: 20 63 68 61 72 20 2a 63 70 2c 20 2a 6f 70 2c 20   char *cp, *op, 
42a0: 2a 73 70 3b 0a 09 09 20 20 20 20 63 70 20 3d 20  *sp;...    cp = 
42b0: 73 7a 43 6f 70 79 3b 0a 09 09 20 20 20 20 6f 70  szCopy;...    op
42c0: 20 3d 20 73 7a 42 75 66 66 65 72 3b 0a 09 09 20   = szBuffer;... 
42d0: 20 20 20 77 68 69 6c 65 20 28 6f 70 20 21 3d 20     while (op != 
42e0: 6d 29 20 2a 63 70 2b 2b 20 3d 20 2a 6f 70 2b 2b  m) *cp++ = *op++
42f0: 3b 0a 09 09 20 20 20 20 73 70 20 3d 20 70 2d 3e  ;...    sp = p->
4300: 76 61 6c 75 65 3b 0a 09 09 20 20 20 20 77 68 69  value;...    whi
4310: 6c 65 20 28 73 70 20 26 26 20 2a 73 70 29 20 2a  le (sp && *sp) *
4320: 63 70 2b 2b 20 3d 20 2a 73 70 2b 2b 3b 0a 09 09  cp++ = *sp++;...
4330: 20 20 20 20 6f 70 20 2b 3d 20 73 74 72 6c 65 6e      op += strlen
4340: 28 70 2d 3e 6b 65 79 29 3b 0a 09 09 20 20 20 20  (p->key);...    
4350: 77 68 69 6c 65 20 28 2a 6f 70 29 20 2a 63 70 2b  while (*op) *cp+
4360: 2b 20 3d 20 2a 6f 70 2b 2b 3b 0a 09 09 20 20 20  + = *op++;...   
4370: 20 2a 63 70 20 3d 20 30 3b 0a 09 09 20 20 20 20   *cp = 0;...    
4380: 6d 65 6d 63 70 79 28 73 7a 42 75 66 66 65 72 2c  memcpy(szBuffer,
4390: 20 73 7a 43 6f 70 79 2c 20 73 69 7a 65 6f 66 28   szCopy, sizeof(
43a0: 73 7a 43 6f 70 79 29 29 3b 0a 09 09 7d 0a 09 20  szCopy));...}.. 
43b0: 20 20 20 7d 0a 09 20 20 20 20 70 72 69 6e 74 66     }..    printf
43c0: 28 22 25 73 22 2c 20 73 7a 42 75 66 66 65 72 29  ("%s", szBuffer)
43d0: 3b 0a 09 7d 0a 0a 09 6c 69 73 74 5f 66 72 65 65  ;..}...list_free
43e0: 28 26 73 75 62 73 74 50 74 72 29 3b 0a 20 20 20  (&substPtr);.   
43f0: 20 7d 0a 20 20 20 20 66 63 6c 6f 73 65 28 66 70   }.    fclose(fp
4400: 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b  );.    return 0;
4410: 0a 7d 0a 0c 0a 42 4f 4f 4c 20 46 69 6c 65 45 78  .}...BOOL FileEx
4420: 69 73 74 73 28 4c 50 43 54 53 54 52 20 73 7a 50  ists(LPCTSTR szP
4430: 61 74 68 29 0a 7b 0a 23 69 66 6e 64 65 66 20 49  ath).{.#ifndef I
4440: 4e 56 41 4c 49 44 5f 46 49 4c 45 5f 41 54 54 52  NVALID_FILE_ATTR
4450: 49 42 55 54 45 53 0a 20 20 20 20 23 64 65 66 69  IBUTES.    #defi
4460: 6e 65 20 49 4e 56 41 4c 49 44 5f 46 49 4c 45 5f  ne INVALID_FILE_
4470: 41 54 54 52 49 42 55 54 45 53 20 28 28 44 57 4f  ATTRIBUTES ((DWO
4480: 52 44 29 2d 31 29 0a 23 65 6e 64 69 66 0a 20 20  RD)-1).#endif.  
4490: 20 20 44 57 4f 52 44 20 70 61 74 68 41 74 74 72    DWORD pathAttr
44a0: 20 3d 20 47 65 74 46 69 6c 65 41 74 74 72 69 62   = GetFileAttrib
44b0: 75 74 65 73 28 73 7a 50 61 74 68 29 3b 0a 20 20  utes(szPath);.  
44c0: 20 20 72 65 74 75 72 6e 20 28 70 61 74 68 41 74    return (pathAt
44d0: 74 72 20 21 3d 20 49 4e 56 41 4c 49 44 5f 46 49  tr != INVALID_FI
44e0: 4c 45 5f 41 54 54 52 49 42 55 54 45 53 20 26 26  LE_ATTRIBUTES &&
44f0: 0a 09 20 20 20 20 21 28 70 61 74 68 41 74 74 72  ..    !(pathAttr
4500: 20 26 20 46 49 4c 45 5f 41 54 54 52 49 42 55 54   & FILE_ATTRIBUT
4510: 45 5f 44 49 52 45 43 54 4f 52 59 29 29 3b 0a 7d  E_DIRECTORY));.}
4520: 0a 0c 0a 0a 2f 2a 0a 20 2a 20 51 75 61 6c 69 66  ..../*. * Qualif
4530: 79 50 61 74 68 20 2d 2d 0a 20 2a 0a 20 2a 09 54  yPath --. *. *.T
4540: 68 69 73 20 63 6f 6d 70 6f 73 65 73 20 74 68 65  his composes the
4550: 20 63 75 72 72 65 6e 74 20 77 6f 72 6b 69 6e 67   current working
4560: 20 64 69 72 65 63 74 6f 72 79 20 77 69 74 68 20   directory with 
4570: 61 20 70 72 6f 76 69 64 65 64 20 70 61 74 68 0a  a provided path.
4580: 20 2a 09 61 6e 64 20 72 65 74 75 72 6e 73 20 74   *.and returns t
4590: 68 65 20 66 75 6c 6c 79 20 71 75 61 6c 69 66 69  he fully qualifi
45a0: 65 64 20 61 6e 64 20 6e 6f 72 6d 61 6c 69 7a 65  ed and normalize
45b0: 64 20 70 61 74 68 2e 0a 20 2a 09 4d 6f 73 74 6c  d path.. *.Mostl
45c0: 79 20 6e 65 65 64 65 64 20 74 6f 20 73 65 74 75  y needed to setu
45d0: 70 20 70 61 74 68 73 20 66 6f 72 20 74 65 73 74  p paths for test
45e0: 69 6e 67 2e 0a 20 2a 2f 0a 0a 73 74 61 74 69 63  ing.. */..static
45f0: 20 69 6e 74 0a 51 75 61 6c 69 66 79 50 61 74 68   int.QualifyPath
4600: 28 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72  (.    const char
4610: 20 2a 73 7a 50 61 74 68 29 0a 7b 0a 20 20 20 20   *szPath).{.    
4620: 63 68 61 72 20 73 7a 43 77 64 5b 4d 41 58 5f 50  char szCwd[MAX_P
4630: 41 54 48 20 2b 20 31 5d 3b 0a 0a 20 20 20 20 47  ATH + 1];..    G
4640: 65 74 46 75 6c 6c 50 61 74 68 4e 61 6d 65 28 73  etFullPathName(s
4650: 7a 50 61 74 68 2c 20 73 69 7a 65 6f 66 28 73 7a  zPath, sizeof(sz
4660: 43 77 64 29 2d 31 2c 20 73 7a 43 77 64 2c 20 4e  Cwd)-1, szCwd, N
4670: 55 4c 4c 29 3b 0a 20 20 20 20 70 72 69 6e 74 66  ULL);.    printf
4680: 28 22 25 73 5c 6e 22 2c 20 73 7a 43 77 64 29 3b  ("%s\n", szCwd);
4690: 0a 20 20 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d  .    return 0;.}
46a0: 0a 0a 2f 2a 0a 20 2a 20 49 6d 70 6c 65 6d 65 6e  ../*. * Implemen
46b0: 74 73 20 4c 6f 63 61 74 65 44 65 70 65 6e 64 65  ts LocateDepende
46c0: 6e 63 79 20 66 6f 72 20 61 20 73 69 6e 67 6c 65  ncy for a single
46d0: 20 64 69 72 65 63 74 6f 72 79 2e 20 53 65 65 20   directory. See 
46e0: 74 68 61 74 20 63 6f 6d 6d 61 6e 64 0a 20 2a 20  that command. * 
46f0: 66 6f 72 20 61 6e 20 65 78 70 6c 61 6e 61 74 69  for an explanati
4700: 6f 6e 2e 0a 20 2a 20 52 65 74 75 72 6e 73 20 30  on.. * Returns 0
4710: 20 69 66 20 66 6f 75 6e 64 20 61 66 74 65 72 20   if found after 
4720: 70 72 69 6e 74 69 6e 67 20 74 68 65 20 64 69 72  printing the dir
4730: 65 63 74 6f 72 79 2e 0a 20 2a 20 52 65 74 75 72  ectory.. * Retur
4740: 6e 73 20 31 20 69 66 20 6e 6f 74 20 66 6f 75 6e  ns 1 if not foun
4750: 64 20 62 75 74 20 6e 6f 20 65 72 72 6f 72 73 2e  d but no errors.
4760: 0a 20 2a 20 52 65 74 75 72 6e 73 20 32 20 6f 6e  . * Returns 2 on
4770: 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20 65 72 72   any kind of err
4780: 6f 72 0a 20 2a 20 42 61 73 69 63 61 6c 6c 79 2c  or. * Basically,
4790: 20 74 68 65 73 65 20 61 72 65 20 75 73 65 64 20   these are used 
47a0: 61 73 20 65 78 69 74 20 63 6f 64 65 73 20 66 6f  as exit codes fo
47b0: 72 20 74 68 65 20 70 72 6f 63 65 73 73 2e 0a 20  r the process.. 
47c0: 2a 2f 0a 73 74 61 74 69 63 20 69 6e 74 20 4c 6f  */.static int Lo
47d0: 63 61 74 65 44 65 70 65 6e 64 65 6e 63 79 48 65  cateDependencyHe
47e0: 6c 70 65 72 28 63 6f 6e 73 74 20 63 68 61 72 20  lper(const char 
47f0: 2a 64 69 72 2c 20 63 6f 6e 73 74 20 63 68 61 72  *dir, const char
4800: 20 2a 6b 65 79 70 61 74 68 29 0a 7b 0a 20 20 20   *keypath).{.   
4810: 20 48 41 4e 44 4c 45 20 68 53 65 61 72 63 68 3b   HANDLE hSearch;
4820: 0a 20 20 20 20 63 68 61 72 20 70 61 74 68 5b 4d  .    char path[M
4830: 41 58 5f 50 41 54 48 2b 31 5d 3b 0a 20 20 20 20  AX_PATH+1];.    
4840: 73 69 7a 65 5f 74 20 64 69 72 6c 65 6e 3b 0a 20  size_t dirlen;. 
4850: 20 20 20 69 6e 74 20 6b 65 79 6c 65 6e 2c 20 72     int keylen, r
4860: 65 74 3b 0a 20 20 20 20 57 49 4e 33 32 5f 46 49  et;.    WIN32_FI
4870: 4e 44 5f 44 41 54 41 20 66 69 6e 66 6f 3b 0a 0a  ND_DATA finfo;..
4880: 20 20 20 20 69 66 20 28 64 69 72 20 3d 3d 20 4e      if (dir == N
4890: 55 4c 4c 20 7c 7c 20 6b 65 79 70 61 74 68 20 3d  ULL || keypath =
48a0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72  = NULL) {..retur
48b0: 6e 20 32 3b 20 2f 2a 20 48 61 76 65 20 6e 6f 20  n 2; /* Have no 
48c0: 72 65 61 6c 20 65 72 72 6f 72 20 72 65 70 6f 72  real error repor
48d0: 74 69 6e 67 20 6d 65 63 68 61 6e 69 73 6d 20 69  ting mechanism i
48e0: 6e 74 6f 20 6e 6d 61 6b 65 20 2a 2f 0a 20 20 20  nto nmake */.   
48f0: 20 7d 0a 20 20 20 20 64 69 72 6c 65 6e 20 3d 20   }.    dirlen = 
4900: 73 74 72 6c 65 6e 28 64 69 72 29 3b 0a 20 20 20  strlen(dir);.   
4910: 20 69 66 20 28 64 69 72 6c 65 6e 20 3e 20 73 69   if (dirlen > si
4920: 7a 65 6f 66 28 70 61 74 68 29 20 2d 20 33 29 20  zeof(path) - 3) 
4930: 7b 0a 09 72 65 74 75 72 6e 20 32 3b 0a 20 20 20  {..return 2;.   
4940: 20 7d 0a 20 20 20 20 73 74 72 6e 63 70 79 28 70   }.    strncpy(p
4950: 61 74 68 2c 20 64 69 72 2c 20 64 69 72 6c 65 6e  ath, dir, dirlen
4960: 29 3b 0a 20 20 20 20 73 74 72 6e 63 70 79 28 70  );.    strncpy(p
4970: 61 74 68 2b 64 69 72 6c 65 6e 2c 20 22 5c 5c 2a  ath+dirlen, "\\*
4980: 22 2c 20 33 29 3b 09 2f 2a 20 49 6e 63 6c 75 64  ", 3);./* Includ
4990: 69 6e 67 20 74 65 72 6d 69 6e 61 74 69 6e 67 20  ing terminating 
49a0: 5c 30 20 2a 2f 0a 20 20 20 20 6b 65 79 6c 65 6e  \0 */.    keylen
49b0: 20 3d 20 73 74 72 6c 65 6e 28 6b 65 79 70 61 74   = strlen(keypat
49c0: 68 29 3b 0a 0a 23 69 66 20 30 20 2f 2a 20 54 68  h);..#if 0 /* Th
49d0: 69 73 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 6e  is function is n
49e0: 6f 74 20 61 76 61 69 6c 61 62 6c 65 20 69 6e 20  ot available in 
49f0: 56 69 73 75 61 6c 20 43 2b 2b 20 36 20 2a 2f 0a  Visual C++ 6 */.
4a00: 20 20 20 20 2f 2a 0a 20 20 20 20 20 2a 20 55 73      /*.     * Us
4a10: 65 20 6e 75 6d 65 72 69 63 73 20 30 20 2d 3e 20  e numerics 0 -> 
4a20: 46 69 6e 64 45 78 49 6e 66 6f 53 74 61 6e 64 61  FindExInfoStanda
4a30: 72 64 2c 0a 20 20 20 20 20 2a 20 31 20 2d 3e 20  rd,.     * 1 -> 
4a40: 46 69 6e 64 45 78 53 65 61 72 63 68 4c 69 6d 69  FindExSearchLimi
4a50: 74 54 6f 44 69 72 65 63 74 6f 72 69 65 73 2c 0a  tToDirectories,.
4a60: 20 20 20 20 20 2a 20 61 73 20 74 68 65 73 65 20       * as these 
4a70: 61 72 65 20 6e 6f 74 20 64 65 66 69 6e 65 64 20  are not defined 
4a80: 69 6e 20 56 69 73 75 61 6c 20 43 2b 2b 20 36 0a  in Visual C++ 6.
4a90: 20 20 20 20 20 2a 2f 0a 20 20 20 20 68 53 65 61       */.    hSea
4aa0: 72 63 68 20 3d 20 46 69 6e 64 46 69 72 73 74 46  rch = FindFirstF
4ab0: 69 6c 65 45 78 28 70 61 74 68 2c 20 30 2c 20 26  ileEx(path, 0, &
4ac0: 66 69 6e 66 6f 2c 20 31 2c 20 4e 55 4c 4c 2c 20  finfo, 1, NULL, 
4ad0: 30 29 3b 0a 23 65 6c 73 65 0a 20 20 20 20 68 53  0);.#else.    hS
4ae0: 65 61 72 63 68 20 3d 20 46 69 6e 64 46 69 72 73  earch = FindFirs
4af0: 74 46 69 6c 65 28 70 61 74 68 2c 20 26 66 69 6e  tFile(path, &fin
4b00: 66 6f 29 3b 0a 23 65 6e 64 69 66 0a 20 20 20 20  fo);.#endif.    
4b10: 69 66 20 28 68 53 65 61 72 63 68 20 3d 3d 20 49  if (hSearch == I
4b20: 4e 56 41 4c 49 44 5f 48 41 4e 44 4c 45 5f 56 41  NVALID_HANDLE_VA
4b30: 4c 55 45 29 20 7b 0a 09 72 65 74 75 72 6e 20 31  LUE) {..return 1
4b40: 3b 20 2f 2a 20 4e 6f 74 20 66 6f 75 6e 64 20 2a  ; /* Not found *
4b50: 2f 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20  /.    }..    /* 
4b60: 4c 6f 6f 70 20 74 68 72 6f 75 67 68 20 61 6c 6c  Loop through all
4b70: 20 73 75 62 64 69 72 73 20 63 68 65 63 6b 69 6e   subdirs checkin
4b80: 67 20 69 66 20 74 68 65 20 6b 65 79 70 61 74 68  g if the keypath
4b90: 20 69 73 20 75 6e 64 65 72 20 74 68 65 72 65 20   is under there 
4ba0: 2a 2f 0a 20 20 20 20 72 65 74 20 3d 20 31 3b 20  */.    ret = 1; 
4bb0: 2f 2a 20 41 73 73 75 6d 65 20 6e 6f 74 20 66 6f  /* Assume not fo
4bc0: 75 6e 64 20 2a 2f 0a 20 20 20 20 64 6f 20 7b 0a  und */.    do {.
4bd0: 09 69 6e 74 20 73 75 62 6c 65 6e 3b 0a 09 2f 2a  .int sublen;../*
4be0: 0a 09 20 2a 20 57 65 20 6e 65 65 64 20 74 6f 20  .. * We need to 
4bf0: 63 68 65 63 6b 20 69 74 20 69 73 20 61 20 64 69  check it is a di
4c00: 72 65 63 74 6f 72 79 20 64 65 73 70 69 74 65 20  rectory despite 
4c10: 74 68 65 0a 09 20 2a 20 46 69 6e 64 45 78 53 65  the.. * FindExSe
4c20: 61 72 63 68 4c 69 6d 69 74 54 6f 44 69 72 65 63  archLimitToDirec
4c30: 74 6f 72 69 65 73 20 69 6e 20 74 68 65 20 61 62  tories in the ab
4c40: 6f 76 65 20 63 61 6c 6c 2e 20 53 65 65 20 53 44  ove call. See SD
4c50: 4b 20 64 6f 63 73 0a 09 20 2a 2f 0a 09 69 66 20  K docs.. */..if 
4c60: 28 28 66 69 6e 66 6f 2e 64 77 46 69 6c 65 41 74  ((finfo.dwFileAt
4c70: 74 72 69 62 75 74 65 73 20 26 20 46 49 4c 45 5f  tributes & FILE_
4c80: 41 54 54 52 49 42 55 54 45 5f 44 49 52 45 43 54  ATTRIBUTE_DIRECT
4c90: 4f 52 59 29 20 3d 3d 20 30 29 20 7b 0a 09 20 20  ORY) == 0) {..  
4ca0: 20 20 63 6f 6e 74 69 6e 75 65 3b 0a 09 7d 0a 09    continue;..}..
4cb0: 73 75 62 6c 65 6e 20 3d 20 73 74 72 6c 65 6e 28  sublen = strlen(
4cc0: 66 69 6e 66 6f 2e 63 46 69 6c 65 4e 61 6d 65 29  finfo.cFileName)
4cd0: 3b 0a 09 69 66 20 28 28 64 69 72 6c 65 6e 2b 31  ;..if ((dirlen+1
4ce0: 2b 73 75 62 6c 65 6e 2b 31 2b 6b 65 79 6c 65 6e  +sublen+1+keylen
4cf0: 2b 31 29 20 3e 20 73 69 7a 65 6f 66 28 70 61 74  +1) > sizeof(pat
4d00: 68 29 29 20 7b 0a 09 20 20 20 20 63 6f 6e 74 69  h)) {..    conti
4d10: 6e 75 65 3b 09 09 2f 2a 20 50 61 74 68 20 64 6f  nue;../* Path do
4d20: 65 73 20 6e 6f 74 20 66 69 74 2c 20 61 73 73 75  es not fit, assu
4d30: 6d 65 20 6e 6f 74 20 6d 61 74 63 68 65 64 20 2a  me not matched *
4d40: 2f 0a 09 7d 0a 09 73 74 72 6e 63 70 79 28 70 61  /..}..strncpy(pa
4d50: 74 68 2b 64 69 72 6c 65 6e 2b 31 2c 20 66 69 6e  th+dirlen+1, fin
4d60: 66 6f 2e 63 46 69 6c 65 4e 61 6d 65 2c 20 73 75  fo.cFileName, su
4d70: 62 6c 65 6e 29 3b 0a 09 70 61 74 68 5b 64 69 72  blen);..path[dir
4d80: 6c 65 6e 2b 31 2b 73 75 62 6c 65 6e 5d 20 3d 20  len+1+sublen] = 
4d90: 27 5c 5c 27 3b 0a 09 73 74 72 6e 63 70 79 28 70  '\\';..strncpy(p
4da0: 61 74 68 2b 64 69 72 6c 65 6e 2b 31 2b 73 75 62  ath+dirlen+1+sub
4db0: 6c 65 6e 2b 31 2c 20 6b 65 79 70 61 74 68 2c 20  len+1, keypath, 
4dc0: 6b 65 79 6c 65 6e 2b 31 29 3b 0a 09 69 66 20 28  keylen+1);..if (
4dd0: 46 69 6c 65 45 78 69 73 74 73 28 70 61 74 68 29  FileExists(path)
4de0: 29 20 7b 0a 09 20 20 20 20 2f 2a 20 46 6f 75 6e  ) {..    /* Foun
4df0: 64 20 61 20 6d 61 74 63 68 2c 20 70 72 69 6e 74  d a match, print
4e00: 20 74 6f 20 73 74 64 6f 75 74 20 2a 2f 0a 09 20   to stdout */.. 
4e10: 20 20 20 70 61 74 68 5b 64 69 72 6c 65 6e 2b 31     path[dirlen+1
4e20: 2b 73 75 62 6c 65 6e 5d 20 3d 20 27 5c 30 27 3b  +sublen] = '\0';
4e30: 0a 09 20 20 20 20 51 75 61 6c 69 66 79 50 61 74  ..    QualifyPat
4e40: 68 28 70 61 74 68 29 3b 0a 09 20 20 20 20 72 65  h(path);..    re
4e50: 74 20 3d 20 30 3b 0a 09 20 20 20 20 62 72 65 61  t = 0;..    brea
4e60: 6b 3b 0a 09 7d 0a 20 20 20 20 7d 20 77 68 69 6c  k;..}.    } whil
4e70: 65 20 28 46 69 6e 64 4e 65 78 74 46 69 6c 65 28  e (FindNextFile(
4e80: 68 53 65 61 72 63 68 2c 20 26 66 69 6e 66 6f 29  hSearch, &finfo)
4e90: 29 3b 0a 20 20 20 20 46 69 6e 64 43 6c 6f 73 65  );.    FindClose
4ea0: 28 68 53 65 61 72 63 68 29 3b 0a 20 20 20 20 72  (hSearch);.    r
4eb0: 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 2f 2a  eturn ret;.}../*
4ec0: 0a 20 2a 20 4c 6f 63 61 74 65 44 65 70 65 6e 64  . * LocateDepend
4ed0: 65 6e 63 79 20 2d 2d 0a 20 2a 0a 20 2a 09 4c 6f  ency --. *. *.Lo
4ee0: 63 61 74 65 73 20 61 20 64 65 70 65 6e 64 65 6e  cates a dependen
4ef0: 63 79 20 66 6f 72 20 61 20 70 61 63 6b 61 67 65  cy for a package
4f00: 2e 0a 20 2a 09 20 20 20 20 6b 65 79 70 61 74 68  .. *.    keypath
4f10: 20 2d 20 61 20 72 65 6c 61 74 69 76 65 20 70 61   - a relative pa
4f20: 74 68 20 77 69 74 68 69 6e 20 74 68 65 20 70 61  th within the pa
4f30: 63 6b 61 67 65 20 64 69 72 65 63 74 6f 72 79 0a  ckage directory.
4f40: 20 2a 09 20 20 20 20 20 20 74 68 61 74 20 69 73   *.      that is
4f50: 20 75 73 65 64 20 74 6f 20 63 6f 6e 66 69 72 6d   used to confirm
4f60: 20 69 74 20 69 73 20 74 68 65 20 63 6f 72 72 65   it is the corre
4f70: 63 74 20 64 69 72 65 63 74 6f 72 79 2e 0a 20 2a  ct directory.. *
4f80: 09 54 68 65 20 73 65 61 72 63 68 20 70 61 74 68  .The search path
4f90: 20 66 6f 72 20 74 68 65 20 70 61 63 6b 61 67 65   for the package
4fa0: 20 64 69 72 65 63 74 6f 72 79 20 69 73 20 63 75   directory is cu
4fb0: 72 72 65 6e 74 6c 79 20 6f 6e 6c 79 0a 20 2a 09  rrently only. *.
4fc0: 20 20 20 20 74 68 65 20 70 61 72 65 6e 74 20 61      the parent a
4fd0: 6e 64 20 67 72 61 6e 64 70 61 72 65 6e 74 20 6f  nd grandparent o
4fe0: 66 20 74 68 65 20 63 75 72 72 65 6e 74 20 77 6f  f the current wo
4ff0: 72 6b 69 6e 67 20 64 69 72 65 63 74 6f 72 79 2e  rking directory.
5000: 0a 20 2a 09 20 20 20 20 49 66 20 66 6f 75 6e 64  . *.    If found
5010: 2c 20 74 68 65 20 63 6f 6d 6d 61 6e 64 20 70 72  , the command pr
5020: 69 6e 74 73 0a 20 2a 09 20 20 20 20 20 20 6e 61  ints. *.      na
5030: 6d 65 5f 44 49 52 50 41 54 48 3d 3c 66 75 6c 6c  me_DIRPATH=<full
5040: 20 70 61 74 68 20 6f 66 20 6c 6f 63 61 74 65 64   path of located
5050: 20 64 69 72 65 63 74 6f 72 79 3e 0a 20 2a 09 20   directory>. *. 
5060: 20 20 20 61 6e 64 20 72 65 74 75 72 6e 73 20 30     and returns 0
5070: 2e 20 49 66 20 6e 6f 74 20 66 6f 75 6e 64 2c 20  . If not found, 
5080: 64 6f 65 73 20 6e 6f 74 20 70 72 69 6e 74 20 61  does not print a
5090: 6e 79 74 68 69 6e 67 20 61 6e 64 20 72 65 74 75  nything and retu
50a0: 72 6e 73 20 31 2e 0a 20 2a 2f 0a 73 74 61 74 69  rns 1.. */.stati
50b0: 63 20 69 6e 74 20 4c 6f 63 61 74 65 44 65 70 65  c int LocateDepe
50c0: 6e 64 65 6e 63 79 28 63 6f 6e 73 74 20 63 68 61  ndency(const cha
50d0: 72 20 2a 6b 65 79 70 61 74 68 29 0a 7b 0a 20 20  r *keypath).{.  
50e0: 20 20 73 69 7a 65 5f 74 20 69 3b 0a 20 20 20 20    size_t i;.    
50f0: 69 6e 74 20 72 65 74 3b 0a 20 20 20 20 73 74 61  int ret;.    sta
5100: 74 69 63 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  tic const char *
5110: 63 6f 6e 73 74 20 70 61 74 68 73 5b 5d 20 3d 20  const paths[] = 
5120: 7b 22 2e 2e 22 2c 20 22 2e 2e 5c 5c 2e 2e 22 2c  {"..", "..\\..",
5130: 20 22 2e 2e 5c 5c 2e 2e 5c 5c 2e 2e 22 7d 3b 0a   "..\\..\\.."};.
5140: 0a 20 20 20 20 66 6f 72 20 28 69 20 3d 20 30 3b  .    for (i = 0;
5150: 20 69 20 3c 20 28 73 69 7a 65 6f 66 28 70 61 74   i < (sizeof(pat
5160: 68 73 29 2f 73 69 7a 65 6f 66 28 70 61 74 68 73  hs)/sizeof(paths
5170: 5b 30 5d 29 29 3b 20 2b 2b 69 29 20 7b 0a 09 72  [0])); ++i) {..r
5180: 65 74 20 3d 20 4c 6f 63 61 74 65 44 65 70 65 6e  et = LocateDepen
5190: 64 65 6e 63 79 48 65 6c 70 65 72 28 70 61 74 68  dencyHelper(path
51a0: 73 5b 69 5d 2c 20 6b 65 79 70 61 74 68 29 3b 0a  s[i], keypath);.
51b0: 09 69 66 20 28 72 65 74 20 3d 3d 20 30 29 20 7b  .if (ret == 0) {
51c0: 0a 09 20 20 20 20 72 65 74 75 72 6e 20 72 65 74  ..    return ret
51d0: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 72  ;..}.    }.    r
51e0: 65 74 75 72 6e 20 72 65 74 3b 0a 7d 0a 0a 0a 2f  eturn ret;.}.../
51f0: 2a 0a 20 2a 20 4c 6f 63 61 6c 20 76 61 72 69 61  *. * Local varia
5200: 62 6c 65 73 3a 0a 20 2a 20 20 20 6d 6f 64 65 3a  bles:. *   mode:
5210: 20 63 0a 20 2a 20 20 20 63 2d 62 61 73 69 63 2d   c. *   c-basic-
5220: 6f 66 66 73 65 74 3a 20 34 0a 20 2a 20 20 20 66  offset: 4. *   f
5230: 69 6c 6c 2d 63 6f 6c 75 6d 6e 3a 20 37 38 0a 20  ill-column: 78. 
5240: 2a 20 20 20 69 6e 64 65 6e 74 2d 74 61 62 73 2d  *   indent-tabs-
5250: 6d 6f 64 65 3a 20 74 0a 20 2a 20 20 20 74 61 62  mode: t. *   tab
5260: 2d 77 69 64 74 68 3a 20 38 0a 20 2a 20 45 6e 64  -width: 8. * End
5270: 3a 0a 20 2a 2f 0a                                :. */.