void CMod::Add( CMod *other ) { total.Add( &other->total ); for ( int i = 0 ; i < MOD_STATCOUNT; i++ ) { stats[ i ].Add( &other->stats[ i ] ); } ComputeTotals(); }
bool CMod::ReadFromFile( char **data ) { int i; int count = 0; char *p = *data; bool bret = false; p = COM_Parse( p ); if ( stricmp( com_token, "{" ) ) { goto finish_read; } p = COM_Parse( p ); if ( !stricmp( com_token, "}" ) ) { goto finish_read; } if ( stricmp( com_token, "gamedir" ) ) { goto finish_read; } p = COM_Parse( p ); SetGameDir( com_token ); p = COM_Parse( p ); count = atoi( com_token ); assert( count <= MOD_STATCOUNT ); for ( i = 0; i < count; i++ ) { p = COM_Parse( p ); stats[ i ].servers = atoi( com_token ); p = COM_Parse( p ); stats[ i ].players = atoi( com_token ); if ( *p == '\r' ) // old file format { stats[ i ].bots = stats[ i ].bots_servers = 0; } else { p = COM_Parse( p ); stats[ i ].bots = atoi( com_token ); p = COM_Parse( p ); stats[ i ].bots_servers = atoi( com_token ); } } p = COM_Parse( p ); if ( stricmp( com_token, "}" ) ) { goto finish_read; } ComputeTotals(); bret = true; finish_read: *data = p; return bret; }
/*************************************************************************** ** ReadSites -- ** This function asks the user for the name of the data ** file to be used, opens it, reads the website Addresses and ** sorts them. The totals are then computed and the tables printed using ** other functions within this one. ** Inputs: None ** Outputs: 4 arrays fll of websites and printed results. ***************************************************************************/ void ReadSites() { FILE *ifp; char filename[SIZE] = "cat"; char temp[SIZE] = "dog"; int j = 0; /*The four arrays are declared*/ WEBSITE t, comSites[SIZE], govSites[SIZE], eduSites[SIZE], netSites[SIZE]; int TotalNonUniqueSites = 0, TotalUniqueSites = 0, TotalTimeLogged = 0; int TotalFunSites = 0, TotalSearchSites = 0, TotalEducationSites = 0; int TotalNewsSites = 0, *pTotalNewsSites, *pTotalNonUniqueSites; int *pTotalUniqueSites, *pTotalTimeLogged, *pTotalFunSites; int *pTotalSearchSites, *pTotalEducationSites; /*The pointers are set to point to the their corresponding values*/ pTotalNonUniqueSites = &TotalNonUniqueSites; pTotalUniqueSites = &TotalUniqueSites; pTotalTimeLogged = &TotalTimeLogged; pTotalFunSites = &TotalFunSites; pTotalSearchSites = &TotalSearchSites; pTotalEducationSites = &TotalEducationSites; pTotalNewsSites = &TotalNewsSites; /*The are filled with dummy values*/ FillArray(comSites); FillArray(netSites); FillArray(eduSites); FillArray(govSites); /*Asks the user for the file name*/ fprintf(stdout, "\nPlease enter the file name: "); fscanf(stdin, "%s", filename); ifp = fopen(filename, "r"); /*If the file cannot exit and give error message*/ if(ifp == NULL) { fprintf(stderr, "The file could not be opened."); exit(-1); } /*Scans every thing in the file until it reaches the end*/ while(fscanf(ifp, "%s %s %d", temp, t.siteType, &t.seconds) != EOF) { /*Breaks the string temp into access code, domain name*/ /* and domain ending and stores the in the temporary structure*/ t.webAddress = CreateAddress(temp); /*Depending on the first letter of the domain ending, stores*/ /*them into the appropriate array*/ if(t.webAddress.domainEnding[0] == 'c') { /*Finds the index of wherever the website is supposed to go*/ j = IsPresent(comSites, t); /*Stores the website in the proper location*/ comSites[j].webAddress = t.webAddress; /*Stores the siteType in the corresponding location*/ strcpy(comSites[j].siteType, t.siteType); /*Adds the number of hits and the seconds*/ comSites[j].hits += 1; comSites[j].seconds += t.seconds; } else if(t.webAddress.domainEnding[0] == 'g') { j = IsPresent(govSites, t); govSites[j].webAddress = t.webAddress; strcpy(govSites[j].siteType, t.siteType); govSites[j].hits += 1; govSites[j].seconds += t.seconds; } else if(t.webAddress.domainEnding[0] == 'n') { j = IsPresent(netSites, t); netSites[j].webAddress = t.webAddress; strcpy(netSites[j].siteType, t.siteType); netSites[j].hits += 1; netSites[j].seconds += t.seconds; } else { j = IsPresent(eduSites, t); eduSites[j].webAddress = t.webAddress; strcpy(eduSites[j].siteType, t.siteType); eduSites[j].hits += 1; eduSites[j].seconds += t.seconds; } } /*Sorts the arrays*/ SortArray(eduSites, ArrayLength(eduSites)); SortArray(govSites, ArrayLength(govSites)); SortArray(comSites, ArrayLength(comSites)); SortArray(netSites, ArrayLength(netSites)); /*Computes the totals using data from all the arrays*/ ComputeTotals(comSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); ComputeTotals(eduSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); ComputeTotals(netSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); ComputeTotals(govSites, pTotalUniqueSites, pTotalNonUniqueSites, pTotalTimeLogged, pTotalFunSites, pTotalSearchSites, pTotalEducationSites, pTotalNewsSites); /*Prints the results of the read*/ PrintTable(comSites, netSites, eduSites, govSites); /*Caclulates the percentages and prints them*/ CalcStats(TotalUniqueSites, TotalFunSites, TotalSearchSites, TotalNewsSites, TotalEducationSites, TotalTimeLogged, TotalNonUniqueSites); return; }