Example #1
0
/* Decrement date info in `*ptm', update the date string in `dst',
   and check if the .../yyyy/mm directory (which is a part of `dst')
   exists. If it does not exist, decrementDate() goes beyound and
   tries to find an old .../yyyy/mm directory until Nyears back.
   Returns 1 if it exists, otherwise returns 0.
   This function is recursive.
 */
int
decrementDate (char* dst, char* date, struct tm* ptm)
{
    char* dend;                 /* end of date string */
    int   mchange = 0;          /* 1 if month changed */
    int   ychange = 0;          /* 1 if year changed */
    pathInfo rs;              /* return status from doesPathExist() */


    assert(dst);
    assert(date);
    assert(ptm);

    if (ptm->tm_mday == 1) {
        mchange = 1;            /* month changed */
        ptm->tm_mday = 31;      /* reset mday. Ok to ignore short months  */
        if (ptm->tm_mon <= 0) { /* year changed */
            ychange = 1;
            --ptm->tm_year;
            ptm->tm_mon = 11;   /* reset month */
        } else {
            --ptm->tm_mon;
        }
    } else {
        --ptm->tm_mday;
    }

    if (ychange) {
        dend = date + 4;        /* end ptr of .../yyyy */
        assert(*dend == '/');
        for (; ptm->tm_yday - ptm->tm_year <= Nyears; --ptm->tm_year) {
            sprintf(date, "%04d", ptm->tm_year + 1900);
            rs = doesPathExist(dst, NULL);
            *dend = '/';        /* sprintf() terminates string */
            if (rs) return 1;
        }
        return 0;               /* no old .../yyyy directories */
    }

    if (mchange) {
        dend = date + 7;        /* end ptr of .../yyyy/mm */
        assert(*dend == '/');
        for (; ptm->tm_mon >= 0; --ptm->tm_mon) {
            sprintf(date, "%04d/%02d", ptm->tm_year + 1900, ptm->tm_mon + 1);
            rs = doesPathExist(dst, NULL);
            *dend = '/';        /* sprintf() terminates string */
            if (rs) return 1;
        }
        ptm->tm_mday = 1;       /* reset date to 01/01/yyyy */
        ptm->tm_mon  = 0;
        return decrementDate(dst, date, ptm);
    } else {
        return 1;               /* no year/month change */
    }

    errExit(("should not happen"));
    return 0;
}
Example #2
0
static CFStringRef py2app_findPyLocation(CFArrayRef pyLocations) {
    CFIndex i;
    CFIndex cnt = py2app_CFArrayGetCount(pyLocations);
    for (i = 0; i < cnt; i++) {
        CFStringRef newLoc;
        CFStringRef pyLocation = py2app_CFArrayGetValueAtIndex(pyLocations, i);
        newLoc = pyStandardizePath(pyLocation);
        if (!newLoc) {
		newLoc = pyLocation;
		py2app_CFRetain(newLoc);
	}
        if (doesPathExist(newLoc)) {
            return newLoc;
        }
        if (newLoc) py2app_CFRelease(newLoc);
    }
    return NULL;
}
Example #3
0
/* Print backup history of `dst'
 */
void
prHistory (char* dst, char* date, struct tm* ptm)
{
    ino_t inode;
    pathInfo rs;                /* return status */
    int   len = 0;
    char* prev;
    char* pd;                   /* date ptr for `prev' */


    assert(dst);
    assert(date);
    assert(ptm);

    prev = malloc(strlen(dst));
    if (!prev) {
        errSysExit(("malloc(strlen(dst))"));
    }
    pd = prev + (date - dst);

    strcpy(prev, dst);
    inode = 0;
    for (;;) {
        sprintf(date, "%04d/%02d/%02d",
                         ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday);
        if (len == 0) {
            len   = strlen(date);
        }
        *(date + len) = '/'; /* sprintf() tereminates string */
        rs = doesPathExist(dst, &inode);
        if (rs == INODE_CHANGE) {
            printf("%s\n", prev);
        }
        if (rs != INODE_NOPATH) {
            sprintf(pd, "%04d/%02d/%02d",
                         ptm->tm_year + 1900, ptm->tm_mon + 1, ptm->tm_mday);
            *(pd + len) = '/'; /* sprintf() tereminates string */
        }
        if (!decrementDate(dst, date, ptm)) break;
    }
    if (inode) {
        printf("%s\n", prev);
    }
}