We start by writing a rough outline of the main loop.
But even before that, we set up the Makefile in such a way that it will be easy to add new source files etc. All we ever want to type is ``make
'' or, perhaps, ``make
check
''.
For the ``check
'' target we execute the command
httpstats httpstats.config access_log
head -10000 access_log >my_access_log
scp
to copy it to our development directory.
The main program should do the following.
All this results in the following draft file httpstats.C. Unfortunately, this file cannot be compiled ``as is'' since the following types are unknown to the compiler: Configuration, LogRecord, and Stats. So we quickly create the following files that define ``stub'' implementations of these classes:
#ifndef CONFIGURATION_H #define CONFIGURATION_H #include <iostream> class Configuration { public: Configuration() {} ~Configuration() {} bool parse(istream&); }; #endif
#include "configuration.h" bool Configuration::Configuration(istream& is) { return true; }
#ifndef LOGRECORD_H #define LOGRECORD_H #include <string> class LogRecord { public: LogRecord() {} }; bool parse_line(const string& line,LogRecord&); #endif
#include "logrecord.h" bool parse_line(const string& line,LogRecord&) { return true; }
#ifndef STATS_H #define STATS_H #include "configuration.h" #include "logrecord.h" class Stats { public: Stats(const Configuration&); void add(const LogRecord&); }; #endif
#include "stats.h" Stats::Stats(const Configuration&) { } void Stats::add(const LogRecord&) { }
After removing syntax errors, the compiled sources can be found in the stage00 directory. We added sensible CXXFLAGS to the Makefile and made the ``make
check
'' target output the time it takes to execute the command.
# Makefile for project2000 # CXXFLAGS = -g -Wall # # CCFILES will contain all C++ source files # HFILES will contain all header files # OBJECTS will contain all compiled C++ source files CCFILES= httpstats.C configuration.C logrecord.C stats.C HFILES= configuration.h logrecord.h stats.h OBJECTS=$(CCFILES:%.C=%.o) httpstats: $(OBJECTS) g++ -o $@ $^ clean: rm $(OBJECTS) httpstats check: httpstats time httpstats access_log httpstats.config include make.depend make.depend: $(CCFILES) g++ -M $^ >$@
make
check
'' at this stage: 10000 lines processed, 0 lines had errors 0.84user 0.00system 0:00.90elapsed 93%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+0outputs (164major+12minor)pagefaults 0swaps