Changeset 312 for trunk/dll/avl.c
- Timestamp:
- Jun 28, 2006, 11:35:26 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dll/avl.c
r306 r312 20 20 30 May 06 SHL load_archivers: add reload support 21 21 16 Jun 06 SHL load_archivers: support signatures containing 0s 22 26 Jun 06 SHL load_archivers: remember where comments are 22 23 23 24 ***********************************************************************/ … … 45 46 //=== quick_find_type() === 46 47 47 ARC_TYPE *quick_find_type(CHAR * filespec, ARC_TYPE *topsig)48 ARC_TYPE *quick_find_type(CHAR *filespec, ARC_TYPE *topsig) 48 49 { 49 50 ARC_TYPE *info, *found = NULL; … … 155 156 } 156 157 157 ARC_TYPE *find_type(CHAR * filespec, ARC_TYPE *topsig)158 ARC_TYPE *find_type(CHAR *filespec, ARC_TYPE *topsig) 158 159 { 159 160 HFILE handle; … … 272 273 } 273 274 274 #pragma alloc_text(AVL,load_archivers, get_archiver_line) 275 276 //=== get_archiver_line() read line, strip comments and whitespace === 275 static UINT cur_line_num; // Input file line counter 276 277 #pragma alloc_text(AVL,load_archivers, get_line_strip_comments, get_line_strip_white) 278 279 //=== get_line_strip_comments() read line, strip comments and whitespace === 277 280 278 281 #define ARCHIVER_LINE_BYTES 256 279 282 280 static PSZ get_ archiver_line(PSZ pszIn, FILE * pf)283 static PSZ get_line_strip_comments(PSZ pszIn, FILE *fp) 281 284 { 282 PSZ psz = fgets(pszIn, ARCHIVER_LINE_BYTES, pf);285 PSZ psz = fgets(pszIn, ARCHIVER_LINE_BYTES, fp); 283 286 PSZ psz2; 284 287 285 if (psz) 286 {288 if (psz) { 289 cur_line_num++; 287 290 psz2 = strchr(pszIn, ';'); 288 291 if (psz2) … … 294 297 } 295 298 296 //=== get_ archiver_line2() read line, strip whitespace ===297 298 static PSZ get_ archiver_line2(PSZ pszIn, FILE * pf)299 //=== get_line_strip_white() read line, strip whitespace === 300 301 static PSZ get_line_strip_white(PSZ pszIn, FILE *fp) 299 302 { 300 PSZ psz = fgets(pszIn, ARCHIVER_LINE_BYTES, pf); 301 302 if (psz) 303 PSZ psz = fgets(pszIn, ARCHIVER_LINE_BYTES, fp); 304 305 if (psz) { 306 cur_line_num++; 303 307 bstripcr(pszIn); // Strip lead white and trailing white and CR/LF 308 } 304 309 305 310 return psz; … … 310 315 INT load_archivers(VOID) 311 316 { 312 FILE *handle; 313 CHAR s[ARCHIVER_LINE_BYTES + 1]; 314 CHAR *p; 315 ARC_TYPE *pat; 316 ARC_TYPE *patLast; 317 INT numlines = NUMLINES; 317 FILE *fp; 318 CHAR sz[ARCHIVER_LINE_BYTES + 1]; 319 CHAR *psz; 320 ARC_TYPE *pat = NULL; 321 ARC_TYPE *patLast = NULL; 322 UINT lines_per_arcsig = LINES_PER_ARCSIG; 323 UINT per_sig_comment_line_num = 0; 318 324 INT i; 319 325 326 // Free current signatures 320 327 if (arcsighead) { 321 328 for (pat = arcsighead; pat;) { … … 328 335 329 336 arcsigsmodified = FALSE; 337 arcsigs_header_lines = 0; 338 arcsigs_trailer_line_num = 0; 330 339 331 340 DosEnterCritSec(); 332 p = searchpath(GetPString(IDS_ARCHIVERBB2));333 if (!p || !*p)341 psz = searchpath(GetPString(IDS_ARCHIVERBB2)); 342 if (!psz || !*psz) 334 343 { 335 344 DosExitCritSec(); 336 345 return -1; 337 346 } 338 handle = _fsopen(p, "r", SH_DENYWR);347 fp = _fsopen(psz, "r", SH_DENYWR); 339 348 DosExitCritSec(); 340 if (! handle)349 if (!fp) 341 350 return -2; 342 strcpy(archiverbb2, p); 343 // Get lines per record count 344 if (!get_archiver_line(s, handle)) 351 strcpy(archiverbb2, psz); // Remember full path 352 353 cur_line_num = 0; 354 355 // Line 1 must contain number of lines per signature definition 356 if (!get_line_strip_comments(sz, fp)) 345 357 { 346 fclose( handle);358 fclose(fp); 347 359 return -3; 348 360 } 349 if (*s )350 numlines = atoi(s);351 if (!*s || numlines < NUMLINES)361 if (*sz) 362 lines_per_arcsig = atoi(sz); 363 if (!*sz || lines_per_arcsig < LINES_PER_ARCSIG) 352 364 return -3; 353 // Parse rest 354 pat = NULL; 355 patLast = NULL; 356 while (!feof(handle)) 365 366 // Parse rest of file 367 // 1st non-blank line starts definition 368 // Need to determine header size and start of trailer 369 370 while (!feof(fp)) 357 371 { 358 if (!get_archiver_line(s, handle)) 359 break; // EOF 360 // 1st non-blank line starts definition 361 // fixme to preserve comments 372 // If reading header 373 if (!arcsigs_header_lines) { 374 // Reading header - find header size and start of signtures 375 if (!get_line_strip_white(sz, fp)) 376 break; // Unexpected EOF 377 if (stristr(sz, "-- Current Archivers --")) { 378 arcsigs_header_lines = cur_line_num; 379 continue; 380 } 381 if (!*sz || *sz == ';') 382 continue; // Header comment or blank line 383 else { 384 // Not a comment, must be start of signatures 385 PSZ psz2 = strchr(sz, ';'); 386 if (psz2) { 387 *psz2 = 0; // Chop trailing comment 388 bstripcr(sz); // Strip leading white and trailing white and CR/LF 389 } 390 arcsigs_header_lines = cur_line_num - 1; 391 } 392 } 393 else { 394 // Reading defintiions 395 if (!get_line_strip_comments(sz, fp)) 396 break; // EOF 397 } 398 362 399 // fixme to avoid allocating empty fields 363 400 364 if (*s) 365 { 401 // Remember start of per sig comments for next definition 402 if (per_sig_comment_line_num == 0) 403 per_sig_comment_line_num = cur_line_num; 404 405 if (*sz) 406 { 407 // At start of defintion 408 366 409 pat = malloc(sizeof(ARC_TYPE)); 367 410 if (!pat) … … 369 412 370 413 memset(pat, 0, sizeof(ARC_TYPE)); 371 pat -> id = strdup(s); 372 if (!get_archiver_line(s, handle)) // line 2 373 374 break; 375 if (*s) 376 pat -> ext = strdup(s); 414 pat -> id = strdup(sz); 415 416 pat -> comment_line_num = per_sig_comment_line_num; 417 pat -> defn_line_num = cur_line_num; 418 419 if (!get_line_strip_comments(sz, fp)) // line 2 - extension 420 break; 421 if (*sz) 422 pat -> ext = strdup(sz); 377 423 else 378 424 pat -> ext = NULL; 379 if (!get_archiver_line(s, handle)) // line 3 380 381 break; 382 pat -> file_offset = atol(s); 383 if (!get_archiver_line(s, handle)) // line 4 384 385 break; 386 if (*s) 387 pat -> list = strdup(s); 425 if (!get_line_strip_comments(sz, fp)) // line 3 - offset to signature 426 break; 427 pat -> file_offset = atol(sz); 428 if (!get_line_strip_comments(sz, fp)) // line 4 - list command 429 break; 430 if (*sz) 431 pat -> list = strdup(sz); 388 432 else 389 433 pat -> list = NULL; 390 434 if (!pat -> list) 391 break; 392 if (!get_archiver_line(s, handle)) // line 5 393 394 break; 395 if (*s) 396 pat -> extract = strdup(s); 435 break; // Must have list command - fixme to complain 436 if (!get_line_strip_comments(sz, fp)) // line 5 437 break; 438 if (*sz) 439 pat -> extract = strdup(sz); 397 440 else 398 441 pat -> extract = NULL; 399 if (!get_archiver_line(s, handle)) // line 6 400 401 break; 402 if (*s) 403 pat -> exwdirs = strdup(s); 442 if (!get_line_strip_comments(sz, fp)) // line 6 443 break; 444 if (*sz) 445 pat -> exwdirs = strdup(sz); 404 446 else 405 447 pat -> exwdirs = NULL; 406 if (!get_archiver_line(s, handle)) // line 7 407 408 break; 409 if (*s) 410 pat -> test = strdup(s); 448 if (!get_line_strip_comments(sz, fp)) // line 7 449 break; 450 if (*sz) 451 pat -> test = strdup(sz); 411 452 else 412 453 pat -> test = NULL; 413 if (!get_archiver_line(s, handle)) // line 8 414 415 break; 416 if (*s) 417 pat -> create = strdup(s); 454 if (!get_line_strip_comments(sz, fp)) // line 8 455 break; 456 if (*sz) 457 pat -> create = strdup(sz); 418 458 else 419 459 pat -> create = NULL; 420 if (!get_archiver_line(s, handle)) // line 9 421 422 break; 423 if (*s) 424 pat -> createwdirs = strdup(s); 460 if (!get_line_strip_comments(sz, fp)) // line 9 461 break; 462 if (*sz) 463 pat -> createwdirs = strdup(sz); 425 464 else 426 465 pat -> createwdirs = NULL; 427 if (!get_archiver_line(s, handle)) // line 10 428 429 break; 430 if (*s) 431 pat -> createrecurse = strdup(s); 466 if (!get_line_strip_comments(sz, fp)) // line 10 467 break; 468 if (*sz) 469 pat -> createrecurse = strdup(sz); 432 470 else 433 471 pat -> createrecurse = NULL; 434 if (!get_archiver_line(s, handle)) // line 11 435 436 break; 437 if (*s) 438 pat -> move = strdup(s); 472 if (!get_line_strip_comments(sz, fp)) // line 11 473 break; 474 if (*sz) 475 pat -> move = strdup(sz); 439 476 else 440 477 pat -> move = NULL; 441 if (!get_archiver_line(s, handle)) // line 12 442 443 break; 444 if (*s) 445 pat -> movewdirs = strdup(s); 478 if (!get_line_strip_comments(sz, fp)) // line 12 479 break; 480 if (*sz) 481 pat -> movewdirs = strdup(sz); 446 482 else 447 483 pat -> movewdirs = NULL; 448 if (!get_archiver_line(s, handle)) // line 13 449 450 break; 451 pat -> delete = strdup(s); 452 453 if (!get_archiver_line2(s, handle)) // line 14 454 break; 455 i = literal(s); // Translate \ escapes 484 if (!get_line_strip_comments(sz, fp)) // line 13 485 break; 486 if (*sz) 487 pat -> delete = strdup(sz); 488 else 489 pat -> delete = NULL; 490 if (!get_line_strip_white(sz, fp)) // line 14 491 break; 492 i = literal(sz); // Translate \ escapes 456 493 if (i) 457 494 { … … 460 497 if (!pat -> signature) 461 498 break; 462 memcpy(pat -> signature, s , i); // signature may not be a string499 memcpy(pat -> signature, sz, i); // signature may not be a string 463 500 } 464 501 else { … … 466 503 pat -> signature = NULL; 467 504 } 468 if (!get_archiver_line2(s, handle)) // line 15 469 470 break; 471 if (*s) 472 pat -> startlist = strdup(s); 505 if (!get_line_strip_white(sz, fp)) // line 15 506 break; 507 if (*sz) 508 pat -> startlist = strdup(sz); 473 509 else 474 510 pat -> startlist = NULL; 475 if (!get_archiver_line2(s, handle)) // line 16 476 477 break; 478 if (*s) 479 pat -> endlist = strdup(s); 511 if (!get_line_strip_white(sz, fp)) // line 16 512 break; 513 if (*sz) 514 pat -> endlist = strdup(sz); 480 515 else 481 516 pat -> endlist = NULL; 482 if (!get_archiver_line(s, handle)) // line 17 483 484 break; 485 pat -> osizepos = atoi(s); 486 if (!get_archiver_line(s, handle)) // line 18 487 488 break; 489 pat -> nsizepos = atoi(s); 490 if (!get_archiver_line(s, handle)) // line 19 491 492 break; 493 pat -> fdpos = atoi(s); 494 p = strchr(s, ','); 495 if (p) 496 { 497 p++; 498 pat -> datetype = atoi(p); 499 } 500 if (!get_archiver_line(s, handle)) // line 20 501 502 break; 503 pat -> fdflds = atoi(s); 504 if (!get_archiver_line(s, handle)) // line 21 505 506 break; 507 pat -> fnpos = atoi(s); 508 p = strchr(s, ','); 509 if (p) 510 { 511 p++; 512 pat -> nameislast = (BOOL) (*p && atol(p) == 0) ? FALSE : TRUE; 513 p = strchr(p, ','); 514 if (p) 517 if (!get_line_strip_comments(sz, fp)) // line 17 518 break; 519 pat -> osizepos = atoi(sz); 520 if (!get_line_strip_comments(sz, fp)) // line 18 521 break; 522 pat -> nsizepos = atoi(sz); 523 if (!get_line_strip_comments(sz, fp)) // line 19 524 break; 525 pat -> fdpos = atoi(sz); 526 psz = strchr(sz, ','); 527 if (psz) 528 { 529 psz++; 530 pat -> datetype = atoi(psz); 531 } 532 if (!get_line_strip_comments(sz, fp)) // line 20 533 break; 534 pat -> fdflds = atoi(sz); 535 if (!get_line_strip_comments(sz, fp)) // line 21 536 break; 537 pat -> fnpos = atoi(sz); 538 psz = strchr(sz, ','); 539 if (psz) 540 { 541 psz++; 542 pat -> nameislast = (BOOL) (*psz && atol(psz) == 0) ? FALSE : TRUE; 543 psz = strchr(psz, ','); 544 if (psz) 515 545 { 516 p ++;517 pat -> nameisnext = (BOOL) (*p && atol(p) == 0) ? FALSE : TRUE;518 p = strchr(p, ',');519 if (p )546 psz++; 547 pat -> nameisnext = (BOOL) (*psz && atol(psz) == 0) ? FALSE : TRUE; 548 psz = strchr(psz, ','); 549 if (psz) 520 550 { 521 p ++;522 pat -> nameisfirst = (BOOL) (*p && atol(p) == 0) ? FALSE : TRUE;551 psz++; 552 pat -> nameisfirst = (BOOL) (*psz && atol(psz) == 0) ? FALSE : TRUE; 523 553 } 524 554 } 525 555 } 526 556 // Ignore unknown lines - must be newer file format 527 for (i = NUMLINES; i < numlines; i++) 528 { 529 if (!get_archiver_line(s, handle)) 530 break; 531 } 532 533 pat -> next = NULL; 534 557 for (i = LINES_PER_ARCSIG; i < lines_per_arcsig; i++) 558 { 559 if (!get_line_strip_comments(sz, fp)) 560 break; // Unexpected EOF - fixme to complain 561 } 562 563 // Add to list, assume next and prev already NULL 535 564 if (!arcsighead) 536 {537 565 arcsighead = patLast = pat; 538 pat -> prev = NULL;539 }540 566 else 541 567 { … … 544 570 patLast = pat; 545 571 } 546 if (pat -> extract && !*pat -> extract) 547 { 548 free(pat -> extract); 549 pat -> extract = NULL; 550 } 572 pat = NULL; // Done with this defintion 573 574 arcsigs_trailer_line_num = cur_line_num + 1; // In case this is last defintion 575 per_sig_comment_line_num = 0; 551 576 } // if got definition 552 577 553 pat = NULL;554 } // while lines 555 fclose( handle);556 557 free_arc_type(pat); 578 } // while more lines 579 580 fclose(fp); 581 582 free_arc_type(pat); // In case partial definition in progress 558 583 559 584 if (!arcsighead) … … 1081 1106 #pragma alloc_text(ARCCNRS,ArcDateTime) 1082 1107 1083 BOOL ArcDateTime(CHAR * dt, INT type, CDATE * cdate, CTIME *ctime)1108 BOOL ArcDateTime(CHAR *dt, INT type, CDATE *cdate, CTIME *ctime) 1084 1109 { 1085 1110 INT x;
Note:
See TracChangeset
for help on using the changeset viewer.