/************************************************************************** cc_extract_html.C ============================================================= Project : Tools for the CC manual writing task around cc_manual.sty. Function : main program, command line parameter parsing System : bison, flex, C++ (g++) Author : (c) 1995 Lutz Kettner as of version 3.3 (Sept. 1999) maintained by Susan Hert Revision : $Id$ Date : $Date$ **************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* Program name and release */ /* ================================= */ const string prog_name = "cc_extract_html"; const string prog_release = "$Id$"; /* Configurable command line options */ /* ================================= */ Switch V_switch = NO_SWITCH; Switch trace_switch = NO_SWITCH; Switch line_switch = NO_SWITCH; Switch config_switch = NO_SWITCH; Switch quiet_switch = NO_SWITCH; Switch verbose_switch = NO_SWITCH; Switch macro_def_switch = NO_SWITCH; Switch macro_exp_switch = NO_SWITCH; Switch macro_def2_switch = NO_SWITCH; Switch macro_exp2_switch = NO_SWITCH; Switch sty_macro_switch = NO_SWITCH; Switch stack_trace_switch = NO_SWITCH; /* Config filename: */ /* ================================= */ string sty_filename = "latex.sty"; /* Configurable command line options */ /* ================================= */ // Manual date, release, title, and author used in filtering the config files. string manual_date; string manual_release; string manual_title; string manual_author; void init_commandline_args() { insertInternalGlobalMacro( "\\lciConfigPath", config_path); insertInternalGlobalMacro( "\\lciTmpPath", tmp_path); insertInternalGlobalMacro( "\\lciExtractHtmlRelease", prog_release); insertInternalGlobalMacro( "\\lciManualDate", manual_date); // check for date format as provided by latex_to_html if ( std::count( manual_date.begin(), manual_date.end(), ',') == 2) { // skip the day std::size_t pos = std::find( manual_date.begin(), manual_date.end(), ',') - manual_date.begin(); if ( manual_date[pos+1] == ' ' ) ++pos; string aux_date = manual_date; aux_date.replace( 0, pos, string()); insertInternalGlobalMacro( "\\today", aux_date); } else { // else keep the full date as provided insertInternalGlobalMacro( "\\today", manual_date); } insertInternalGlobalMacro( "\\lciManualRelease", manual_release); insertInternalGlobalMacro( "\\lciManualTitle", manual_title); insertInternalGlobalMacro( "\\lciManualAuthor", manual_author); insertInternalGlobalMacro( "\\lciIfVersionFlag", V_switch ? "\\lcTrue" : "\\lcFalse"); insertInternalGlobalMacro( "\\lciIfQuietFlag", quiet_switch ? "\\lcTrue" : "\\lcFalse"); insertInternalGlobalMacro( "\\lciIfVerboseFlag", verbose_switch ? "\\lcTrue" : "\\lcFalse"); insertInternalGlobalMacro( "\\lciIfMacroDefFlag", macro_def2_switch ? "\\lcTrue" : "\\lcFalse"); insertInternalGlobalMacro( "\\lciIfMacroExpFlag", macro_exp2_switch ? "\\lcTrue" : "\\lcFalse"); insertInternalGlobalMacro( "\\lciOutputFilename", ""); insertInternalGlobalMacro( "\\lciMainFilename", ""); } /* Index */ /* ======*/ extern int HREF_counter; /* Taylored semantic functions used in syntax.y */ /* ============================================ */ void handleString( const char* s) { if( current_ostream ) *current_ostream << s; } void handleString( const string& s) { if( current_ostream ) *current_ostream << s; } void handleChar( char c) { if( current_ostream ) *current_ostream << c; } /* main */ /* ==== */ #define MaxParameters 1000 #define MaxOptionalParameters 999 #define ErrParameters 10000 /* this macro opens a block, in which the switch is detected */ /* it must be closed with the macro endDetect() */ #define detectSwitch( var, text) \ if ( (( argv[i][0] == '/' ) || ( argv[i][0] == '-' ) || \ ( argv[i][0] == '+' )) && ( strcmp( text, argv[i]+1) == 0)) { \ if ( argv[i][0] == '+' ) \ var = PLUS_SWITCH; \ else \ var = MINUS_SWITCH; #define endDetect() \ if ( nParameters <= MaxParameters ) \ continue; \ else \ break; \ } /* >main: main function with standard unix parameter input */ /* ------------------------------------------------------- */ main( int argc, char **argv) { // Check environment: char* s = getenv("LATEX_CONV_CONFIG"); if( s ) config_path = s; s = getenv("LATEX_CONV_INPUTS"); if( s ) latex_conv_inputs = s; int i; int nParameters = 0; typedef const char* ParamType; ParamType parameters[ MaxParameters + 1]; Switch help_switch = NO_SWITCH; Switch dummy_switch; insertInternalGlobalMacro( "\\lciInstallLatexConverterCSSFile", "" ); for (i = 1; i < argc; i++) { /* check switches */ detectSwitch( dummy_switch, "get_latex_conv_config"); cout << config_path << endl; return 0; endDetect(); detectSwitch( dummy_switch, "date"); i++; if ( i < argc) manual_date = argv[i]; else { cerr << "*** Error: option -date needs an additional parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( dummy_switch, "release"); i++; if ( i < argc) manual_release = argv[i]; else { cerr << "*** Error: option -release needs an additional " "parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( dummy_switch, "title"); i++; if ( i < argc) manual_title = argv[i]; else { cerr << "*** Error: option -title needs an additional " "parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( dummy_switch, "author"); i++; if ( i < argc) manual_author = argv[i]; else { cerr << "*** Error: option -author needs an additional " "parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( config_switch, "config"); i++; if ( i < argc) { config_path = argv[i]; } else { cerr << "*** Error: option -config needs an additional " "parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( dummy_switch, "sty"); i++; if ( i < argc) { sty_filename = argv[i]; } else { cerr << "*** Error: option -sty needs an additional parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( dummy_switch, "tmp"); i++; if ( i < argc) { tmp_path = argv[i]; } else { cerr << "*** Error: option -tmp needs an additional parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( dummy_switch, "header"); i++; if ( i < argc) { string s = argv[i]; assert_trailing_slash_in_path( s); insertGlobalMacro( "\\lciHeaderPath", "", 0, s); if ( s[0] == '/') { insertGlobalMacro( "\\lciIfRelativeHeaderPath", "", 0,"\\lcFalse"); } else { insertGlobalMacro( "\\lciIfRelativeHeaderPath", "", 0, "\\lcTrue"); } } else { cerr << "*** Error: option -header needs an additional " "parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( dummy_switch, "color"); enableColor(); endDetect(); detectSwitch( dummy_switch, "main"); i++; if ( i < argc) { pre_main_filename = argv[i]; } else { cerr << "*** Error: option -main needs an additional parameter" << endl; nParameters = ErrParameters; } endDetect(); detectSwitch( quiet_switch, "quiet"); endDetect(); detectSwitch( verbose_switch, "v"); endDetect(); detectSwitch( trace_switch, "trace"); endDetect(); detectSwitch( line_switch, "line"); endDetect(); detectSwitch( macro_def2_switch, "macrodef"); endDetect(); detectSwitch( macro_exp2_switch, "macroexp"); endDetect(); detectSwitch( sty_macro_switch, "stymacro"); endDetect(); detectSwitch( stack_trace_switch, "stacktrace"); endDetect(); detectSwitch( V_switch, "V"); cerr << prog_name << " " << prog_release << " (c) Lutz Kettner" << endl; cerr << "Using: "; eraseMacro( "\\lciInstallLatexConverterCSSFile" ); endDetect(); detectSwitch( help_switch, "h"); endDetect(); detectSwitch( help_switch, "H"); endDetect(); detectSwitch( help_switch, "help"); endDetect(); // check for unknown command line option if ( argv[i][0] == '-' ) { cerr << "*** Error: unknown command line option `" << argv[i] << "'." << endl; nParameters = ErrParameters; } /* else get standard or optional parameters */ if ( nParameters < MaxParameters ) { parameters[nParameters ++] = argv[i]; continue; } nParameters = ErrParameters; break; } (void)(dummy_switch); // simulate a use of 'dummy_switch'. if (! V_switch && ((nParameters < MaxParameters - MaxOptionalParameters) || (nParameters > MaxParameters) || (help_switch != NO_SWITCH))) { if (help_switch == NO_SWITCH) cerr << "*** Error: in parameter list" << endl; cerr << prog_name << " " << prog_release << " (c) Lutz Kettner" << endl; cerr << "Usage: " << prog_name << " [] " << endl; cerr << " -V prints version message." < set a date for the manual." < set a release number for the " "manual." << endl; cerr << " -title set a title text for the manual." << endl; cerr << " -author set an author address (email) for " "the manual." << endl; cerr << " -config set the path where to find the " "config files." << endl; cerr << " -tmp set the path where to put the " "output files." << endl; cerr << " -header set the path to the C " "header files." << endl; cerr << " -main main filename for the part before" " any chapter." << endl; cerr << " -sty