//: C02:Cppcheck.cpp // From Thinking in C++, 2nd Edition // Available at http://www.BruceEckel.com // (c) Bruce Eckel 2000 // Copyright notice in Copyright.txt // Configures .h & .cpp files // To conform to style standard. // Tests existing files for conformance #include "../require.h" #include #include #include #include using namespace std; int main(int argc, char* argv[]) { const int sz = 40; // Buffer sizes const int bsz = 100; requireArgs(argc, 1); // File set name enum bufs { base, header, implement, Hline1, guard1, guard2, guard3, CPPline1, include, bufnum }; char b[bufnum][sz]; ostrstream osarray[] = { ostrstream(b[base], sz), ostrstream(b[header], sz), ostrstream(b[implement], sz), ostrstream(b[Hline1], sz), ostrstream(b[guard1], sz), ostrstream(b[guard2], sz), ostrstream(b[guard3], sz), ostrstream(b[CPPline1], sz), ostrstream(b[include], sz), }; osarray[base] << argv[1] << ends; // Find any '.' in the string using the // Standard C library function strchr(): char* period = strchr(b[base], '.'); if(period) *period = 0; // Strip extension // Force to upper case: for(int i = 0; b[base][i]; i++) b[base][i] = toupper(b[base][i]); // Create file names and internal lines: osarray[header] << b[base] << ".h" << ends; osarray[implement] << b[base] << ".cpp" << ends; osarray[Hline1] << "//" << ": " << b[header] << " -- " << ends; osarray[guard1] << "#ifndef " << b[base] << "_H" << ends; osarray[guard2] << "#define " << b[base] << "_H" << ends; osarray[guard3] << "#endif // " << b[base] << "_H" << ends; osarray[CPPline1] << "//" << ": " << b[implement] << " -- " << ends; osarray[include] << "#include \"" << b[header] << "\"" <