|
// THIS FILE IS PROVIDED FOR INFORMATIONAL PURPOSE ONLY.
// NO COMERCIAL USE!!!
// Information: decl_spec@yahoo.com
#include "stdafx.h"
#include "lcProjectParser.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int getfext(const char* filename)
{
int count, sz;
sz=count = strlen(filename);
while (count-- && filename[count]!='.');
if (count<=0) return FEXT_NO_EXT;
char *ext = new char[sz-count+1];
memcpy(ext, filename+count, sz-count);
ext[sz-count]=0;
ext=strlwr(ext);
int result = FEXT_OTHER;
if (0==strcmp(ext, ".h"))
result = FEXT_CPP_HEADER;
else
{
if (0==strcmp(ext, ".cpp"))
result = FEXT_CPP_FILE;
else
{
if (0==strcmp(ext, ".c"))
result = FEXT_C_FILE;
}
}
delete [] ext;
return result;
}
int ProcessDSP(const char* filename, srcmng& sources)
{
if (!filename) return 0;
int nf = 0 ;
FILE* f=fopen(filename, "rt");
char *line = NULL;
while (!feof(f))
{
delete [] line;
line = new char[MAX_CHARS];
fgets(line, MAX_CHARS, f);
char* pos=strstr(line, SRC_IDEN);
if (!pos || pos!=line)
continue;
pos+=strlen(SRC_IDEN);
char* en=strstr(pos, "\n");
if (!en) continue;
char* file_name = new char[en-pos+1];
memcpy(file_name, pos, en-pos);
file_name[en-pos]=0;
int ftype = getfext(file_name);
if (FEXT_OTHER == ftype || FEXT_NO_EXT == ftype)
{
delete[] file_name;
} else
{
sources.addfile(file_name);
nf++;
}
}
delete [] line;
fclose(f);
return nf;
}
int ProcessFile(const char* filename, lsrc_item* item)
{
FILE* f= fopen(filename, "rb");
if (!f) return 0;
fseek(f, 0, SEEK_END);
unsigned long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
char *filebuf = new char[fsize];
fread(filebuf, 1, fsize, f);
int lcount= 0;
_counter_data d= count(filebuf, fsize);
fclose(f);
item->fs=fsize;
item->lc = d._lines_+d._comnt_ + d._blank_;
item->cc = d._comnt_;
item->elc = d._lines_;
item->blc = d._blank_;
delete [] filebuf;
return lcount;
}
void chg_to_dir(const char* file_name, char*& cur_dir)
{
const char *f_s = strchr(file_name, '\\');
const char *l_s = NULL;
if (!f_s) return;
while( f_s )
{
l_s = f_s;
f_s=strchr(l_s+1, '\\');
}
char *dirbuf = new char[l_s-file_name+1];
memcpy(dirbuf, file_name, l_s-file_name);
dirbuf[l_s-file_name]=0;
int howmuch = GetCurrentDirectory(0, NULL);
cur_dir = new char[howmuch];
GetCurrentDirectory(howmuch, cur_dir);
if (!SetCurrentDirectory(dirbuf))
{
delete[] cur_dir;
cur_dir = NULL;
}
delete [] dirbuf;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.