Changeset 2838 for trunk/src/win32k/ldr/myldrOpen.cpp
- Timestamp:
- Feb 21, 2000, 10:24:02 AM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/win32k/ldr/myldrOpen.cpp
r2837 r2838 1 /* $Id: myldrOpen.cpp,v 1. 9 2000-02-21 05:00:52bird Exp $1 /* $Id: myldrOpen.cpp,v 1.10 2000-02-21 09:24:01 bird Exp $ 2 2 * 3 3 * myldrOpen - ldrOpen. … … 43 43 #include "myExecPgm.h" 44 44 45 /******************************************************************************* 46 * Global Variables * 47 *******************************************************************************/ 48 extern BOOL fQAppType; /* From LDRQAppType */ 45 49 46 50 /******************************************************************************* … … 98 102 * Try get the filesize 99 103 */ 100 /*101 104 rc = SftFileSize(*phFile, (PULONG)SSToDS(&cbFile)); 102 105 if (rc != NO_ERROR) 103 106 { 104 107 kprintf(("ldrOpen: SftFileSize failed with rc=%d\n", rc)); 105 */106 108 cbFile = (unsigned)~0; 107 /* 108 } */ 109 } 109 110 110 111 /* … … 235 236 } 236 237 } 237 238 } 239 240 /* 241 * Only unreconized files and readerror passes this point! 242 * 243 * * Fileformats with lower priority should reside here. * 244 * 245 */ 246 247 /* 248 * If the initial readoperation failed try to read a smaller amount, in case it is a small script... 249 * 4 bytes is a small amount isn't it? 250 */ 251 if (rc != NO_ERROR) 252 { 253 kprintf(("ldrOpen: first ldrread failed with rc=%d. tries to read 4 byte.\n", rc)); 254 cchRead = 4; 255 if ((rc = ldrRead(*phFile, 0UL, pach, 0UL, cchRead, NULL)) != NO_ERROR) 256 kprintf(("ldrOpen: second ldrread failed with rc=%d.\n ", rc)); 257 } 258 259 /* 260 * Now we'll try again, UNIX styled script? 261 */ 262 if (rc == NO_ERROR && *pach == '#' && pach[1] == '!') 263 { 238 264 /* 239 * Only unreconized files and readerror passes this point!240 * 241 * * Fileformats with lower priority should reside here. *242 * 265 * UNIX styled script? 266 * FIXME! Must be more than 64 bytes long? 267 * No options! 268 * Firstline < 64 bytes! 243 269 */ 244 245 /* 246 * If the initial readoperation failed try to read a smaller amount, in case it is a small script... 247 * 4 bytes is a small amount isn't it? 248 */ 249 if (rc != NO_ERROR) 270 kprintf(("ldrOpen: unix script?\n")); 271 cchRead = min(cbFile, 256); 272 rc = ldrRead(*phFile, 0UL, pach, 0UL, cchRead, NULL); 273 if (rc == NO_ERROR) 250 274 { 251 kprintf(("ldrOpen: first ldrread failed with rc=%d. tries to read 4 byte.\n", rc)); 252 cchRead = 4; 253 if ((rc = ldrRead(*phFile, 0UL, pach, 0UL, cchRead, NULL)) != NO_ERROR) 254 kprintf(("ldrOpen: second ldrread failed with rc=%d.\n ", rc)); 255 } 256 257 /* 258 * Now we'll try again, UNIX styled script? 259 */ 260 if (rc == NO_ERROR && *pach == '#' && pach[1] == '!') 261 { 275 char *pszStart = pach+2; 276 kprintf(("ldrOpen: script debug 1\n")); 277 278 /* Make sure we don't read to much... */ 279 pszBuffer[cchRead] = '\0'; 280 262 281 /* 263 * UNIX styled script? 264 * FIXME! Must be more than 64 bytes long? 265 * No options! 266 * Firstline < 64 bytes! 282 * Skip blanks 267 283 */ 268 kprintf(("ldrOpen: unix script?\n")); 269 270 cchRead = min(cbFile, 256); 271 rc = ldrRead(*phFile, 0UL, pach, 0UL, cchRead, NULL); 272 if (rc != NO_ERROR) 284 pszStart = pszBuffer + 2; /* skips the "#!" stuff. */ 285 while (*pszStart != '\0' && (*pszStart == ' ' || *pszStart == '\t')) 286 pszStart++; 287 kprintf(("ldrOpen: script debug 2\n")); 288 289 /* anything left on the line? */ 290 if (*pszStart != '\0' && *pszStart != '\r' && *pszStart != '\n') 273 291 { 274 char *pszStart = pach+2; 275 kprintf(("ldrOpen: script debug 1\n")); 276 277 /* Make sure we don't read to much... */ 278 pszBuffer[cchRead] = '\0'; 292 char * pszEnd; /* Pointer to the end of the string(s) when the next step is finished. */ 293 unsigned cchToAdd = 1; /* Chars to add */ 294 BOOL fFirst = TRUE; /* Set if a '\0' has not been set yet. 295 * If this is clear, there are one or more parameters after the interpreter name. */ 279 296 280 297 /* 281 * Skip blanks 282 */ 283 pszStart = pszBuffer + 2; /* skips the "#!" stuff. */ 284 while (*pszStart != '\0' && (*pszStart == ' ' || *pszStart == '\t')) 285 pszStart++; 286 kprintf(("ldrOpen: script debug 2\n")); 287 288 /* anything left on the line? */ 289 if (*pszStart != '\0' && *pszStart != '\r' && *pszStart != '\n') 298 * find linesize and make parameters ready for copying 299 */ 300 pszEnd = pszStart; 301 kprintf(("ldrOpen: script debug 3\n")); 302 while (*pszEnd != '\0' && *pszEnd != '\r' && *pszEnd != '\n') 290 303 { 291 char * pszEnd; /* Pointer to the end of the string(s) when the next step is finished. */ 292 //char * pszFirstArg; /* Pointer to the first argument, the one after the interpreter name. */ 293 unsigned cchToAdd = 1; /* Chars to add */ 294 int f = TRUE; /* flag which tells me if I have just closed the last argument. */ 295 /* 296 * find linesize and make parameters ready for copying 297 */ 298 pszEnd = pszStart; 299 kprintf(("ldrOpen: script debug 3\n")); 300 //pszFirstArg = NULL; 301 while (*pszEnd != '\0' && *pszEnd != '\r' && *pszEnd != '\n') 304 if (fFirst && (*pszEnd == ' ' || *pszEnd == '\t')) 302 305 { 303 if (f) 304 { 305 f = FALSE; 306 //if (pszFirstArg != NULL) pszFirstArg = pszEnd + 1; 307 } 308 else if (!f && (*pszEnd == ' ' || *pszEnd == '\t')) 309 { 310 *pszEnd = '\0'; 311 f = TRUE; 312 } 313 314 /* next */ 315 pszEnd++; 316 cchToAdd++; 306 *pszEnd = '\0'; 307 fFirst = FALSE; 308 if (pszEnd[1] == '\0' || pszEnd[1] == '\r' || pszEnd[1] == '\n') 309 fFirst = TRUE; 317 310 } 318 *pszEnd = '\0'; 319 kprintf(("ldrOpen: script debug 4\n")); 320 311 312 /* next */ 313 pszEnd++; 314 cchToAdd++; 315 } 316 *pszEnd = '\0'; 317 kprintf(("ldrOpen: script debug 4\n")); 318 319 /* 320 * If ldrQueryApp type we don't have any ExecPgm buffer we need to mess with. 321 * We'll simply try open the the interpreter. 322 */ 323 if (fQAppType) 324 { 325 rc = ldrClose(*phFile); 326 rc = ldrOpen(phFile, pszStart, param3); /* FIXME, recusion! check that name not equal! Use flags to prevent race? */ 327 } 328 else 329 { 321 330 /* 322 331 * Find the ExecPgm buffer. … … 326 335 if (pBuffer != NULL) 327 336 { 328 unsigned cchArguments = getArgsLength(pBuffer->achArgs); 329 kprintf(("ldrOpen: debug1\n"));337 unsigned cchArguments = getArgsLength(pBuffer->achArgs); /* minus the first argument. */ 338 unsigned cchScriptnameDelta = strlen(pBuffer->szFilename) - strlen(pBuffer->achArgs); /* scriptname size difference. */ 330 339 331 340 kprintf(("ldrOpen: script debug 6\n")); … … 334 343 * Is there enough space in the struct? 335 344 */ 336 if (cchArguments + cchToAdd < sizeof(pBuffer->achArgs))345 if (cchArguments + cchToAdd + cchScriptnameDelta < sizeof(pBuffer->achArgs)) 337 346 { 338 347 kprintf(("ldrOpen: script debug 7\n")); … … 344 353 if (rc == NO_ERROR) 345 354 { 346 kprintf(("ldrOpen: scri tpdebug 8\n"));355 kprintf(("ldrOpen: script debug 8\n")); 347 356 /* Make space for the addition arguments. */ 348 memmove(&pBuffer->achArgs[cchToAdd], &pBuffer->achArgs[0], cchArguments); 349 memcpy(&pBuffer->achArgs[0], pszBuffer, cchToAdd); 350 kprintf(("ldrOpen: script debug 9\n")); 357 #ifdef DEBUG 358 char *psz = &pBuffer->achArgs[0]; 359 int i = 0; 360 while (*psz != '\0') 361 { 362 kprintf(("Arg %d: %s\n", i++, psz)); 363 psz += 1 + strlen(psz); 364 } 365 #endif 366 memmove(&pBuffer->achArgs[cchToAdd + cchScriptnameDelta], 367 &pBuffer->achArgs[0], cchArguments); 368 369 /* 370 * Copy the arguments. 371 */ 372 kprintf(("ldrOpen: script debug 8\n")); 373 memcpy(&pBuffer->achArgs[0], pszStart, cchToAdd); /* Interpreter with arguments */ 374 if (!fFirst) 375 pBuffer->achArgs[cchToAdd - 1] = ' '; 376 strcpy(&pBuffer->achArgs[cchToAdd], pszFilename); /* Scriptname */ 377 kprintf(("ldrOpen: script debug a\n")); 378 379 #ifdef DEBUG 380 psz = &pBuffer->achArgs[0]; 381 i = 0; 382 while (*psz != '\0') 383 { 384 kprintf(("Arg %d: %s\n", i++, psz)); 385 psz += 1 + strlen(psz); 386 } 387 #endif 351 388 } 352 389 else … … 365 402 } 366 403 } 367 else368 {369 kprintf(("ldrOpen: no interpereter on the first line.\n"));370 rc = ERROR_BAD_EXE_FORMAT; /*?*/371 }372 404 } 373 405 else 374 406 { 375 kprintf(("ldrOpen: read of min(cbFile, 256) = %d failed, rc = %d\n", cchRead, rc)); 407 kprintf(("ldrOpen: no interpereter on the first line.\n")); 408 rc = ERROR_BAD_EXE_FORMAT; /*?*/ 376 409 } 377 } /* else inn other formats here. */ 378 } 379 else 380 { 381 kprintf(("ldrOpen: ldrRead failed with rc=%d when reading DosHdr.\n", rc)); 382 rc = NO_ERROR; 383 } 410 } 411 else 412 { 413 kprintf(("ldrOpen: read of min(cbFile, 256) = %d failed, rc = %d\n", cchRead, rc)); 414 } 415 } /* else inn other formats here. */ 384 416 rfree(pszBuffer); 385 417 }
Note:
See TracChangeset
for help on using the changeset viewer.