Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

read1.c

00001 #include <time.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include "queue.h"
00006 
00007 void main(void);
00008 char *sfgets(char *, int, FILE *);
00009 
00010 int email=0;
00011 int nicks=0;
00012 int urls=0;
00013 int access=0;
00014 
00015 typedef struct urllist_struct UrlList;
00016 
00017 struct urllist_struct {
00018     char url[128];
00019     LIST_ENTRY(urllist_struct) urls;
00020 };
00021 
00022 typedef struct regnicklist RegNickList;
00023 
00024 struct regnicklist {
00025     char nick[33];
00026     time_t reged;
00027     LIST_ENTRY(regnicklist) users;
00028 };
00029 
00030 LIST_HEAD(,regnicklist)       firstUser;
00031 LIST_HEAD(,regnicklist)       lastUser;
00032 LIST_HEAD(,urllist_struct)    firstUrl;
00033 LIST_HEAD(,urllist_struct)    lastUrl;
00034 
00035 void main(void)
00036 {
00037     unsigned long totalnicklen=0;
00038     unsigned long totalurllen=0;
00039     int longestnick=0;
00040     int longesturl=0;
00041     int averagenick=0;
00042     int averageurl=0;
00043     unsigned int thenicks[33];
00044     RegNickList *read;
00045     UrlList *url;
00046     char line[1024];
00047     char *tmp = line;
00048     char args[13][129];
00049     FILE *ns;
00050     int done = 0;
00051     int a, x;
00052     time_t CTime;
00053 
00054     for (a = 0; a < 33; a++)
00055       thenicks[a] = 0;
00056       
00057     ns = fopen("nickserv/nickserv.db", "r");
00058     if(!ns)
00059       return;
00060     while(!done) {
00061         if (!(sfgets(line, 1024, ns))) {
00062             done = 1;
00063             break;
00064         }
00065         tmp = line;
00066         x = a = 0;
00067         while(*tmp && x < 10) {
00068             if(x == 9) {
00069                 tmp++;
00070                 while(*tmp) {
00071                     args[x][a] = *tmp;
00072                     a++;
00073                     tmp++;
00074                 }
00075             }
00076             else {
00077                 while(*tmp != ' ' && *tmp) {
00078                     args[x][a] = *tmp;
00079                     a++;
00080                     tmp++;
00081                 }
00082             }
00083             
00084             args[x][a] = 0;
00085             x++;
00086             while(*tmp == ' ')
00087               tmp++;
00088             a = 0;
00089         }
00090         
00091         if(!strcmp(args[0], "nick")) {
00092             read = calloc(1, sizeof(RegNickList));
00093             LIST_INSERT_HEAD(&firstUser, read, users);
00094             strcpy(read->nick, args[1]);
00095             read->reged = (time_t)atol(args[6]);
00096             nicks++;
00097         }
00098         else if(!strcmp(args[0], "url")) {
00099             url = calloc(1, sizeof(UrlList));
00100             LIST_INSERT_HEAD(&firstUrl, url, urls);
00101             strncpy(url->url, args[2], 128);
00102             urls++;
00103         }
00104         else if(!strcmp(args[0], "access")) {
00105             access++;
00106         }
00107         else if(!strcmp(args[0], "email")) {
00108             email++;
00109         }
00110         else if(!strcmp(args[0], "done"))
00111           done = 1;
00112     }
00113     fclose(ns);
00114     CTime = time(NULL);
00115     printf("Nicks: %i\nUrls: %i\nAccess List Entries: %i\nEmails: %i\n", nicks, urls, access, email);
00116     for(read = firstUser.lh_first;read;read = read->users.le_next) {
00117         thenicks[strlen(read->nick) - 1]++;
00118         totalnicklen = totalnicklen + strlen(read->nick);
00119         if (strlen(read->nick) > longestnick)
00120           longestnick = strlen(read->nick);
00121     }
00122 
00123     for(url = firstUrl.lh_first;url;url = url->urls.le_next) {
00124         totalurllen = totalurllen + strlen(url->url);
00125         if (strlen(url->url) > longesturl)
00126           longesturl = strlen(url->url);
00127     }
00128     
00129     averagenick = totalnicklen / nicks;
00130     averageurl = totalurllen / urls;
00131     printf("Largest Nick Length: %5i * Largest URL Length: %5i\n", longestnick, longesturl);
00132     printf("Average Nick Length: %5i * Average URL Length: %5i\n", averagenick, averageurl);
00133     printf("Nick Lengths (chars):\n");
00134     printf("  1 = %3i *  2 = %3i *  3 = %3i *  4 = %3i *  5 = %3i\n", thenicks[0], thenicks[1], thenicks[2], thenicks[3], thenicks[4]);
00135     printf("  6 = %3i *  7 = %3i *  8 = %3i *  9 = %3i * 10 = %3i\n", thenicks[5], thenicks[6], thenicks[17], thenicks[8], thenicks[9]);
00136     printf(" 11 = %3i * 12 = %3i * 13 = %3i * 14 = %3i * 15 = %3i\n", thenicks[10], thenicks[11], thenicks[12], thenicks[13], thenicks[14]);
00137     printf(" 16 = %3i * 17 = %3i * 18 = %3i * 19 = %3i * 20 = %3i\n", thenicks[15], thenicks[16], thenicks[27], thenicks[18], thenicks[19]);
00138     printf(" 21 = %3i * 22 = %3i * 23 = %3i * 24 = %3i * 25 = %3i\n", thenicks[20], thenicks[21], thenicks[26], thenicks[23], thenicks[24]);
00139     printf(" 26 = %3i * 27 = %3i * 28 = %3i * 29 = %3i * 30 = %3i\n", thenicks[25], thenicks[26], thenicks[27], thenicks[28], thenicks[29]);
00140     printf(" 31 = %3i * 32 = %3i\n", thenicks[30], thenicks[31]);
00141 }    
00142 
00143 char *
00144 sfgets(char *str, int len, FILE *fp)
00145 {
00146         if(!fgets(str, len, fp))
00147                   return NULL;
00148         else {
00149           if(str[0])
00150             str[strlen(str) - 1] = 0;
00151           return str;
00152         }
00153 }
00154                                                                                     

Generated at Sat Oct 25 20:56:09 2003 for Services using Doxygen.
Services Copyr. 1996-2001 Chip Norkus, Max Byrd, Greg Poma, Michael Graff, James Hess, Dafydd James. All rights reserved See LICENSE for licensing information.