diff options
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 136 |
1 files changed, 136 insertions, 0 deletions
@@ -406,6 +406,131 @@ freeChunks(void) | |||
406 | 406 | ||
407 | 407 | ||
408 | /* | 408 | /* |
409 | * Get the time string to be used for a file. | ||
410 | * This is down to the minute for new files, but only the date for old files. | ||
411 | * The string is returned from a static buffer, and so is overwritten for | ||
412 | * each call. | ||
413 | */ | ||
414 | const char * | ||
415 | timeString(time_t timeVal) | ||
416 | { | ||
417 | time_t now; | ||
418 | char * str; | ||
419 | static char buf[26]; | ||
420 | |||
421 | time(&now); | ||
422 | |||
423 | str = ctime(&timeVal); | ||
424 | |||
425 | strcpy(buf, &str[4]); | ||
426 | buf[12] = '\0'; | ||
427 | |||
428 | if ((timeVal > now) || (timeVal < now - 365*24*60*60L)) | ||
429 | { | ||
430 | strcpy(&buf[7], &str[20]); | ||
431 | buf[11] = '\0'; | ||
432 | } | ||
433 | |||
434 | return buf; | ||
435 | } | ||
436 | |||
437 | |||
438 | /* | ||
439 | * Routine to see if a text string is matched by a wildcard pattern. | ||
440 | * Returns TRUE if the text is matched, or FALSE if it is not matched | ||
441 | * or if the pattern is invalid. | ||
442 | * * matches zero or more characters | ||
443 | * ? matches a single character | ||
444 | * [abc] matches 'a', 'b' or 'c' | ||
445 | * \c quotes character c | ||
446 | * Adapted from code written by Ingo Wilken. | ||
447 | */ | ||
448 | BOOL | ||
449 | match(const char * text, const char * pattern) | ||
450 | { | ||
451 | const char * retryPat; | ||
452 | const char * retryText; | ||
453 | int ch; | ||
454 | BOOL found; | ||
455 | |||
456 | retryPat = NULL; | ||
457 | retryText = NULL; | ||
458 | |||
459 | while (*text || *pattern) | ||
460 | { | ||
461 | ch = *pattern++; | ||
462 | |||
463 | switch (ch) | ||
464 | { | ||
465 | case '*': | ||
466 | retryPat = pattern; | ||
467 | retryText = text; | ||
468 | break; | ||
469 | |||
470 | case '[': | ||
471 | found = FALSE; | ||
472 | |||
473 | while ((ch = *pattern++) != ']') | ||
474 | { | ||
475 | if (ch == '\\') | ||
476 | ch = *pattern++; | ||
477 | |||
478 | if (ch == '\0') | ||
479 | return FALSE; | ||
480 | |||
481 | if (*text == ch) | ||
482 | found = TRUE; | ||
483 | } | ||
484 | |||
485 | if (!found) | ||
486 | { | ||
487 | pattern = retryPat; | ||
488 | text = ++retryText; | ||
489 | } | ||
490 | |||
491 | /* fall into next case */ | ||
492 | |||
493 | case '?': | ||
494 | if (*text++ == '\0') | ||
495 | return FALSE; | ||
496 | |||
497 | break; | ||
498 | |||
499 | case '\\': | ||
500 | ch = *pattern++; | ||
501 | |||
502 | if (ch == '\0') | ||
503 | return FALSE; | ||
504 | |||
505 | /* fall into next case */ | ||
506 | |||
507 | default: | ||
508 | if (*text == ch) | ||
509 | { | ||
510 | if (*text) | ||
511 | text++; | ||
512 | break; | ||
513 | } | ||
514 | |||
515 | if (*text) | ||
516 | { | ||
517 | pattern = retryPat; | ||
518 | text = ++retryText; | ||
519 | break; | ||
520 | } | ||
521 | |||
522 | return FALSE; | ||
523 | } | ||
524 | |||
525 | if (pattern == NULL) | ||
526 | return FALSE; | ||
527 | } | ||
528 | |||
529 | return TRUE; | ||
530 | } | ||
531 | |||
532 | |||
533 | /* | ||
409 | * Write all of the supplied buffer out to a file. | 534 | * Write all of the supplied buffer out to a file. |
410 | * This does multiple writes as necessary. | 535 | * This does multiple writes as necessary. |
411 | * Returns the amount written, or -1 on an error. | 536 | * Returns the amount written, or -1 on an error. |
@@ -543,3 +668,14 @@ recursiveAction( const char *fileName, BOOL recurse, BOOL followLinks, | |||
543 | 668 | ||
544 | 669 | ||
545 | /* END CODE */ | 670 | /* END CODE */ |
671 | |||
672 | |||
673 | |||
674 | |||
675 | |||
676 | |||
677 | |||
678 | |||
679 | |||
680 | |||
681 | |||