Example #1
0
/*!
* Prints the standardized file header for all output files.
*
* \param pout output file stream
* \param title custom title
* \param cmd current command line string
*
* \return file status
*/
int CUtil::PrintFileHeader(ofstream &pout, const string &title, const string &cmd)
{
    string myOutput;
    time_t myTime;
    struct tm *myLocalTime;
    time(&myTime);
#if defined UNIX || defined MINGW
    myLocalTime = localtime(&myTime);
#else
    struct tm myLT;
    errno_t eno = localtime_s(&myLT, &myTime);
    myLocalTime = &myLT;
#endif

    myOutput = "USC Unified CodeCount (UCC)";
    PrintFileHeaderLine(pout, myOutput);

    myOutput = "(c) Copyright 1998 - 2012 University of Southern California";
    PrintFileHeaderLine(pout, myOutput);
    pout << endl;

    myOutput = title;
    PrintFileHeaderLine(pout, myOutput);

    ostringstream s0;
    s0 << "Generated by UCC v." << PRODUCT_REVISION << " on " << myLocalTime->tm_mon + 1
       << " " << myLocalTime->tm_mday << " " << myLocalTime->tm_year + 1900;
    myOutput = s0.str();
    PrintFileHeaderLine(pout, myOutput);

    // print command line if given
    if (cmd.length() > 0)
    {
        myOutput = cmd;
        PrintFileHeaderLine(pout, myOutput);
    }
    pout << endl;

    return 1;
}
/*!
* Retrieves the web language output file stream.
* Opens a new stream if it has not been opened already.
*
* \param webType file language type
* \param outputFileNamePrePend name to prepend to the output file
* \param cmd current command line string
* \param csvOutput CSV file stream? (otherwise ASCII text file)
* \param legacyOutput legacy format file stream? (otherwise standard text file)
*
* \return output file stream
*/
ofstream* CWebCounter::GetOutputStream(WebType webType, const string &outputFileNamePrePend, const string &cmd, bool csvOutput, bool legacyOutput)
{
	if (webType == WEB_PHP)
	{
		if (csvOutput)
		{
			if (!php_output_file_csv.is_open())
			{
				string ofname = outputFileNamePrePend + "PHP";
				ofname += OUTPUT_FILE_NAME_CSV;
				php_output_file_csv.open(ofname.c_str(), ofstream::out);

				if (!php_output_file_csv.is_open()) return NULL;
				PrintFileHeader(php_output_file_csv, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(php_output_file_csv, "RESULTS FOR PHP FILES");
				php_output_file_csv << endl << ",,,,HTML,,JS-Clnt,,VBS-Clnt,,PHP,,," << endl;
				php_output_file_csv << "Total,Blank,Comments,,Word,Exec.,Data,Exec.,Data,Exec.,Comp.,Data,Exec.,Logical SLOC,,,,,Physical,File,Module" << endl;
				php_output_file_csv << "Lines,Lines,Whole,Embed,LOC,Instr,Decl,Instr,Decl,Instr,Direct.,Decl,Instr,HTML,JS-Clnt,VBS-Clnt,PHP,Total,SLOC,Type,Name" << endl;
			}
			return &php_output_file_csv;
		}
		else
		{
			if (!php_output_file.is_open())
			{
				string ofname = outputFileNamePrePend + "PHP";
				ofname += OUTPUT_FILE_NAME;
				php_output_file.open(ofname.c_str(), ofstream::out);

				if (!php_output_file.is_open()) return NULL;
				PrintFileHeader(php_output_file, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(php_output_file, "RESULTS FOR PHP FILES");
				php_output_file << endl << "                                    |       HTML      |     JS-Clnt     |    VBS-Clnt     |           PHP           |" << endl;
				if (legacyOutput)
				{
					php_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  | Compiler  Data   Exec.  |                Logical SLOC                | File  Module" << endl;
					php_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. | Direct.   Decl.  Instr. |   Total      HTML JS-Clnt VBS-Clnt     PHP | Type  Name" << endl;
					php_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-------------------------+---------+----------------------------------+---------------------------" << endl;
				}
				else
				{
					php_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  | Compiler  Data   Exec.  |                Logical SLOC                | Physical | File  Module" << endl;
					php_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. | Direct.   Decl.  Instr. |    HTML JS-Clnt VBS-Clnt     PHP     Total |   SLOC   | Type  Name" << endl;
					php_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-------------------------+----------------------------------+---------+----------+---------------------------" << endl;
				}
			}
			return &php_output_file;
		}
	}
	else if (webType == WEB_JSP)
	{
		if (csvOutput)
		{
			if (!jsp_output_file_csv.is_open())
			{
				string ofname = outputFileNamePrePend + "JSP";
				ofname += OUTPUT_FILE_NAME_CSV;
				jsp_output_file_csv.open(ofname.c_str(), ofstream::out);

				if (!jsp_output_file_csv.is_open()) return NULL;

				PrintFileHeader(jsp_output_file_csv, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(jsp_output_file_csv, "RESULTS FOR JSP FILES");
				jsp_output_file_csv << endl << ",,,,HTML,,JS-Clnt,,VBS-Clnt,,Java" << endl;
				jsp_output_file_csv << "Total,Blank,Comments,,Word,Exec.,Data,Exec.,Data,Exec.,Comp.,Data,Exec.,Logical SLOC,,,,,Physical,File,Module" << endl;
				jsp_output_file_csv << "Lines,Lines,Whole,Embed,LOC,Instr,Decl,Instr,Decl,Instr,Direct.,Decl,Instr,HTML,JS-Clnt,VBS-Clnt,Java,Total,SLOC,Type,Name" << endl;
			}
			return &jsp_output_file_csv;
		}
		else
		{
			if (!jsp_output_file.is_open())
			{
				string ofname = outputFileNamePrePend + "JSP";
				ofname += OUTPUT_FILE_NAME;
				jsp_output_file.open(ofname.c_str(), ofstream::out);

				if (!jsp_output_file.is_open()) return NULL;

				PrintFileHeader(jsp_output_file, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(jsp_output_file, "RESULTS FOR JSP FILES");
				jsp_output_file << endl << "                                    |       HTML      |     JS-Clnt     |    VBS-Clnt     |          Java           |" << endl;
				if (legacyOutput)
				{
					jsp_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  | Compiler  Data   Exec.  |                Logical SLOC                | File  Module" << endl;
					jsp_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. | Direct.   Decl.  Instr. |   Total      HTML JS-Clnt VBS-Clnt    Java | Type  Name" << endl;
					jsp_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-------------------------+---------+----------------------------------+---------------------------" << endl;
				}
				else
				{
					jsp_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  | Compiler  Data   Exec.  |                Logical SLOC                | Physical | File  Module" << endl;
					jsp_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. | Direct.   Decl.  Instr. |    HTML JS-Clnt VBS-Clnt    Java     Total |   SLOC   | Type  Name" << endl;
					jsp_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-------------------------+----------------------------------+---------+----------+---------------------------" << endl;
				}
			}
			return &jsp_output_file;
		}
	}
	else if (webType == WEB_ASP)
	{
		if (csvOutput)
		{
			if (!asp_output_file_csv.is_open())
			{
				string ofname = outputFileNamePrePend + "ASP";
				ofname += OUTPUT_FILE_NAME_CSV;
				asp_output_file_csv.open(ofname.c_str(), ofstream::out);

				if (!asp_output_file_csv.is_open()) return NULL;

				PrintFileHeader(asp_output_file_csv, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(asp_output_file_csv, "RESULTS FOR ASP FILES");
				asp_output_file_csv << endl << ",,,,HTML,,JS-Clnt,,VBS-Clnt,,JS-Svr,,VBS-Svr,,C#-Svr" << endl;
				asp_output_file_csv << "Total,Blank,Comments,,Word,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Logical SLOC,,,,,,,Physical,File,Module" << endl;
				asp_output_file_csv << "Lines,Lines,Whole,Embed,LOC,Instr,Decl,Instr,Decl,Instr,Decl,Instr,Decl,Instr,Decl,Instr,HTML,JS-Clnt,VBS-Clnt,JS-Svr,VBS-Svr,C#-Svr,Total,SLOC,Type,Name" << endl;
			}
			return &asp_output_file_csv;
		}
		else
		{
			if (!asp_output_file.is_open())
			{
				string ofname = outputFileNamePrePend + "ASP";
				ofname += OUTPUT_FILE_NAME;
				asp_output_file.open(ofname.c_str(), ofstream::out);

				if (!asp_output_file.is_open()) return NULL;

				PrintFileHeader(asp_output_file, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(asp_output_file, "RESULTS FOR ASP FILES");
				asp_output_file << endl << "                                    |       HTML      |     JS-Clnt     |    VBS-Clnt     |      JS-Svr     |     VBS-Svr     |      C#-Svr     |" << endl;
				if (legacyOutput)
				{
					asp_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                        Logical SLOC                        | File  Module" << endl;
					asp_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Total      HTML JS-Clnt VBS-Clnt  JS-Svr VBS-Svr  C#-Svr | Type  Name" << endl;
					asp_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+-----------------+-----------------+---------+--------------------------------------------------+---------------------------" << endl;
				}
				else
				{
					asp_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                        Logical SLOC                        | Physical | File  Module" << endl;
					asp_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |    HTML JS-Clnt VBS-Clnt  JS-Svr VBS-Svr  C#-Svr     Total |   SLOC   | Type  Name" << endl;
					asp_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+-----------------+-----------------+--------------------------------------------------+---------+----------+---------------------------" << endl;
				}
			}
			return &asp_output_file;
		}
	}
	else if (webType == WEB_CFM)
	{
		if (csvOutput)
		{
			if (!cfm_output_file_csv.is_open())
			{
				string ofname = outputFileNamePrePend + "ColdFusion";
				ofname += OUTPUT_FILE_NAME_CSV;
				cfm_output_file_csv.open(ofname.c_str(), ofstream::out);

				if (!cfm_output_file_csv.is_open()) return NULL;

				PrintFileHeader(cfm_output_file_csv, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(cfm_output_file_csv, "RESULTS FOR ColdFusion FILES");
				cfm_output_file_csv << endl << ",,,,HTML,,JS-Clnt,,VBS-Clnt,,SQL,,ColdFusion,,CFScript" << endl;
				cfm_output_file_csv << "Total,Blank,Comments,,Word,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Logical SLOC,,,,,,,Physical,File,Module" << endl;
				cfm_output_file_csv << "Lines,Lines,Whole,Embed,LOC,Instr,Decl,Instr,Decl,Instr,Decl,Instr,Decl,Instr,Decl,Instr,HTML,JS-Clnt,VBS-Clnt,SQL,ColdFusion,CFScript,Total,SLOC,Type,Name" << endl;
			}
			return &cfm_output_file_csv;
		}
		else
		{
			if (!cfm_output_file.is_open())
			{
				string ofname = outputFileNamePrePend + "ColdFusion";
				ofname += OUTPUT_FILE_NAME;
				cfm_output_file.open(ofname.c_str(), ofstream::out);

				if (!cfm_output_file.is_open()) return NULL;

				PrintFileHeader(cfm_output_file, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(cfm_output_file, "RESULTS FOR ColdFusion FILES");
				cfm_output_file << endl << "                                    |       HTML      |     JS-Clnt     |    VBS-Clnt     |       SQL       |    ColdFusion   |     CFScript    |" << endl;
				if (legacyOutput)
				{
					cfm_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                          Logical SLOC                          | File  Module" << endl;
					cfm_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Total      HTML JS-Clnt VBS-Clnt     SQL ColdFusion CFScript | Type  Name" << endl;
					cfm_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+-----------------+-----------------+---------+------------------------------------------------------+---------------------------" << endl;
				}
				else
				{
					cfm_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                          Logical SLOC                          | Physical | File  Module" << endl;
					cfm_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |    HTML JS-Clnt VBS-Clnt     SQL ColdFusion CFScript     Total |   SLOC   | Type  Name" << endl;
					cfm_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+-----------------+-----------------+------------------------------------------------------+---------+----------+---------------------------" << endl;
				}
			}
			return &cfm_output_file;
		}
	}
	else if (webType == WEB_XML)
	{
		if (csvOutput)
		{
			if (!xml_output_file_csv.is_open())
			{
				string ofname = outputFileNamePrePend + "XML";
				ofname += OUTPUT_FILE_NAME_CSV;
				xml_output_file_csv.open(ofname.c_str(), ofstream::out);

				if (!xml_output_file_csv.is_open()) return NULL;

				PrintFileHeader(xml_output_file_csv, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(xml_output_file_csv, "RESULTS FOR XML FILES");
				xml_output_file_csv << endl << ",,,,XML,,JS-Clnt,,VBS-Clnt,,C#-Clnt" << endl;
				xml_output_file_csv << "Total,Blank,Comments,,Word,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Logical SLOC,,,,,Physical,File,Module" << endl;
				xml_output_file_csv << "Lines,Lines,Whole,Embed,LOC,Instr,Decl,Instr,Decl,Instr,Decl,Instr,XML,JS-Clnt,VBS-Clnt,C#-Clnt,Total,SLOC,Type,Name" << endl;
			}
			return &xml_output_file_csv;
		}
		else
		{
			if (!xml_output_file.is_open())
			{
				string ofname = outputFileNamePrePend + "XML";
				ofname += OUTPUT_FILE_NAME;
				xml_output_file.open(ofname.c_str(), ofstream::out);

				if (!xml_output_file.is_open()) return NULL;

				PrintFileHeader(xml_output_file, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(xml_output_file, "RESULTS FOR XML FILES");
				xml_output_file << endl << "                                    |       XML       |     JS-Clnt     |    VBS-Clnt     |     C#-Clnt     |" << endl;
				if (legacyOutput)
				{
					xml_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                Logical SLOC                | File  Module" << endl;
					xml_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Total       XML JS-Clnt VBS-Clnt C#-Clnt | Type  Name" << endl;
					xml_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+---------+----------------------------------+---------------------------" << endl;
				}
				else
				{
					xml_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                Logical SLOC                | Physical | File  Module" << endl;
					xml_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |     XML JS-Clnt VBS-Clnt C#-Clnt     Total |   SLOC   | Type  Name" << endl;
					xml_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+----------------------------------+---------+----------+---------------------------" << endl;
				}
			}
			return &xml_output_file;
		}
	}
	else // html
	{
		if (csvOutput)
		{
			if (!html_output_file_csv.is_open())
			{
				string ofname = outputFileNamePrePend + "HTML";
				ofname += OUTPUT_FILE_NAME_CSV;
				html_output_file_csv.open(ofname.c_str(), ofstream::out);

				if (!html_output_file_csv.is_open()) return NULL;

				PrintFileHeader(html_output_file_csv, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(html_output_file_csv, "RESULTS FOR HTML FILES");
				html_output_file_csv << endl << ",,,,HTML,,JS-Clnt,,VBS-Clnt,,C#-Clnt" << endl;
				html_output_file_csv << "Total,Blank,Comments,,Word,Exec.,Data,Exec.,Data,Exec.,Data,Exec.,Logical SLOC,,,,,Physical,File,Module" << endl;
				html_output_file_csv << "Lines,Lines,Whole,Embed,LOC,Instr,Decl,Instr,Decl,Instr,Decl,Instr,HTML,JS-Clnt,VBS-Clnt,C#-Clnt,Total,SLOC,Type,Name" << endl;
			}
			return &html_output_file_csv;
		}
		else
		{
			if (!html_output_file.is_open())
			{
				string ofname = outputFileNamePrePend + "HTML";
				ofname += OUTPUT_FILE_NAME;
				html_output_file.open(ofname.c_str(), ofstream::out);

				if (!html_output_file.is_open()) return NULL;

				PrintFileHeader(html_output_file, "SLOC COUNT RESULTS", cmd);

				PrintFileHeaderLine(html_output_file, "RESULTS FOR HTML FILES");
				html_output_file << endl << "                                    |       HTML      |     JS-Clnt     |    VBS-Clnt     |     C#-Clnt     |" << endl;
				if (legacyOutput)
				{
					html_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                Logical SLOC                | File  Module" << endl;
					html_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Total      HTML JS-Clnt VBS-Clnt C#-Clnt | Type  Name" << endl;
					html_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+---------+----------------------------------+---------------------------" << endl;
				}
				else
				{
					html_output_file << "   Total   Blank |      Comments    |    Word  Exec.  |   Data   Exec.  |   Data   Exec.  |   Data   Exec.  |                Logical SLOC                | Physical | File  Module" << endl;
					html_output_file << "   Lines   Lines |   Whole Embedded |     LOC  Instr. |   Decl.  Instr. |   Decl.  Instr. |   Decl.  Instr. |    HTML JS-Clnt VBS-Clnt C#-Clnt     Total |   SLOC   | Type  Name" << endl;
					html_output_file << "-----------------+------------------+-----------------+-----------------+-----------------+-----------------+----------------------------------+---------+----------+---------------------------" << endl;
				}
			}
			return &html_output_file;
		}
	}
}