/* * counter - A rudimentary web page counter. * Written by Mike Henderson, 1995 * Copyright Mike Henderson, 1995 * */ #include #define width 114 /* 19*6 */ #define height 25 #define htroot "/n/leadbelly/belly1/www/htdocs" int DEBUG= 0; main(){ char str[20], comments[80], filename[20]; char pbmtype[20], cntr_file[120], cntr_gif[120], digits_path[120]; char cntr_gif2[120]; char *user, *page, *fname, *caller; int X, Y, MaxVal, x, y, i, tmp; unsigned char image[2850]; unsigned char red[256], grn[256], blu[256]; long count; FILE *fp, *fp_out; /* * Print out the neccessary text for server to recognize this as html */ printf("Content-type: text/html\n\n"); /* * We need to determine which user's index.shtml script has invoked this * program. I'd prefer not the trust the user to supply that info as in * the PATH_INFO env variable. Rather, for server side includes, the * additional variable DOCUMENT_URI can be used. It will contain the path * of the html file that called this program (e.g. /~mgh/index.shtml) * Just need to parse it properly. This is all done in get_user() */ caller = (char *)getenv("DOCUMENT_URI"); /* * Set some filenames and paths that we need. */ sprintf(cntr_file, "%s/%s_counter", htroot, caller); sprintf(cntr_gif, "%s/%s_counter.gif", htroot, caller); sprintf(cntr_gif2, "%s_counter.gif", caller); sprintf(digits_path, "/n/leadbelly/belly1/www/cgi-bin/CCR_forms/counter"); /* * Open the .counter file and increment count. * If it doesnt exist, then count is 0 and the file will get created below. */ count = 0; if ((fp = fopen(cntr_file, "r")) != NULL){ fscanf(fp, "%d", &count); fclose(fp); } ++count; sprintf(str, "%06d", count); /* * generate a grey scale color table. Needed for GIF image. Note that * the images I use are not just BW because they are antialiased! */ for(i=0; i<256; ++i){ red[i] = (unsigned char)i; grn[i] = (unsigned char)i; blu[i] = (unsigned char)i; } /* * for each digit, read in the appropriate file * and paste into the image array. * Could be sped up quite a bit by not reading files * that have already been read. Also could store digits in * binary to speed up. Image could also use some beautifying... * Motif style 3D frame would be easy. Also, Tekton font would * look alot better than Tex's CM fonts! Could allow coice of * several fonts? This loop needs error checking on file I/O ... */ for(i=0; i<6; ++i){ sprintf(filename, "%s/%1d_tekton.pgm", digits_path, str[i]-48); fp = fopen(filename, "r"); /* must be a PPM file to work for now */ fscanf(fp, "%s", pbmtype); fgets(comments, 80, fp); fgets(comments, 80, fp); fscanf(fp, "%d %d", &X, &Y); fscanf(fp, "%d", &MaxVal); for (y=0; y\n", cntr_gif2); /* printf("%06d\n", count); */ if ((fp = fopen(cntr_file, "w")) != NULL){ fprintf(fp, "%06d\n", count); fclose(fp); } else{ printf("could not write to file: %s\n", cntr_file); } }