Clownfish-CFC

 view release on metacpan or  search on metacpan

src/CFCTest.c  view on Meta::CPAN

510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
    CFCBase *result = CFCParser_parse(parser, src);
    OK(test, result != NULL, "parse class");
    STR_EQ(test, CFCBase_get_cfc_class(result),
           "Clownfish::CFC::Model::Class", "result class");
    return (struct CFCClass*)result;
}
 
time_t
CFCTest_get_file_mtime(const char *path) {
    struct stat buf;
    if (stat(path, &buf)) {
        CFCUtil_die("Can't stat '%s': %s", path, strerror(errno));
    }
    return buf.st_mtime;
}
 
#if defined(CHY_HAS_WINDOWS_H)
 
#include <windows.h>
 
void

src/CFCUtil.c  view on Meta::CPAN

354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
char
CFCUtil_toupper(char c) {
    if (!IS_ASCII(c)) { return c; }
    return (char)toupper(c);
}
 
int
CFCUtil_current(const char *orig, const char *dest) {
    // If the destination file doesn't exist, we're not current.
    struct stat dest_stat;
    if (stat(dest, &dest_stat) == -1) {
        return false;
    }
 
    // If the source file is newer than the dest, we're not current.
    struct stat orig_stat;
    if (stat(orig, &orig_stat) == -1) {
        CFCUtil_die("Missing source file '%s': %s", orig, strerror(errno));
    }
    if (orig_stat.st_mtime > dest_stat.st_mtime) {
        return false;
    }
 
    // Current!
    return 1;
}

src/CFCUtil.c  view on Meta::CPAN

478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
    if (len == -1) { CFCUtil_die("ftell error : %s\n", strerror(errno)); }
 
    /* Return to where we were. */
    check_val = fseek(f, bookmark, SEEK_SET);
    if (check_val == -1) { CFCUtil_die("fseek error : %s\n", strerror(errno)); }
 
    return len;
}
 
// Note: this has to be defined before including the Perl headers because they
// redefine stat() in an incompatible way on certain systems (Windows).
int
CFCUtil_is_dir(const char *path) {
    struct stat stat_buf;
    int stat_check = stat(path, &stat_buf);
    if (stat_check == -1) {
        return false;
    }
    return (stat_buf.st_mode & S_IFDIR) ? true : false;
}
 
int
CFCUtil_make_path(const char *path) {
    CFCUTIL_NULL_CHECK(path);
    char *target = CFCUtil_strdup(path);
    size_t orig_len = strlen(target);
    size_t len = orig_len;
    for (size_t i = 0; i <= len; i++) {
        if (target[i] == CHY_DIR_SEP_CHAR || i == len) {
            target[i] = 0; // NULL-terminate.
            struct stat stat_buf;
            int stat_check = stat(target, &stat_buf);
            if (stat_check != -1) {
                if (!(stat_buf.st_mode & S_IFDIR)) {
                    CFCUtil_die("%s isn't a directory", target);
                }
            }
            else {
                int success = CFCUtil_make_dir(target);
                if (!success) {
                    FREEMEM(target);
                    return false;

src/CFCUtil.c  view on Meta::CPAN

525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
    FREEMEM(target);
    return true;
}
 
void
CFCUtil_walk(const char *path, CFCUtil_walk_callback_t callback,
             void *context) {
    // If it's a valid file system entry, invoke the callback.
    struct stat stat_buf;
    int stat_check = stat(path, &stat_buf);
    if (stat_check == -1) {
        return;
    }
    callback(path, context);
 
    // Recurse into directories.
    if (!(stat_buf.st_mode & S_IFDIR)) {
        return;
    }
    void   *dirhandle = CFCUtil_opendir(path);

t/001-util.t  view on Meta::CPAN

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
ok( current( $foo_txt, $foo_txt ), "current" );
ok( !current( $foo_txt, 't' ), "not current" );
ok( !current( $foo_txt, "nonexistent_file" ),
    "not current when dest file mising"
);
 
my $ten_seconds_ago = time() - 10;
utime( $ten_seconds_ago, $ten_seconds_ago, $foo_txt )
    or die "utime failed";
write_if_changed( $foo_txt, "foo" );
is( stat($foo_txt)->mtime, $ten_seconds_ago,
    "write_if_changed does nothing if contents not changed" );
write_if_changed( $foo_txt, "foofoo" );
ok( stat($foo_txt)->mtime != $ten_seconds_ago,
    "write_if_changed writes if contents changed"
);
 
unlink $foo_txt;
 
my %defaults = ( foo => undef );
sub test_verify_args { return verify_args( \%defaults, @_ ) }
 
ok( test_verify_args( foo => 'foofoo' ), "args verified" );
ok( !test_verify_args('foo'), "odd args fail verification" );



( run in 0.463 second using v1.01-cache-2.11-cpan-49f99fa48dc )