$treeview $search $mathjax $extrastylesheet
otsdaq_utilities
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 // doxygen_main_editor.cpp 00002 // by rrivera at fnal dot gov 00003 // created May 2018 00004 // 00005 // This is a simple html code injector to improve the main.html generated by doxygen. 00006 // 00007 // Planned to be used in conjunction with OnlineDocPushUpdate.sh 00008 // 00009 // compile with: 00010 // g++ doxygen_main_editor.cpp -o hw.o 00011 // 00012 // if developing, consider appending -D_GLIBCXX_DEBUG to get more 00013 // descriptive error messages 00014 // 00015 // run with: 00016 //./doxygen_main_editor.o <full main.html path> <full inject main html file path> 00017 // 00018 00019 #include <arpa/inet.h> 00020 #include <errno.h> 00021 #include <netdb.h> 00022 #include <netinet/in.h> 00023 #include <stdio.h> 00024 #include <stdlib.h> 00025 #include <string.h> 00026 #include <sys/socket.h> 00027 #include <sys/types.h> 00028 #include <unistd.h> 00029 #include <iomanip> 00030 #include <iostream> 00031 00032 // take only file name 00033 #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 00034 00035 // use this for normal printouts 00036 #define __PRINTF__ printf 00037 #define __COUT__ cout << __FILENAME__ << std::dec << " [" << __LINE__ << "]\t" 00038 #define __E__ std::endl 00039 00040 // and use this to suppress 00041 //#define __PRINTF__ if(0) printf 00042 //#define __COUT__ if(0) cout 00043 00044 using namespace std; 00045 00046 int main(int argc, char** argv) 00047 { 00048 __COUT__ << "Starting doxygen main.html editor..." << __E__; 00049 00050 if(argc < 4) 00051 { 00052 __COUT__ << "Need 3 arguments: for the full path to main.html AND to " 00053 "ARRAY:<html-to-inject>" 00054 << __E__; 00055 return 0; 00056 } 00057 string mainfn = argv[1]; 00058 string injectfn = argv[2]; 00059 string inject2fn = argv[3]; 00060 __COUT__ << "main.html destination full path: " << mainfn << __E__; 00061 __COUT__ << "main.html source full path: " << mainfn + ".bk" << __E__; 00062 __COUT__ << "inject.html source full path: " << injectfn << __E__; 00063 __COUT__ << "inject2.html source full path: " << inject2fn << __E__; 00064 00065 FILE* mainSrc = fopen((mainfn + ".bk").c_str(), "r"); 00066 if(!mainSrc) 00067 { 00068 __COUT__ << "Failed to open... " << mainfn + ".bk" << __E__; 00069 return 0; 00070 } 00071 FILE* injectSrc = fopen((injectfn).c_str(), "r"); 00072 if(!injectSrc) 00073 { 00074 __COUT__ << "Failed to open... " << injectfn << __E__; 00075 return 0; 00076 } 00077 FILE* inject2Src = fopen((inject2fn).c_str(), "r"); 00078 if(!inject2Src) 00079 { 00080 __COUT__ << "Failed to open... " << inject2fn << __E__; 00081 return 0; 00082 } 00083 FILE* mainDest = fopen((mainfn).c_str(), "w"); 00084 if(!mainSrc) 00085 { 00086 __COUT__ << "Failed to open... " << mainfn << __E__; 00087 return 0; 00088 } 00089 00090 char line[1000]; 00091 unsigned int countdown = -1; 00092 00093 unsigned int injectIndex = 0; 00094 00095 bool injected = true; 00096 while(fgets(line, 1000, mainSrc)) 00097 { 00098 fputs(line, mainDest); // output main line to file 00099 __COUT__ << line << (line[strlen(line) - 1] == '\n' ? "" : "\n"); 00100 00101 if(injected && !strcmp(line, "<div class=\"contents\">\n")) 00102 { 00103 injected = false; 00104 countdown = 0; 00105 injectIndex = 1; 00106 // continue; 00107 } 00108 else if(injected && !strcmp(line, "<head>\n")) 00109 { 00110 injected = false; 00111 countdown = 0; 00112 injectIndex = 2; 00113 // continue; 00114 } 00115 00116 if(!injected && countdown == 0) // inject file 00117 { 00118 injected = true; 00119 00120 switch(injectIndex) 00121 { 00122 case 1: 00123 { 00124 // get one more line and modify it, ie, clip ugly start and delete close 00125 // tag for content div fgets(line,1000,mainSrc); 00126 // __COUT__ << "MOD " << line << (line[strlen(line)-1] == 00127 //'\n'?"":"\n"); line[strlen(line)-7] = '\0'; 00128 // for(countdown=strlen(line)-16;countdown<strlen(line);++countdown) 00129 // if(line[countdown]=='v') break; 00130 // 00131 // //keep version number 00132 // fputs("<h3>",mainDest); 00133 // __COUT__ << "<h3>" << __E__; 00134 // fputs(&line[countdown],mainDest); //output main line to 00135 // file 00136 // __COUT__ << &line[countdown] << __E__; 00137 00138 while(fgets(line, 1000, injectSrc)) 00139 { 00140 fputs(line, mainDest); // output inject line to file 00141 __COUT__ << line << (line[strlen(line) - 1] == '\n' ? "" : "\n"); 00142 } 00143 00144 // add close content div 00145 // fputs("</div>",mainDest); 00146 // __COUT__ << "</div>" << __E__; 00147 00148 break; 00149 } 00150 case 2: 00151 { 00152 while(fgets(line, 1000, inject2Src)) 00153 { 00154 fputs(line, mainDest); // output inject line to file 00155 __COUT__ << line << (line[strlen(line) - 1] == '\n' ? "" : "\n"); 00156 } 00157 break; 00158 } 00159 default: 00160 __COUT__ << "Unknown injection!" << __E__; 00161 } 00162 } 00163 else if(!injected) 00164 { 00165 --countdown; 00166 } 00167 } 00168 00169 fclose(mainDest); 00170 fclose(injectSrc); 00171 fclose(mainSrc); 00172 00173 __COUT__ << "Doxygen main.html editor complete!" << __E__; 00174 00175 return 0; 00176 }