/* ** Originally count.c, by Chris Stephens, stephenc@pcmail.cbil.vcu.edu, (c)1995. ** Code cleaned up and enhanced by Fred Christiansen, fredch@fc.hp.com, ** as odometer.c; supports: ** - 8 digits instead of 7 (and by changing ODO_DIGITS, up to 10 (number ** of digits in an unsigned long)) ** - acceptance of an argument to create a distinct counter file name; this ** permits refs like when ** used in combination with Ksh script odometer.cgi: ** exec ./odometer $QUERY_STRING */ #include #include char *bitmap[] = { "0xff","0xff","0xff","0xc3","0x99","0x99","0x99","0x99", /* rows 1-8 of 0 */ "0x99","0x99","0x99","0x99","0xc3","0xff","0xff","0xff", /* rows 9-16 of 0 */ "0xff","0xff","0xff","0xcf","0xc7","0xcf","0xcf","0xcf", /* rows 1-8 of 1 */ "0xcf","0xcf","0xcf","0xcf","0xcf","0xff","0xff","0xff", /* rows 9-16 of 1 */ "0xff","0xff","0xff","0xc3","0x99","0x9f","0x9f","0xcf", /* rows 1-8 of 2 */ "0xe7","0xf3","0xf9","0xf9","0x81","0xff","0xff","0xff", /* rows 9-16 of 2 */ "0xff","0xff","0xff","0xc3","0x99","0x9f","0x9f","0xc7", /* rows 1-8 of 3 */ "0x9f","0x9f","0x9f","0x99","0xc3","0xff","0xff","0xff", /* rows 9-16 of 3 */ "0xff","0xff","0xff","0xcf","0xcf","0xc7","0xc7","0xcb", /* rows 1-8 of 4 */ "0xcb","0xcd","0x81","0xcf","0x87","0xff","0xff","0xff", /* rows 9-16 of 4 */ "0xff","0xff","0xff","0x81","0xf9","0xf9","0xf9","0xc1", /* rows 1-8 of 5 */ "0x9f","0x9f","0x9f","0x99","0xc3","0xff","0xff","0xff", /* rows 9-16 of 5 */ "0xff","0xff","0xff","0xc7","0xf3","0xf9","0xf9","0xc1", /* rows 1-8 of 6 */ "0x99","0x99","0x99","0x99","0xc3","0xff","0xff","0xff", /* rows 9-16 of 6 */ "0xff","0xff","0xff","0x81","0x99","0x9f","0x9f","0xcf", /* rows 1-8 of 7 */ "0xcf","0xe7","0xe7","0xf3","0xf3","0xff","0xff","0xff", /* rows 9-16 of 7 */ "0xff","0xff","0xff","0xc3","0x99","0x99","0x99","0xc3", /* rows 1-8 of 8 */ "0x99","0x99","0x99","0x99","0xc3","0xff","0xff","0xff", /* rows 9-16 of 8 */ "0xff","0xff","0xff","0xc3","0x99","0x99","0x99","0x99", /* rows 1-8 of 9 */ "0x83","0x9f","0x9f","0xcf","0xe3","0xff","0xff","0xff" /* rows 9-16 of 9 */ }; /* Due to the id under which cgi's are executed, the perms on the following ** file needs to be 666. */ #define ODO_FILE "/usr/users/victor/html/.odo%s" /* prime w/ 1 */ #define UPDATE "r+" #define NL '\n' /* new line char */ #define ODO_DIGITS 8 /* # digits displayed */ #define BUFSIZE (ODO_DIGITS+2) /* 8 digits + NL + nul */ #define BM_HT 16 /* bitmap height */ #define BM_WD 8 /* bitmap width */ main(int argc, char *argv[]) { FILE *fp; char path[64], buf[BUFSIZE], dial[ODO_DIGITS]; unsigned long cnt; int i, l; char *p; /* Check args. Establish path to odometer file. */ if (argc != 2) exit(1); sprintf(path, ODO_FILE, argv[1]); /* Read current count (and rewind file), bump it, and write it out */ if ((fp = fopen(path, UPDATE)) == NULL) exit(1); lockf(fileno(fp), F_LOCK, 0); /* lock out concurrent writers */ fgets(buf, BUFSIZE, fp); rewind(fp); cnt = strtoul(buf, (char **)NULL, 10); fprintf(fp, "%u\n", ++cnt); fclose(fp); /* Calc length (ignoring NL) and copy right-to-left into dial */ for (l = 0, p = buf; *p != NL; l++, p++) ; for (i = 0, p = buf; i < l; i++, p++) dial[ODO_DIGITS - l + i] = *p; for (i = 0; i < (ODO_DIGITS - l); i++) /* backfill with zeros */ dial[i] = '0'; /* Print the XBM definition */ printf("Content-type: image/x-xbitmap\n\n"); printf("#define odo_width %d\n", (BM_WD*ODO_DIGITS)); printf("#define odo_height %d\n", BM_HT); printf("static char odo_bits[] = {\n"); for (i = 0; i < BM_HT; i++) { for (l = 0; l < ODO_DIGITS; l++) { printf("%s, ", bitmap[(((dial[l]-'0')*BM_HT)+i)]); if (l == 7) printf("\n"); } if (i == 15) printf("};"); } printf("\n"); exit(0); }