Pandemonium
Lijsterbeslaan 3
B-2940 Stabroek, Belgium
IBAN: BE78 9794 3692 5286
BIC: ARSPBE22XXX
KBO: 0314.595.348
VAT: BE 0 881.023.185
request blrootsales@pandemonium.be
ID:  Pass:    [ Not logged in. ]

 Cool build info gathering app 
 Dave Driesen
Joined 2007-05-18 20:59:14.
(3903 Days old)

Cool build info gathering app

Posted on: 2011-02-12 10:57:41 
IP: Logged 
One of the main things I missed while building for Win32 is the lack of flexibility that you get on Linux... Our Linux build scripts, for example, contain commands that gather source code information and statistics and embed that data into the binaries.

So instead of googling around for a few hours and installing some messy third party application and/or dishing out a few bucks, I decided to throw something together myself.

This application parses a Visual Studio project file and examines source files to collect data such as byte count, character count, line count and maximum line length. Running this application with your project file as parameter will give you a file named "version." which you can then include to define the statistical variables. It's a bit clunky here and there but does the trick and remember, it was thrown together quite lazily. I might polish it up if people want me to.

#include <windows.h>
#include <windowsx.h>
#include <shellapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/stat.h>
#include <iostream>
#include <fstream>
#include <tchar.h>

using namespace std;

int linecount=0;
int bytecount=0;
int charcount=0;
int wordcount=0;
int maxlinelen=0;

std::string ws2s(const wstring &src_string) {
size_t src_len = src_string.length();

if(src_len == 0) return "";

char *buf = new(std::nothrow) char[src_len + 1];

if(buf == 0) return "";

wcstombs(buf, src_string.c_str(), src_len);
buf[src_len] = '\0';

string final_string(buf);

if(buf != 0) delete [] buf;

return final_string;
}

int getfilesize(string s) {
FILE* file;
int result;

if ((file = fopen((char*) s.c_str(), "rb")) == NULL) return 0;
// obtain file size:
fseek (file , 0 , SEEK_END);
result = ftell (file);
fclose(file);
return result;
}

int countwords(string s) {

int result=0;
string::iterator I;
bool inWord=false;
for(I=s.begin(); I!=s.end(); I++) {
if ((((*I)>='A') && ((*I)<='Z')) || (((*I)>='a') && ((*I)<='z'))) {
if (!inWord) {
result++;
inWord=true;
}
} else inWord=false;
}
return result;
}

void parsefile(string s) {
int result=0;
ifstream ifs( s.c_str() );
string temp;

while( getline( ifs, temp ) ) {
linecount++;
charcount+=temp.length();
if (temp.length()>maxlinelen) maxlinelen=temp.length();
wordcount+=countwords(temp);
}

ifs.close();
}

int _tmain(int argc, _TCHAR* argv[]) {

LPWSTR *szArglist;
int nArgs;

szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
if (nArgs>1) {
string executable_location=ws2s(szArglist[0]);
string param_1=ws2s(szArglist[1]);

ifstream ifs( param_1 );
string temp;

while( getline( ifs, temp ) ) {
if (temp.find("RelativePath")!=string::npos) {
int Q1=temp.find_first_of(""")+1;
int Q2=temp.find_last_of(""");
string efFile=temp.substr(Q1,Q2-Q1);
bytecount+=getfilesize(efFile);
parsefile (efFile);
cout << "Gathering stats for " << efFile << "n";
}

}
ifs.close();

fstream outfile("version.h", ios_base::out );
outfile << "#define __LINECOUNT__ " << linecount << "n";
outfile << "#define __CHARCOUNT__ " << charcount << "n";
outfile << "#define __WORDCOUNT__ " << wordcount << "n";
outfile << "#define __BYTECOUNT__ " << bytecount << "n";
outfile << "#define __MAXLINELEN__ " << maxlinelen << "n";
outfile.close();
cout << "Byte count: " << bytecount << "n";
cout << "Word count: " << wordcount << "n";
cout << "Line count: " << linecount << "n";
cout << "Character count: " << charcount << "n";
cout << "Max line length: " << maxlinelen << "n";
} else {
cout << "Expected path to Visual Studio project file. Aborting.n";
cout << "Please call Stats with path to .vcproj file.";
}

return (int) 0;
}

  Showing entry "Cool build info gathering app".
Pandemonium 2009


These pages are the intellectual property of the Pandemonium crew.
Welcome to Pandemonium.be - Antwerp based development studio providing development and administration services. Developers and maintainers of the Pyromasaur 3D framework.
Secure
"