- Timestamp:
- May 19, 2008, 1:41:35 AM (17 years ago)
- Location:
- trunk/libc/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libc/src/kNIX/b_initArgv.c
r2989 r3644 30 30 *******************************************************************************/ 31 31 #include "kNIX.h" 32 #include <klibc/startup.h> 32 33 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_INITTERM 33 34 #include <klibc/logstrict.h> … … 75 76 static size_t parse_args(const char *pszSrc, char **papszArgs, char *pbPool) 76 77 { 78 char ch; 77 79 size_t cbArgs = 0; 78 80 __libc_Back_gcArgs = 0; … … 89 91 } 90 92 ++pszSrc; 91 for (;;) 93 94 /* Check for the kLIBC signature used for unix arguments. */ 95 if ( pszSrc[0] != 0x7f 96 || pszSrc[1] != 'k' 97 || pszSrc[2] != 'L' 98 || pszSrc[3] != 'I' 99 || pszSrc[4] != 'B' 100 || pszSrc[5] != 'C' 101 || pszSrc[6] != 0x7f 102 || pszSrc[7] != '\0') 92 103 { 93 /* skip white spaces */ 94 while (IS_WHITE(*pszSrc)) 95 ++pszSrc; 96 if (*pszSrc == 0) 97 break; 98 99 /* 100 * Parse one argument. 101 */ 102 char fFlags; 103 char *pfFlags = pbPool ? pbPool++ : &fFlags; 104 *pfFlags = (char)_ARG_NONZERO; 105 cbArgs++; 106 const size_t offArg = cbArgs; 107 PUTV; 108 char chQuote = 0; 104 /* Convert from OS/2 command line convention to C/Unix. */ 109 105 for (;;) 110 106 { 111 /* End quote. */ 112 if (*pszSrc == chQuote && chQuote) 113 chQuote = 0; 114 /* Start of double quote. */ 115 else if (!chQuote && *pszSrc == '"') 107 /* skip white spaces */ 108 while (IS_WHITE(*pszSrc)) 109 ++pszSrc; 110 if (*pszSrc == 0) 111 break; 112 113 /* 114 * Parse one argument. 115 */ 116 char fFlags; 117 char *pfFlags = pbPool ? pbPool++ : &fFlags; 118 *pfFlags = (char)_ARG_NONZERO; 119 cbArgs++; 120 const size_t offArg = cbArgs; 121 PUTV; 122 char chQuote = 0; 123 for (;;) 116 124 { 117 chQuote = '"'; 118 *pfFlags |= _ARG_DQUOTE; 125 /* End quote. */ 126 if (*pszSrc == chQuote && chQuote) 127 chQuote = 0; 128 /* Start of double quote. */ 129 else if (!chQuote && *pszSrc == '"') 130 { 131 chQuote = '"'; 132 *pfFlags |= _ARG_DQUOTE; 133 } 134 /* 135 * Only permit the single quote to be used at the start of an argument or 136 * within an already quoted one. This restriction is necessary to support 137 * unquoted filenames containing the single quote char. 138 */ 139 else if ( !chQuote 140 && *pszSrc == '\'' 141 && ( offArg == cbArgs 142 || (*pfFlags & _ARG_DQUOTE))) 143 { 144 chQuote = '\''; 145 *pfFlags |= _ARG_DQUOTE; 146 } 147 /* 148 * The escape character. This is truly magic/weird. 149 * It doesn't escape anything unless it's in front of a 150 * double quote character. EMX weirdness... 151 * (Ok, not escaping more than necessary is ok when using \ as path 152 * separator, but why weird interpretation of \\\\"asdf"? 153 */ 154 else if (*pszSrc == '\\' && chQuote != '\'') 155 { 156 int cSlashes = 0; 157 do 158 { 159 cSlashes++; 160 pszSrc++; 161 } while (*pszSrc == '\\'); 162 163 if (*pszSrc == '"') 164 { 165 /* Treat it as escapes. */ 166 while (cSlashes >= 2) 167 { 168 PUTC('\\'); 169 cSlashes -= 2; 170 } 171 if (cSlashes & 1) 172 PUTC(*pszSrc); 173 else 174 pszSrc--; 175 } 176 else 177 { 178 /* unmodified, no escaping. */ 179 while (cSlashes-- > 0) 180 PUTC('\\'); 181 pszSrc--; 182 } 183 } 184 /* Check for end of argument. */ 185 else if ( *pszSrc == '\0' 186 || ( IS_WHITE(*pszSrc) 187 && !chQuote)) 188 break; 189 /* Normal character. */ 190 else 191 PUTC(*pszSrc); 192 ++pszSrc; 119 193 } 120 /* 121 * Only permit the single quote to be used at the start of an argument or 122 * within an already quoted one. This restriction is necessary to support 123 * unquoted filenames containing the single quote char. 124 */ 125 else if ( !chQuote 126 && *pszSrc == '\'' 127 && ( offArg == cbArgs 128 || (*pfFlags & _ARG_DQUOTE))) 194 PUTC(0); 195 } 196 } 197 else 198 { 199 /* The kLIBC spawn packs exactly what we want, including the flag at [-1]. */ 200 pszSrc += sizeof(__KLIBC_ARG_SIGNATURE); 201 if (pbPool) 202 { 203 /* copying */ 204 while (*pszSrc) 129 205 { 130 chQuote = '\''; 131 *pfFlags |= _ARG_DQUOTE; 206 LIBC_ASSERT((unsigned)*pszSrc & __KLIBC_ARG_NONZERO); 207 __libc_Back_gcArgs++; 208 *papszArgs++ = pbPool + 1; 209 do 210 { 211 *pbPool++ = ch = *pszSrc++; 212 } while (ch); 132 213 } 133 /* 134 * The escape character. This is truly magic/weird. 135 * It doesn't escape anything unless it's in front of a 136 * double quote character. EMX weirdness... 137 * (Ok, not escaping more than necessary is ok when using \ as path 138 * separator, but why weird interpretation of \\\\"asdf"? 139 */ 140 else if (*pszSrc == '\\' && chQuote != '\'') 214 } 215 else 216 { 217 /* counting */ 218 while (*pszSrc) 141 219 { 142 int cSlashes = 0; 220 __libc_Back_gcArgs++; 221 LIBC_ASSERT((unsigned)*pszSrc & __KLIBC_ARG_NONZERO); 143 222 do 144 223 { 145 cSlashes++; 146 pszSrc++; 147 } while (*pszSrc == '\\'); 148 149 if (*pszSrc == '"') 150 { 151 /* Treat it as escapes. */ 152 while (cSlashes >= 2) 153 { 154 PUTC('\\'); 155 cSlashes -= 2; 156 } 157 if (cSlashes & 1) 158 PUTC(*pszSrc); 159 else 160 pszSrc--; 161 } 162 else 163 { 164 /* unmodified, no escaping. */ 165 while (cSlashes-- > 0) 166 PUTC('\\'); 167 pszSrc--; 168 } 224 cbArgs++; 225 ch = *pszSrc++; 226 } while (ch); 169 227 } 170 /* Check for end of argument. */171 else if ( *pszSrc == '\0'172 || ( IS_WHITE(*pszSrc)173 && !chQuote))174 break;175 /* Normal character. */176 else177 PUTC(*pszSrc);178 ++pszSrc;179 228 } 180 PUTC(0);181 229 } 182 230 return cbArgs; -
trunk/libc/src/kNIX/os2/__spawnve.c
r3641 r3644 33 33 /** @todo Cleanup __spawnve.c properly! */ 34 34 #include <emx/syscalls.h> 35 #include <klibc/startup.h> 35 36 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS 36 37 #include <klibc/logstrict.h> … … 193 194 LIBCLOG_ENTER("np=%p:{mode=%#x}\n", (void *)np, np->mode); 194 195 FS_VAR(); 196 char szLineBuf[512]; 195 197 196 198 /* … … 234 236 235 237 /* 236 * cmd.exe and 4os2.exe needs different argument handling. 238 * cmd.exe and 4os2.exe needs different argument handling, and 239 * starting with kLIBC 0.6.4 we can pass argv directly to LIBC 240 * programs. 237 241 * (1 == cmd or 4os2 shell, 0 == anything else) 238 242 */ 243 enum { args_standard, args_cmd, args_unix } enmMethod = args_standard; 239 244 char *psz = _getname(pszPgmName); 240 int method = stricmp(psz, "cmd.exe") == 0 241 || stricmp(psz, "4os2.exe") == 0; 245 if ( stricmp(psz, "cmd.exe") == 0 246 || stricmp(psz, "4os2.exe") == 0) 247 enmMethod = args_cmd; 248 else 249 { 250 HFILE hFile = NULLHANDLE; 251 ULONG ulAction = 0; 252 rc = DosOpen((PCSZ)pszPgmName, &hFile, &ulAction, 0, FILE_NORMAL, 253 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, 254 OPEN_FLAGS_SEQUENTIAL | OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY, 255 NULL); 256 if (!rc) 257 { 258 ULONG cbRead = 0; 259 rc = DosRead(hFile, szLineBuf, sizeof(szLineBuf), &cbRead); 260 DosClose(hFile); 261 if (rc) 262 LIBCLOG_ERROR("DosRead - rc=%d (%s)\n", rc, pszPgmName); 263 else if ( cbRead >= __KLIBC_STUB_MIN_SIZE 264 && szLineBuf[0] == 'M' 265 && szLineBuf[1] == 'Z' 266 && !memcmp(&szLineBuf[__KLIBC_STUB_SIGNATURE_OFF], __KLIBC_STUB_SIGNATURE_BASE, sizeof(__KLIBC_STUB_SIGNATURE_BASE) - 1) 267 ) 268 { 269 char const *pchVer = &szLineBuf[__KLIBC_STUB_SIGNATURE_OFF + sizeof(__KLIBC_STUB_SIGNATURE_BASE) - 1]; 270 if (*pchVer >= '0' && *pchVer <= '9') 271 enmMethod = !(np->mode & P_NOUNIXARGV) ? args_unix : args_standard; 272 } 273 /** @todo move the hash bang handling up here. */ 274 /*else if (!rc && szLineBuf[0] == '#') 275 { 276 } */ 277 } 278 /* Catch some plain failures here, leave the rest for later. */ 279 else if ( rc == ERROR_FILE_NOT_FOUND 280 || rc == ERROR_PATH_NOT_FOUND) 281 { 282 errno = __libc_back_native2errno(rc); 283 LIBCLOG_RETURN_INT(-1); 284 } 285 else 286 LIBCLOG_ERROR("rc=%d (%s)\n", rc, pszPgmName); 287 } 242 288 243 289 /* … … 249 295 char *pszArg = NULL; 250 296 size_t cbArgs = 0; 297 int i; 298 251 299 if (np->arg_count > 0) 252 300 { … … 257 305 pszArg += cch; pszSrc += cch; 258 306 } 259 int i; 260 for (i = 1; i < np->arg_count; ++i) 307 if (enmMethod == args_unix) 261 308 { 262 if (i > 1) 309 /* first arg is the signature. */ 310 ADD(sizeof(__KLIBC_ARG_SIGNATURE)); 311 memcpy(pszArg, __KLIBC_ARG_SIGNATURE, sizeof(__KLIBC_ARG_SIGNATURE)); 312 pszArg += sizeof(__KLIBC_ARG_SIGNATURE); 313 314 /* then comes the argument vector. */ 315 for (i = 1; i < np->arg_count; ++i) 263 316 { 264 ADD(1); 265 *pszArg++ = ' '; 317 unsigned char chFlags = *pszSrc++; 318 chFlags &= __KLIBC_ARG_MASK; 319 chFlags |= __KLIBC_ARG_ARGV; 320 cch = strlen(pszSrc) + 1; 321 ADD(cch + 1); 322 *pszArg++ = chFlags; 323 memcpy(pszArg, pszSrc, cch); 324 pszArg += cch; 325 pszSrc += cch; 266 326 } 267 ++pszSrc; /* skip flags byte */ 268 BOOL fQuote = FALSE; 269 if (*pszSrc == 0) 270 fQuote = TRUE; 271 else if (ulMode & P_QUOTE) 327 328 /* the double termination. */ 329 ADD(1); 330 *pszArg = '\0'; 331 } 332 else 333 { 334 /* quote the arguments in emx / cmd.exe fashion. */ 335 for (i = 1; i < np->arg_count; ++i) 272 336 { 273 if (pszSrc[0] == '@' && pszSrc[1] != 0) 337 if (i > 1) 338 { 339 ADD(1); 340 *pszArg++ = ' '; 341 } 342 ++pszSrc; /* skip flags byte */ 343 BOOL fQuote = FALSE; 344 if (*pszSrc == 0) 274 345 fQuote = TRUE; 275 else 346 else if (ulMode & P_QUOTE) 347 { 348 if (pszSrc[0] == '@' && pszSrc[1] != 0) 349 fQuote = TRUE; 350 else 351 for (psz = (char *)pszSrc; *psz != 0; ++psz) 352 if (*psz == '?' || *psz == '*') 353 { 354 fQuote = TRUE; 355 break; 356 } 357 } 358 if (!fQuote) 359 { 276 360 for (psz = (char *)pszSrc; *psz != 0; ++psz) 277 if (*psz == ' ?' || *psz == '*')361 if (*psz == ' ' || *psz == '\t' || (*psz == '"' && enmMethod == args_cmd)) 278 362 { 279 363 fQuote = TRUE; 280 364 break; 281 365 } 282 } 283 if (!fQuote) 284 { 285 for (psz = (char *)pszSrc; *psz != 0; ++psz) 286 if (*psz == ' ' || *psz == '\t' || (*psz == '"' && method == 1)) 366 } 367 if (fQuote) 368 { 369 ADD(1); 370 *pszArg++ = '"'; 371 } 372 size_t bs = 0; 373 while (*pszSrc != 0) 374 { 375 if (*pszSrc == '"' && enmMethod == args_standard) 287 376 { 288 fQuote = TRUE; 289 break; 377 ++bs; 378 ADD(bs); 379 memset(pszArg, '\\', bs); pszArg += bs; 380 bs = 0; 290 381 } 291 } 292 if (fQuote) 293 { 294 ADD(1); 295 *pszArg++ = '"'; 296 } 297 size_t bs = 0; 298 while (*pszSrc != 0) 299 { 300 if (*pszSrc == '"' && method == 0) 301 { 302 ++bs; 303 ADD(bs); 382 else if (*pszSrc == '\\' && enmMethod == args_standard) 383 ++bs; 384 else 385 bs = 0; 386 ADD(1); 387 *pszArg++ = *pszSrc; 388 ++pszSrc; 389 } 390 if (fQuote) 391 { 392 ADD(1+bs); 304 393 memset(pszArg, '\\', bs); pszArg += bs; 305 bs = 0; 306 } 307 else if (*pszSrc == '\\' && method == 0) 308 ++bs; 309 else 310 bs = 0; 311 ADD(1); 312 *pszArg++ = *pszSrc; 394 *pszArg++ = '"'; 395 } 313 396 ++pszSrc; 314 397 } 315 if (fQuote) 316 { 317 ADD(1+bs); 318 memset(pszArg, '\\', bs); pszArg += bs; 319 *pszArg++ = '"'; 320 } 321 ++pszSrc; 398 /* The arguments are an array of zero terminated strings, ending with an empty string. */ 399 ADD(2); 400 *pszArg++ = '\0'; 401 *pszArg++ = '\0'; 322 402 } 323 /* The arguments are an array of zero terminated strings, ending with an empty string. */324 ADD(2);325 *pszArg++ = '\0';326 *pszArg++ = '\0';327 403 328 404 … … 359 435 * requires inspection of the first line of the file. 360 436 */ 361 char szLineBuf[256];362 437 const char *pszInterpreter = NULL; 363 438 const char *pszInterpreterArgs = NULL; … … 528 603 529 604 /* 530 * Delay a tiny bit while the child is starting up and doing the inheriting. 531 * If we figure that it's a libc child, we can wait a good deal longer. 605 * Wait for the child to become active and complete the inhertining. 532 606 */ 533 607 int fDoneInherit = __libc_spmWaitForChildToBecomeAlive(pEmbryo); … … 701 775 } 702 776 else if (rc > 0) 703 errno = rc;777 errno = __libc_back_native2errno(rc); 704 778 else 705 779 errno = -rc; -
trunk/libc/src/libc/misc/response.c
r2433 r3644 5 5 #include <stdlib.h> 6 6 #include <string.h> 7 #include < emx/startup.h>7 #include <klibc/startup.h> 8 8 9 9 #define RPUT(x) do \ … … 30 30 for (i = 1; i < old_argc; ++i) 31 31 if (old_argv[i] != NULL 32 && !(old_argv[i][-1] & (_ ARG_DQUOTE|_ARG_WILDCARD))32 && !(old_argv[i][-1] & (__KLIBC_ARG_DQUOTE | __KLIBC_ARG_WILDCARD | __KLIBC_ARG_SHELL)) 33 33 && old_argv[i][0] == '@') 34 34 break; … … 39 39 { 40 40 if (i == 0 || old_argv[i] == NULL 41 || (old_argv[i][-1] & (_ ARG_DQUOTE|_ARG_WILDCARD))41 || (old_argv[i][-1] & (__KLIBC_ARG_DQUOTE | __KLIBC_ARG_WILDCARD | __KLIBC_ARG_SHELL)) 42 42 || old_argv[i][0] != '@' 43 43 || (f = fopen (old_argv[i]+1, "rt")) == NULL) … … 45 45 else 46 46 { 47 line[0] = _ ARG_NONZERO|_ARG_RESPONSE;47 line[0] = __KLIBC_ARG_NONZERO | __KLIBC_ARG_RESPONSE; 48 48 while (fgets (line+1, sizeof (line)-1, f) != NULL) 49 49 { -
trunk/libc/src/libc/misc/wildcard.c
r732 r3644 5 5 #include <stdlib.h> 6 6 #include <string.h> 7 #include <emx/startup.h>8 7 #include <emx/syscalls.h> 8 #include <klibc/startup.h> 9 9 10 10 #define WPUT(x) do { \ … … 32 32 for (i = 1; i < old_argc; ++i) 33 33 if (old_argv[i] != NULL && 34 !(old_argv[i][-1] & (_ ARG_DQUOTE|_ARG_RESPONSE)) &&34 !(old_argv[i][-1] & (__KLIBC_ARG_DQUOTE | __KLIBC_ARG_RESPONSE | __KLIBC_ARG_ARGV | __KLIBC_ARG_SHELL)) && 35 35 strpbrk (old_argv[i], "?*") != NULL) 36 36 break; … … 41 41 { 42 42 if (i == 0 || old_argv[i] == NULL 43 || (old_argv[i][-1] & (_ ARG_DQUOTE|_ARG_RESPONSE))43 || (old_argv[i][-1] & (__KLIBC_ARG_DQUOTE | __KLIBC_ARG_RESPONSE | __KLIBC_ARG_ARGV | __KLIBC_ARG_SHELL)) 44 44 || strpbrk (old_argv[i], "?*") == NULL 45 45 || __findfirst (old_argv[i], 0x10, &find) != 0) … … 47 47 else 48 48 { 49 line[0] = _ ARG_NONZERO|_ARG_WILDCARD;49 line[0] = __KLIBC_ARG_NONZERO | __KLIBC_ARG_WILDCARD; 50 50 strcpy (line+1, old_argv[i]); 51 51 p = _getname (line + 1);
Note:
See TracChangeset
for help on using the changeset viewer.