Changeset 1308 in kBuild
- Timestamp:
- Dec 2, 2007 2:05:11 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin/redirect.c
r1302 r1308 47 47 { 48 48 fprintf(pOut, 49 "usage: %s [-[rwa+tb]<fd> [=|:| ]<file>] -- <program> [args]\n"49 "usage: %s [-[rwa+tb]<fd> <file>] [-E <var=val>] [-C <dir>] -- <program> [args]\n" 50 50 " or: %s --help\n" 51 51 " or: %s --version\n" … … 56 56 " o = stdout\n" 57 57 " e = stderr\n" 58 "\n" 59 "The -E switch is for making changes to the environment in a putenv\n" 60 "fashion.\n" 61 "\n" 62 "The -C switch is for changing the current directory. This takes immediate\n" 63 "effect, so be careful where you put it.\n" 58 64 "\n" 59 65 "This command is really just a quick hack to avoid invoking the shell\n" … … 103 109 else if (!strcmp(psz, "-version")) 104 110 psz = "V"; 111 else if (!strcmp(psz, "-env")) 112 psz = "E"; 113 else if (!strcmp(psz, "-chdir")) 114 psz = "C"; 105 115 } 106 116 … … 119 129 KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, KBUILD_VERSION_PATCH); 120 130 return 0; 131 } 132 133 /* 134 * Environment switch? 135 */ 136 if (*psz == 'E') 137 { 138 psz++; 139 if (*psz == ':' || *psz == '=') 140 psz++; 141 else 142 { 143 if (i + 1 >= argc) 144 { 145 fprintf(pStdErr, "%s: syntax error: no argument for %s\n", argv[0], argv[i]); 146 return 1; 147 } 148 psz = argv[++i]; 149 } 150 if (putenv(psz)) 151 { 152 fprintf(pStdErr, "%s: error: putenv(\"%s\"): %s\n", argv[0], psz, strerror(errno)); 153 return 1; 154 } 155 continue; 156 } 157 158 /* 159 * Change directory switch? 160 */ 161 if (*psz == 'C') 162 { 163 psz++; 164 if (*psz == ':' || *psz == '=') 165 psz++; 166 else 167 { 168 if (i + 1 >= argc) 169 { 170 fprintf(pStdErr, "%s: syntax error: no argument for %s\n", argv[0], argv[i]); 171 return 1; 172 } 173 psz = argv[++i]; 174 } 175 if (!chdir(psz)) 176 continue; 177 #ifdef _MSC_VER 178 { 179 /* drop trailing slash if any. */ 180 size_t cch = strlen(psz); 181 if ( cch > 2 182 && (psz[cch - 1] == '/' || psz[cch - 1] == '\\') 183 && psz[cch - 1] != ':') 184 { 185 int rc2; 186 char *pszCopy = strdup(psz); 187 do pszCopy[--cch] = '\0'; 188 while ( cch > 2 189 && (pszCopy[cch - 1] == '/' || pszCopy[cch - 1] == '\\') 190 && pszCopy[cch - 1] != ':'); 191 rc2 = chdir(pszCopy); 192 free(pszCopy); 193 if (!rc2) 194 continue; 195 } 196 } 197 #endif 198 fprintf(pStdErr, "%s: error: chdir(\"%s\"): %s\n", argv[0], psz, strerror(errno)); 199 return 1; 121 200 } 122 201
Note:
See TracChangeset
for help on using the changeset viewer.