17 #define HANDLE intptr_t
18 #define INVALID_HANDLE_VALUE -1
47 #define NEW_PAGE "\f\n"
55 #if defined(_WIN32) && defined(__GNUG__)
117 friend int main(
int argc,
char** argv);
131 bool accepting_options=
true;
133 for(
int i=1; i<argc; i++)
135 string next_arg=argv[i];
137 (accepting_options==
false) ||
138 (next_arg.substr(0,2)!=
"--")
148 else if(next_arg==
"--")
153 accepting_options=
false;
155 else if(next_arg==
"--help")
164 unsigned int assignment_pos=next_arg.find(
"=");
165 if(assignment_pos==string::npos)
167 cerr <<
"Unexpected option " << next_arg << endl;
173 string next_opt=next_arg.substr(0,assignment_pos);
174 string next_val=next_arg.substr(assignment_pos+1);
176 if(next_opt==
"--outdir")
180 else if(next_opt==
"--db_infile")
184 else if(next_opt==
"--db_outfile")
188 else if(next_opt==
"--opt_infile")
192 else if(next_opt==
"--opt_outfile")
196 else if(next_opt==
"--html_outfile")
200 else if(next_opt==
"--xml_outfile")
205 else if(next_opt==
"--lang")
209 else if(next_opt==
"--report_mask")
216 else if(next_opt==
"--debug_mask")
225 cerr <<
"Unexpected option " << next_opt << endl;
279 while(!std::cin.eof())
282 std::cin >> filename;
298 HANDLE sh = _findfirst(file_arg.c_str(), &fd);
306 string directoryPrefix;
307 size_t directoryPrefixLength = file_arg.find_last_of(
"/\\");
308 if(directoryPrefixLength!=string::npos)
310 directoryPrefix = string(file_arg,0,directoryPrefixLength+1);
314 int findnextReturnValue = 0;
315 while (findnextReturnValue==0)
317 string sFileName=directoryPrefix;
318 sFileName.append(fd.name);
321 findnextReturnValue = _findnext(sh, &fd);
327 cout << file_arg << endl;
340 std::list<file_entry>::iterator file_iterator=
file_list.begin();
345 string filename=entry.first;
352 if(file_language.size()==0)
361 unsigned int period_pos=file_language.find(
".");
362 string base_language=file_language.substr(0,period_pos);
364 f=fopen(filename.c_str(),
"r");
367 cerr <<
"Couldn't open " << filename << endl;
372 cerr <<
"Processing " << filename;
381 (base_language==
"c++") ||
385 cerr <<
" as C/C++ (" << file_language <<
")"
388 CLexer theLexer(&in);
389 ANTLRTokenBuffer thePipe(&theLexer);
391 CParser theParser(&thePipe);
394 theParser.init(filename,file_language);
407 theParser.traceGuessOption(-1);
412 #endif // CC_INCLUDED
414 else if(base_language==
"java")
416 cerr <<
" as Java" << endl;
418 JLexer theLexer(&in);
419 ANTLRTokenBuffer thePipe(&theLexer);
421 JParser theParser(&thePipe);
422 theParser.init(filename,file_language);
423 theParser.traceGuessOption(-1);
424 theParser.compilationUnit();
427 #endif // JAVA_INCLUDED
429 else if(base_language==
"ada")
431 cerr <<
" as Ada" << endl;
433 ALexer theLexer(&in);
434 ANTLRTokenBuffer thePipe(&theLexer);
436 AdaPrser theParser(&thePipe);
437 theParser.init(filename,file_language);
438 theParser.traceGuessOption(-1);
439 theParser.goal_symbol();
442 #endif // ADA_INCLUDED
443 else if(base_language==
"")
445 cerr <<
" - no parseable language identified";
449 cerr <<
"Unexpected language " << base_language.c_str()
450 <<
" (" << file_language.c_str()
451 <<
") for file " << filename.c_str() << endl;
467 return prj->
ToFile(outfile);
483 cerr << endl <<
"Generating HTML reports" << endl;
491 cerr << endl <<
"Generating XML reports" << endl;
507 for (
int i=0; arg[i]!=
'\0'; i++)
540 for (
int i=0; arg[i]!=
'\0'; i++) {
592 cerr <<
"Unexpected report requested:" << arg[i] << endl;
606 string version_string=
"Version ";
609 const char *credit_strings[] =
611 "CCCC - a code counter for C and C++",
612 "===================================",
614 "A program to analyse C and C++ source code and report on",
615 "some simple software metrics",
616 version_string.c_str(),
617 "Copyright Tim Littlefair, 1995, 1996, 1997, 1998, 1999, 2000",
618 "with contributions from Bill McLean, Herman Hueni, Lynn Wilson ",
619 "Peter Bell, Thomas Hieber and Kenneth H. Cox.",
621 "The development of this program was heavily dependent on",
622 "the Purdue Compiler Construction Tool Set (PCCTS) ",
623 "by Terence Parr, Will Cohen, Hank Dietz, Russel Quoung,",
624 "Tom Moog and others.",
626 "CCCC comes with ABSOLUTELY NO WARRANTY.",
627 "This is free software, and you are welcome to redistribute it",
628 "under certain conditions. See the file COPYING in the source",
629 "code distribution for details.",
632 const char **string_ptr=credit_strings;
633 while(*string_ptr!=NULL)
635 os << *string_ptr << endl;
649 <<
"Primary HTML output is in " <<
html_outfile << endl;
652 cerr <<
"Detailed HTML reports on modules and source are in " <<
outdir << endl;
654 cerr <<
"Primary XML output is in " <<
xml_outfile << endl ;
657 cerr <<
"Detailed XML reports on modules are in " <<
outdir << endl;
659 cerr <<
"Database dump is in " <<
db_outfile << endl << endl;
663 cerr << endl <<
"No files parsed on this run" << endl << endl;
673 const char *usage_strings[] =
676 "cccc [options] file1.c ... ",
677 "Process files listed on command line.",
678 "If the filenames include '-', read a list of files from standard input.",
679 "Command Line Options: (default arguments/behaviour specified in braces)",
680 "--help * generate this help message",
681 "--outdir=<dname> * directory for generated files {.cccc}",
682 "--html_outfile=<fname> * name of main HTML report {<outdir>/cccc.html}",
683 "--xml_outfile=<fname> * name of main XML report {<outdir>/cccc.xml}",
684 "--db_infile=<fname> * preload internal database from named file",
686 "--db_outfile=<fname> * save internal database to file {<outdir>/cccc.db}",
687 "--opt_infile=<fname> * load options from named file {hard coded, see below}",
688 "--opt_outfile=<fname> * save options to named file {<outdir>/cccc.opt}",
689 "--lang=<string> * use language specified for files specified ",
690 " after this option (c,c++,ada,java, no default)",
691 "--report_mask=<hex> * control report content ",
692 "--debug_mask=<hex> * control debug output content ",
693 " (refer to ccccmain.cc for mask values)",
694 "Refer to ccccmain.cc for usage of --report_mask and --debug_mask.",
695 "Refer to cccc_opt.cc for hard coded default option values, including default ",
696 "extension/language mapping and metric treatment thresholds.",
699 const char **string_ptr=usage_strings;
700 while(*string_ptr!=NULL)
702 os << *string_ptr << endl;
712 int main(
int argc,
char **argv)
723 cerr <<
"Parsing" << endl;
732 _mkdir(app->
outdir.c_str());
734 mkdir(app->
outdir.c_str(),0777);
static void Save_Options(const string &filename)
void PrintUsage(ostream &os)
#define SKIP_IDENTIFIERS_ARRAY_SIZE
char * skip_identifiers[SKIP_IDENTIFIERS_ARRAY_SIZE]
static void GenerateReports(CCCC_Project *project, int report_mask, const string &outfile, const string &outdir)
static void Load_Options()
int FromFile(ifstream &infile)
void HandleReportOption(const string &)
#define CCCC_VERSION_STRING
ANTLRToken currentLexerToken
static string getFileLanguage(const string &filename)
friend int main(int argc, char **argv)
static void set_active_project(CCCC_Project *prj)
static void GenerateReports(CCCC_Project *project, int report_mask, const string &outfile, const string &outdir)
int ToFile(ofstream &outfile)
std::pair< string, string > file_entry
int main(int argc, char **argv)
std::list< file_entry > file_list
void HandleDebugOption(const string &)
void PrintCredits(ostream &os)
void HandleArgs(int argc, char **argv)
void AddFileArgument(const string &)