8 * Compare a string to a mask
10 * @ - uppercase letter
11 * # - lowercase letter
14 * * - swallow remaining characters
15 * <x> - exact match for any other character
17 static int checkmask(const char *data, const char *mask)
21 for (i = 0; mask[i] != '\0' && mask[i] != '*'; i++) {
47 return (data[i] == '\0');
51 * Converts 8 hex digits to a time integer
53 static int hex2sec(const char *x)
58 for (i = 0, j = 0; i < 8; i++) {
69 return -1; /* so that it works with 8-byte ints */
74 int main(int argc, char **argv)
81 char path[FILENAME_MAX + 1];
83 time_t date, lmod, expire;
86 char sdate[30], slmod[30], sexpire[30];
87 const char time_format[] = "%e %b %Y %R";
90 printf("Usage: cls directory\n");
105 if (s[0] == '.' || s[0] == '#')
107 sprintf(path, "%s/%s", argv[1], s);
108 fp = fopen(path, "r");
113 if (fgets(line, 1034, fp) == NULL) {
118 if (!checkmask(line, "&&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&&\n")) {
119 fprintf(stderr, "Bad cache file\n");
123 date = hex2sec(line);
124 lmod = hex2sec(line + 9);
125 expire = hex2sec(line + 18);
126 ver = hex2sec(line + 27);
127 len = hex2sec(line + 35);
128 if (fgets(line, 1034, fp) == NULL) {
135 if (strncmp(line, "X-URL: ", 7) != 0 || line[i - 1] != '\n') {
136 fprintf(stderr, "Bad cache file\n");
142 strftime(sdate, 30, time_format, &ts);
149 strftime(slmod, 30, time_format, &ts);
155 ts = *gmtime(&expire);
156 strftime(sexpire, 30, time_format, &ts);
159 strcpy(sexpire, "-");
161 printf("%s: %d; %s %s %s\n", line + 7, ver, sdate, slmod, sexpire);