small improvements to htmlgen utility; this does NOT affect the mozilla tree

This commit is contained in:
rickg%netscape.com 2000-01-22 00:55:25 +00:00
parent b109cd3999
commit 493c18e6d6
2 changed files with 132 additions and 122 deletions

View File

@ -7,10 +7,10 @@
/*======================================================== /*========================================================
Special keywords: Special keywords:
$0..$9: represent command line arguments $0..$9: represent command line arguments
@file: the name of the file being writtent @file: the name of the file being writtent
@nextfile: the name of the next file to be written @nextfile: the name of the next file to be written
@htmlgen: runs the app recursively with given arguments. @import: imports text from another file.
*========================================================*/ *========================================================*/
@ -26,27 +26,27 @@
static char* tagTable[] = { static char* tagTable[] = {
"a", "abbr", "acronym", "address", "applet", "area", "A", "ABBR", "ACRONYM", "ADDRESS", "APPLET", "AREA",
"b", "base", "basefont", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "B", "BASE", "BASEFONT", "BDO", "BGSOUND", "BIG", "BLINK", "BLOCKQUOTE", "BODY", "BR", "BUTTON",
"caption", "center", "cite", "code", "col", "colgroup", "CAPTION", "CENTER", "CITE", "CODE", "COL", "COLGROUP",
"dd", "del", "dfn", "dir", "div", "dl", "dt", "DD", "DEL", "DFN", "DIR", "DIV", "DL", "DT",
"em", "embed", "EM", "EMBED",
"fieldset", "font", "form", "frame", "frameset", "FIELDSET", "FONT", "FORM", "FRAME", "FRAMESET",
"h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "html", "H1", "H2", "H3", "H4", "H5", "H6", "HEAD", "HR", "HTML",
"i", "iframe", "ilayer", "img", "input", "ins", "isindex", "I", "IFRAME", "ILAYER", "IMG", "INPUT", "INS", "ISINDEX",
"kbd", "keygen", "KBD", "KEYGEN",
"label", "layer", "legend", "li", "link", "listing", "LABEL", "LAYER", "LEGEND", "LI", "LINK", "LISTING",
"map", "menu", "meta", "multicol", "MAP", "MENU", "META", "MULTICOL",
"nobr", "noembed", "noframes", "nolayer", "noscript", "NOBR", "NOEMBED", "NOFRAMES", "NOLAYER", "NOSCRIPT",
"object", "ol", "optgroup", "option", "OBJECT", "OL", "OPTGROUP", "OPTION",
"p", "param", "plaintext", "pre", "P", "PARAM", "PLAINTEXT", "PRE",
"q", "Q",
"s","samp","script","select","server","small","sound","spacer","span","strike","strong","style","sub","sup", "S","SAMP","SCRIPT","SELECT","SERVER","SMALL","SOUND","SPACER","SPAN","STRIKE","STRONG","STYLE","SUB","SUP",
"table", "tbody", "td", "textarea", "tfoot", "th", "thead", "title", "tr", "tt", "TABLE", "TBODY", "TD", "TEXTAREA", "TFOOT", "TH", "THEAD", "TITLE", "TR", "TT",
"u", "ul", "U", "UL",
"var", "VAR",
"wbr", "WBR",
"xmp", "XMP",
0 0
}; };
static char gCWD[1025]; static char gCWD[1025];
@ -83,15 +83,15 @@ int findTag(const char* aTagName) {
int findNearestTag(char* aTag){ int findNearestTag(char* aTag){
int result=-1; int result=-1;
if(aTag){ if(aTag){
char theChar=tolower(aTag[0]); char theChar=toupper(aTag[0]);
int theIndex=-1; int theIndex=-1;
while(tagTable[++theIndex]){ while(tagTable[++theIndex]){
if(tolower(tagTable[theIndex][0])==theChar) { if(toupper(tagTable[theIndex][0])==theChar) {
return theIndex; return theIndex;
} }
} }
} }
if(tolower(aTag[0])<'a') if(toupper(aTag[0])<'A')
result=0; result=0;
else result=107; else result=107;
return result; return result;
@ -280,14 +280,16 @@ public:
strcpy(mFilename,theBuffer); strcpy(mFilename,theBuffer);
readDefs=false; readDefs=false;
} }
#if 0
else if(!stricmp(theBuffer,"-D")){ else if(!stricmp(theBuffer,"-D")){
readDefs=true; readDefs=true;
} }
#endif
else if(!stricmp(theBuffer,"-O")){ else if(!stricmp(theBuffer,"-O")){
aStream >> theBuffer; aStream >> theBuffer;
readDefs=false; readDefs=false;
} }
else if(readDefs){ else {
if(theBuffer[0]){ if(theBuffer[0]){
addMacro(theBuffer); addMacro(theBuffer);
theBuffer[0]=0; theBuffer[0]=0;
@ -300,7 +302,7 @@ public:
void buildArgBuffer(char* aBuffer) { void buildArgBuffer(char* aBuffer) {
aBuffer[0]=0; aBuffer[0]=0;
if(mFilename[0]) { if(mFilename[0]) {
sprintf(aBuffer,"-0 %s -f %s -d ",gThisFile,mFilename); sprintf(aBuffer,"-o %s -f %s ",gThisFile,mFilename);
} }
for(int i=0;i<mCount;i++){ for(int i=0;i<mCount;i++){
if(mKeys[i]) { if(mKeys[i]) {
@ -407,44 +409,42 @@ void expandMacros(char* aBuffer,CMacros& aMacroSet){
* @param * @param
* @return * @return
*/ */
int processFile(char* aDir,fstream& anOutputStream,istrstream& aInputArgs){ int processFile(char* aDir,CMacros& aMacroList,fstream& anOutputStream,fstream& anInputStream){
int result=0; int result=0;
CMacros theMacros; if(anInputStream.is_open()){
theMacros.consume(aInputArgs); bool done=false;
char theBuffer[1024];
char* theFilename=theMacros.getFilename(); char* p=0;
fstream theInputStream(theFilename,ios::in);
if(theInputStream.is_open()){
bool done=false;
char theBuffer[1024];
char theWord[600];
while((!done) && (0==result)){ while((!done) && (0==result)){
theInputStream.getline(theBuffer,sizeof(theBuffer)-1); anInputStream.getline(theBuffer,sizeof(theBuffer)-1);
if(theInputStream.gcount()){ if(anInputStream.gcount()){
//before doing anything else, expand the macros and keywords... //before doing anything else, expand the macros and keywords...
expandMacros(theBuffer,theMacros); expandMacros(theBuffer,aMacroList);
expandKeywords(theBuffer,theMacros); expandKeywords(theBuffer,aMacroList);
//Now process each line: //Now process each line:
if(strchr(theBuffer,'@')) { p=strstr(theBuffer,"@import");
if(p) {
//First, see if the line is an htmlgen statement; if so, recurse to read new file... //First, see if the line is an htmlgen statement; if so, recurse to read new file...
istrstream iStr(theBuffer); char theFilename[1024];
iStr>>theWord;
if(!stricmp(theWord,"@htmlgen")){
//If you're here, we found an htmlgen statement. strcpy(theFilename,"htmlgen -F ");
// To handle this, we have to: p+=8;
// 1. strip off the @htmlgen strcat(theFilename,p);
// 2. grab the filename and collect the args,
// 3. and recurse... //If you're here, we found an htmlgen statement.
// To handle this, we have to:
result=processFile(aDir,anOutputStream,iStr); // 1. strip off the @htmlgen
} // 2. grab the filename and collect the args,
// 3. and recurse...
fstream theInStream(p,ios::in);
result=processFile(aDir,aMacroList,anOutputStream,theInStream);
} }
else anOutputStream << theBuffer << endl; else anOutputStream << theBuffer << endl;
} }
@ -467,17 +467,22 @@ int iterate(istrstream& aInputArgs){
CMacros theArgs; CMacros theArgs;
theArgs.consume(aInputArgs); theArgs.consume(aInputArgs);
char theBuffer[1024];
char theFilename[1024]; char theFilename[1024];
bool done=!theArgs.first(); bool done=!theArgs.first();
while((!done) && (0==result)){ while((!done) && (0==result)){
CMacros theTempArgs(theArgs); CMacros theTempArgs(theArgs);
theTempArgs.buildArgBuffer(theBuffer);
istrstream theArgStream(theBuffer); //theTempArgs.buildArgBuffer(theBuffer);
// istrstream theArgStream(theBuffer);
sprintf(theFilename,"%s\\%s",gCWD,gThisFile); sprintf(theFilename,"%s\\%s",gCWD,gThisFile);
fstream theOutStream(theFilename,ios::trunc); fstream theOutStream(theFilename,ios::trunc);
result=processFile(gCWD,theOutStream,theArgStream);
char* theInFile=theArgs.getFilename();
fstream theInStream(theInFile,ios::in);
result=processFile(gCWD,theTempArgs,theOutStream,theInStream);
theArgs.dump(); theArgs.dump();
done=!theArgs.next(); done=!theArgs.next();
} }
@ -507,6 +512,6 @@ int main(int argc,char* argv[]){
istrstream aStrStream(theBuffer); istrstream aStrStream(theBuffer);
result=iterate(aStrStream); result=iterate(aStrStream);
} }
else cout<<endl <<"HTMLGenerator usage -f filename [-d yyy|xxx,yyy|xxx...yyy]" << endl; else cout<<endl <<"HTMLGenerator usage -f filename [yyy | xxx,yyy | xxx-yyy]" << endl;
return result; return result;
} }

View File

@ -7,10 +7,10 @@
/*======================================================== /*========================================================
Special keywords: Special keywords:
$0..$9: represent command line arguments $0..$9: represent command line arguments
@file: the name of the file being writtent @file: the name of the file being writtent
@nextfile: the name of the next file to be written @nextfile: the name of the next file to be written
@htmlgen: runs the app recursively with given arguments. @import: imports text from another file.
*========================================================*/ *========================================================*/
@ -26,27 +26,27 @@
static char* tagTable[] = { static char* tagTable[] = {
"a", "abbr", "acronym", "address", "applet", "area", "A", "ABBR", "ACRONYM", "ADDRESS", "APPLET", "AREA",
"b", "base", "basefont", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "B", "BASE", "BASEFONT", "BDO", "BGSOUND", "BIG", "BLINK", "BLOCKQUOTE", "BODY", "BR", "BUTTON",
"caption", "center", "cite", "code", "col", "colgroup", "CAPTION", "CENTER", "CITE", "CODE", "COL", "COLGROUP",
"dd", "del", "dfn", "dir", "div", "dl", "dt", "DD", "DEL", "DFN", "DIR", "DIV", "DL", "DT",
"em", "embed", "EM", "EMBED",
"fieldset", "font", "form", "frame", "frameset", "FIELDSET", "FONT", "FORM", "FRAME", "FRAMESET",
"h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "html", "H1", "H2", "H3", "H4", "H5", "H6", "HEAD", "HR", "HTML",
"i", "iframe", "ilayer", "img", "input", "ins", "isindex", "I", "IFRAME", "ILAYER", "IMG", "INPUT", "INS", "ISINDEX",
"kbd", "keygen", "KBD", "KEYGEN",
"label", "layer", "legend", "li", "link", "listing", "LABEL", "LAYER", "LEGEND", "LI", "LINK", "LISTING",
"map", "menu", "meta", "multicol", "MAP", "MENU", "META", "MULTICOL",
"nobr", "noembed", "noframes", "nolayer", "noscript", "NOBR", "NOEMBED", "NOFRAMES", "NOLAYER", "NOSCRIPT",
"object", "ol", "optgroup", "option", "OBJECT", "OL", "OPTGROUP", "OPTION",
"p", "param", "plaintext", "pre", "P", "PARAM", "PLAINTEXT", "PRE",
"q", "Q",
"s","samp","script","select","server","small","sound","spacer","span","strike","strong","style","sub","sup", "S","SAMP","SCRIPT","SELECT","SERVER","SMALL","SOUND","SPACER","SPAN","STRIKE","STRONG","STYLE","SUB","SUP",
"table", "tbody", "td", "textarea", "tfoot", "th", "thead", "title", "tr", "tt", "TABLE", "TBODY", "TD", "TEXTAREA", "TFOOT", "TH", "THEAD", "TITLE", "TR", "TT",
"u", "ul", "U", "UL",
"var", "VAR",
"wbr", "WBR",
"xmp", "XMP",
0 0
}; };
static char gCWD[1025]; static char gCWD[1025];
@ -83,15 +83,15 @@ int findTag(const char* aTagName) {
int findNearestTag(char* aTag){ int findNearestTag(char* aTag){
int result=-1; int result=-1;
if(aTag){ if(aTag){
char theChar=tolower(aTag[0]); char theChar=toupper(aTag[0]);
int theIndex=-1; int theIndex=-1;
while(tagTable[++theIndex]){ while(tagTable[++theIndex]){
if(tolower(tagTable[theIndex][0])==theChar) { if(toupper(tagTable[theIndex][0])==theChar) {
return theIndex; return theIndex;
} }
} }
} }
if(tolower(aTag[0])<'a') if(toupper(aTag[0])<'A')
result=0; result=0;
else result=107; else result=107;
return result; return result;
@ -280,14 +280,16 @@ public:
strcpy(mFilename,theBuffer); strcpy(mFilename,theBuffer);
readDefs=false; readDefs=false;
} }
#if 0
else if(!stricmp(theBuffer,"-D")){ else if(!stricmp(theBuffer,"-D")){
readDefs=true; readDefs=true;
} }
#endif
else if(!stricmp(theBuffer,"-O")){ else if(!stricmp(theBuffer,"-O")){
aStream >> theBuffer; aStream >> theBuffer;
readDefs=false; readDefs=false;
} }
else if(readDefs){ else {
if(theBuffer[0]){ if(theBuffer[0]){
addMacro(theBuffer); addMacro(theBuffer);
theBuffer[0]=0; theBuffer[0]=0;
@ -300,7 +302,7 @@ public:
void buildArgBuffer(char* aBuffer) { void buildArgBuffer(char* aBuffer) {
aBuffer[0]=0; aBuffer[0]=0;
if(mFilename[0]) { if(mFilename[0]) {
sprintf(aBuffer,"-0 %s -f %s -d ",gThisFile,mFilename); sprintf(aBuffer,"-o %s -f %s ",gThisFile,mFilename);
} }
for(int i=0;i<mCount;i++){ for(int i=0;i<mCount;i++){
if(mKeys[i]) { if(mKeys[i]) {
@ -407,44 +409,42 @@ void expandMacros(char* aBuffer,CMacros& aMacroSet){
* @param * @param
* @return * @return
*/ */
int processFile(char* aDir,fstream& anOutputStream,istrstream& aInputArgs){ int processFile(char* aDir,CMacros& aMacroList,fstream& anOutputStream,fstream& anInputStream){
int result=0; int result=0;
CMacros theMacros; if(anInputStream.is_open()){
theMacros.consume(aInputArgs); bool done=false;
char theBuffer[1024];
char* theFilename=theMacros.getFilename(); char* p=0;
fstream theInputStream(theFilename,ios::in);
if(theInputStream.is_open()){
bool done=false;
char theBuffer[1024];
char theWord[600];
while((!done) && (0==result)){ while((!done) && (0==result)){
theInputStream.getline(theBuffer,sizeof(theBuffer)-1); anInputStream.getline(theBuffer,sizeof(theBuffer)-1);
if(theInputStream.gcount()){ if(anInputStream.gcount()){
//before doing anything else, expand the macros and keywords... //before doing anything else, expand the macros and keywords...
expandMacros(theBuffer,theMacros); expandMacros(theBuffer,aMacroList);
expandKeywords(theBuffer,theMacros); expandKeywords(theBuffer,aMacroList);
//Now process each line: //Now process each line:
if(strchr(theBuffer,'@')) { p=strstr(theBuffer,"@import");
if(p) {
//First, see if the line is an htmlgen statement; if so, recurse to read new file... //First, see if the line is an htmlgen statement; if so, recurse to read new file...
istrstream iStr(theBuffer); char theFilename[1024];
iStr>>theWord;
if(!stricmp(theWord,"@htmlgen")){
//If you're here, we found an htmlgen statement. strcpy(theFilename,"htmlgen -F ");
// To handle this, we have to: p+=8;
// 1. strip off the @htmlgen strcat(theFilename,p);
// 2. grab the filename and collect the args,
// 3. and recurse... //If you're here, we found an htmlgen statement.
// To handle this, we have to:
result=processFile(aDir,anOutputStream,iStr); // 1. strip off the @htmlgen
} // 2. grab the filename and collect the args,
// 3. and recurse...
fstream theInStream(p,ios::in);
result=processFile(aDir,aMacroList,anOutputStream,theInStream);
} }
else anOutputStream << theBuffer << endl; else anOutputStream << theBuffer << endl;
} }
@ -467,17 +467,22 @@ int iterate(istrstream& aInputArgs){
CMacros theArgs; CMacros theArgs;
theArgs.consume(aInputArgs); theArgs.consume(aInputArgs);
char theBuffer[1024];
char theFilename[1024]; char theFilename[1024];
bool done=!theArgs.first(); bool done=!theArgs.first();
while((!done) && (0==result)){ while((!done) && (0==result)){
CMacros theTempArgs(theArgs); CMacros theTempArgs(theArgs);
theTempArgs.buildArgBuffer(theBuffer);
istrstream theArgStream(theBuffer); //theTempArgs.buildArgBuffer(theBuffer);
// istrstream theArgStream(theBuffer);
sprintf(theFilename,"%s\\%s",gCWD,gThisFile); sprintf(theFilename,"%s\\%s",gCWD,gThisFile);
fstream theOutStream(theFilename,ios::trunc); fstream theOutStream(theFilename,ios::trunc);
result=processFile(gCWD,theOutStream,theArgStream);
char* theInFile=theArgs.getFilename();
fstream theInStream(theInFile,ios::in);
result=processFile(gCWD,theTempArgs,theOutStream,theInStream);
theArgs.dump(); theArgs.dump();
done=!theArgs.next(); done=!theArgs.next();
} }
@ -507,6 +512,6 @@ int main(int argc,char* argv[]){
istrstream aStrStream(theBuffer); istrstream aStrStream(theBuffer);
result=iterate(aStrStream); result=iterate(aStrStream);
} }
else cout<<endl <<"HTMLGenerator usage -f filename [-d yyy|xxx,yyy|xxx...yyy]" << endl; else cout<<endl <<"HTMLGenerator usage -f filename [yyy | xxx,yyy | xxx-yyy]" << endl;
return result; return result;
} }