home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
dbutil.zip
/
BUFOP.ZIP
/
FILES.CPP
< prev
next >
Wrap
Text File
|
1993-09-05
|
5KB
|
132 lines
#include "hostvars.hpp"
#include "options.hpp"
#include "compsql.hpp"
#include "files.hpp"
#include <itime.hpp>
#include <idate.hpp>
#include <fstream.h>
#include <Istring.hpp>
const char strtcomment[] ="/* * * * * S Q L R E M O V E D * * * * \n";
const char endcomment[] = " \n* * * * * E N D O F S Q L R E M O V E */ \n";
void removeComments(IString & theStr,Boolean inSQLStmt);
void processFile(IString fileName)
/****************************************************************/
/* this routine will process the input file and generate calls */
/* for the IBM DB2 OS/2 database */
/* The header files can include other includes */
/* but they can not be recursive (i.e. header a include header b */
/* which includes header a) */
/****************************************************************/
{
ifstream fin;
ofstream fout;
int count;
int total;
char instr[256]; // largest input line
IString line="" ,source;
fin.open(fileName,ios::in);
if (!fin) {
cout << "could not process file: " << fileName << "\n";
return; // big deal
} /* endif */
// make the output file name
// if the suffix was sqh make into hpp
// if the suffix was sqc make into cpp
fileName = fileName.upperCase();
fileName = fileName.change(".SQH",".HPP"); // if header file
fileName = fileName.change(".SQC",".CPP"); // if source file
fout.open(fileName);
if (!fout) {
cout << " could not open output file " << fileName << "\n";
} /* endif */
count = 0;
IString msg;
msg = "Processing ";
msg += fileName;
monitorMessage( msg);
ITime t;
IDate d;
fout << "// \n";
fout << "// processed by precompiler " << d.today() << " " << t.now() << "\n";
fout << "// \n";
while (fin.eof()== 0) {
count++;
fin.getline(instr,255);
line = instr;
source = line;
removeComments(line,false);
if (IsSQL(line)) { // if this is an SQL command
// fout << strtcomment; // start a begin comment block
source.insert("//### "); // comment each line
while (! line.includes(";")) { // look for end of SQL Stm
fin.getline(instr,255);
source = source + "\n//### " +instr; // comment &append the source
IString tmp = instr;
removeComments(tmp,true);
line = line + tmp;
count++;
} /* endwhile */
source = source + "\n ";
char * cp = &source[0];
fout.write(cp,source.length());
// fout << endcomment; // end of comment block
prepareSQL(line,fout,count);
line = "";
source = "";
} /* endif */
else{
fout << source << "\n";
if (InDeclare()) {
processDeclare(line);
} /*endif */
}
} /* endwhile */
fout.close();
} // end process file
static int inComment = 0;
void removeComments(IString & theStr, Boolean InSQLStmt)
{
int copypos=0;
/***************************************************** */
/* if we were in the middle of a multi line comment */
/* check to see of the end of comment is on this line */
/* if it is, then delete up to the end of the comment */
/***************************************************** */
if (inComment > 0) { // check if comming out of comment
if (theStr.includes("*/")){ // end of comment in this line
theStr.remove(0,theStr.indexOf("*/")+2);
inComment--; // dec comment counter
}
else
{ theStr= ""; // in a comment return empty str
return;
}/* endif end of comment */
} /* endif was in comment line */
if (InSQLStmt) { // allow ANSI standard sql comments
theStr.change("--","//"); // by making them look like C++ comments
} /* endif */
if (theStr.includes("//")) { // check for one line comments
copypos = theStr.indexOf("//");
theStr = theStr.subString(0,copypos-1);
} /* endif // type comment */
if (theStr.includes("/*")) {
copypos = theStr.indexOf("/*"); // check for normal comment
inComment++;
IString tmp = theStr.subString(0,copypos-1);
removeComments(theStr,false); // recursive call to check for end of comment
theStr.insert(tmp);
} /* endif */
return;
} // end of remove comments