home *** CD-ROM | disk | FTP | other *** search
- Path: vixen.cso.uiuc.edu!arh0268!not-for-mail
- From: Dannyman@enteract.com (Unknown)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Bored? Tell me why my code crashes! :)
- Date: 22 Mar 1996 03:02:57 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4it591$aov@vixen.cso.uiuc.edu>
- NNTP-Posting-Host: arh0268.urh.uiuc.edu
- X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
-
- Short program follows introduction!
-
- It works, sometimes, but just crashes others. As nearly as I can tell,
- it's the pettern matching stuff .... everything else seems to work if I
- remove these bits. If I pass no wildcards, in fact, the thing works fine,
- although the output is rather dull.
-
- Quick background on program function;
-
- Takes in a statsfile generated by another program I'm writing, and
- generates "top ten" statistics, matched, preferably to a wildcard pattern.
- It's a web-based project, so you can see sample input files at;
-
- http://arh0268.urh.uiuc.edu/stats/hosts.raw
- /requested.raw
- /referers.raw
-
- You can see a script meant to run the freak, among other things, in a
- script at;
-
- http://arh0268.urh.uiuc.edu/s/dostats (Program name here is t10 ...)
-
- As well, *all* critiques of this code and my approach to it's
- implementation, suggestions for better elegance/stability or whatever are
- welcome. :) I'm a newbie ...
-
- (Compiled under GCC ...)
-
- Code follows ...
-
- --
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- #include <proto/dos.h>
-
- #define BUFLEN 200
-
- main(int argc, char *argv[])
- {
- BPTR readin;
-
- char buf[BUFLEN];
- char data[BUFLEN-10];
- char chits[10];
- int ctr;
- unsigned long hits, tot;
-
- char match[514];
- char fallback[] = "#?";
-
- if(!argc) /* If no argc passed, program was started from Workbench ... */
- {
- printf("Sorry, this program must be executed at command-line!\n");
- exit(0);
- }
-
- if((readin = Open(argv[1], MODE_OLDFILE)) != 0)
- {
- if(ParsePatternNoCase(argv[2], match, 514) == -1)
- {
- printf("AAAGH!\n");
- Close(readin);
- exit(0);
- }
-
- FGets(readin, buf, BUFLEN);
-
- strcpy(chits, strtok(buf, " "));
- tot = atoi(chits);
-
- printf("%6d Total\n\n", tot);
-
- for(ctr = 0; (ctr < 10 && (FGets(readin, buf, BUFLEN) != NULL)); )
- {
- strcpy(chits, strtok(buf, " "));
- hits = atoi(chits);
- strcpy(data, strtok(NULL, "\n"));
- if (MatchPatternNoCase(match, data))
- {
- printf("%6d %s (%.5g%%)\n", hits, data, (float)hits/tot*100);
- ctr++;
- }
- }
- Close(readin);
- }
- else
- printf("Could not open %s !\nUsage: %s <input-file> [include-pattern]\n", argv[1], argv[0]);
- }
-