/* "getsett.c" version 1.1 * * Copyright 1995-2004 Thomas Insel (tinsel@jaka.ece.uiuc.edu) * * You may redistribute this file provided it is unchanged and you * include the entirety of this notice and disclaimer. You may * distribute a compiled version of this file provided you reproduce * the entirety of this notice and disclaimer in the documentation * and/or other materials provided with the distribution. * * Please contact the author if you wish to distribute this file under * different conditions or have changes to the file. * * You may obtain the current version of this file from * http://jaka.ece.uiuc.edu/~tinsel/Java/Tartan/src/getsett.c * * DISCLAIMER * * This software is provided "as is" and any express or implied * warranties, including, but not limited to the implied warranties of * merchantability and fitness for a particular purpose are * disclaimed. * * In no event shall Thomas Insel be liable for any direct, indirect, * special, exemplary, or consequential damages (including, but not * limited to, procurement of substitute goods or services; loss of * use, data, or profits; or business interruption) however caused an * on any theory of liability, whether in contract, strict liability, * or tort (including negligence or otherwise) arising in any way out * of the use of this software, even if advised of the possibility of * such damage. */ #include #include #define SETTFILE "/home/tinsel/public_html/Java/Tartan/setts.txt" #define DELIMS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \t\r\n" /* List all setts in the file. */ listSetts(FILE *fred) { char read_buffer[2048]; char *ind; printf("Index of Setts\n"); printf("

Index of Setts

\n"); } /* Count threads in a given sett. */ int threadcount(char *s, int sym) { int sum = 0, last=0, laster=0, first; char *t; t = strtok(strdup(s), DELIMS); first = atoi(t); while (t != NULL) { laster = last; last = atoi(t); if (sym==0) sum += last; else sum += 2*last; t = strtok(NULL, DELIMS); } if (sym==1) sum -= (last+first); if (sym==2) sum -= (last+laster); return sum; } /* Print the web page for a particular sett, specified by name */ printSett(FILE *fred, char *settname) { char read_buffer[2048]; char printed=0, *ind1=NULL; int tc, symm; printf("%s

%s

\n", settname, settname); while (!feof(fred)) { fgets(read_buffer, 2048, fred); if (strncasecmp(read_buffer, settname, strlen(settname)) == 0 && read_buffer[strlen(settname)] == ' ') { ind1 = index(read_buffer, ' '); read_buffer[strlen(read_buffer) - 1] = 0; if (ind1[1] == '(') { if (ind1[2] == 'a') symm = 0; else symm = 2; ind1+=4; } else symm = 1; tc = threadcount(ind1+1,symm); printf("\n", tc, tc); printf("\n", ind1+1); printf("\n", symm); printf("\n"); printf("\n"); printf("

%s\n", ind1+1); if (symm==0) printf(" (asymmetric)"); else if (symm==2) printf(" (double-pivot)"); printf("

\n"); printed++; break; } } if(!printed) printf("

Sorry, can't find %s.

\n", settname); printf("

You can return to the "); printf("index of setts.

\n"); printf("
Thomas Insel / "); printf("tinsel@jaka.ece.uiuc.edu
\n"); } main(int argc, char *argv[]) { FILE *fred; printf("Content-type: text/html\n\n"); if ( (fred = fopen(SETTFILE, "r")) == NULL ) { printf("getsett: can't read quote file.\n"); exit(0); } if (argc == 2) printSett(fred, argv[1]); else listSetts(fred); fclose(fred); }