LCOV - code coverage report
Current view: top level - otsdaq-utilities/onlineDoc - doxygen_main_editor.cpp (source / functions) Coverage Total Hit
Test: mu2edaq.info.cleaned Lines: 0.0 % 67 0
Test Date: 2026-07-30 01:56:44 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /// doxygen_main_editor.cpp
       2              : ///    by rrivera at fnal dot gov
       3              : ///       created May 2018
       4              : ///
       5              : /// This is a simple html code injector to improve the main.html generated by doxygen.
       6              : ///
       7              : /// Planned to be used in conjunction with OnlineDocPushUpdate.sh
       8              : ///
       9              : /// compile with:
      10              : /// g++ doxygen_main_editor.cpp -o doxygen_main_editor
      11              : ///      or
      12              : /// g++ ./srcs/otsdaq-utilities/onlineDoc/doxygen_main_editor.cpp -o doxygen_main_editor
      13              : ///
      14              : /// if developing, consider appending -D_GLIBCXX_DEBUG to get more
      15              : /// descriptive error messages
      16              : ///
      17              : /// run with:
      18              : ///./doxygen_main_editor <full main.html path> <full inject main html file path>
      19              : ///
      20              : ///
      21              : #include <arpa/inet.h>
      22              : #include <errno.h>
      23              : #include <netdb.h>
      24              : #include <netinet/in.h>
      25              : #include <stdio.h>
      26              : #include <stdlib.h>
      27              : #include <string.h>
      28              : #include <sys/socket.h>
      29              : #include <sys/types.h>
      30              : #include <unistd.h>
      31              : #include <iomanip>
      32              : #include <iostream>
      33              : 
      34              : /// use this for normal printouts
      35              : #define __PRINTF__ printf
      36              : 
      37              : #define __MF_SUBJECT__ "doxy_main"
      38              : 
      39              : #define __SHORTFILE__                                   \
      40              :         (__builtin_strstr(&__FILE__[0], "/srcs/")           \
      41              :              ? __builtin_strstr(&__FILE__[0], "/srcs/") + 6 \
      42              :              : __FILE__)
      43              : #define __COUT_HDR_L__ "[" << std::dec << __LINE__ << " |\t"
      44              : #define __COUT_HDR_FL__ __SHORTFILE__ << " " << __COUT_HDR_L__
      45              : 
      46              : #define __COUT_TYPE__(X) std::cout << QUOTE(X) << ":"
      47              : #define __COUT_ERR__ __COUT_TYPE__(LogError) << __COUT_HDR_FL__
      48              : #define __COUT_WARN__ __COUT_TYPE__(LogWarning) << __COUT_HDR_FL__
      49              : #define __COUT_INFO__ __COUT_TYPE__(LogInfo) << __COUT_HDR_FL__
      50              : #define __COUT__ __COUT_TYPE__(LogDebug) << __COUT_HDR_FL__
      51              : 
      52              : #define __SS__            \
      53              :         std::stringstream ss; \
      54              :         ss << "|" << __MF_DECOR__ << ": " << __COUT_HDR_FL__
      55              : #define __SS_THROW__                        \
      56              :         {                                       \
      57              :                 __COUT_ERR__ << "\n" << ss.str();   \
      58              :                 throw std::runtime_error(ss.str()); \
      59              :         }  //put in {}'s to prevent surprises, e.g. if ... else __SS_THROW__;
      60              : #define __E__ std::endl
      61              : #define Q(X) #X
      62              : #define QUOTE(X) Q(X)
      63              : #define __COUTV__(X) __COUT__ << QUOTE(X) << " = " << X << __E__
      64              : 
      65              : /// and use this to suppress
      66              : /// #define __PRINTF__ if(0) printf
      67              : /// #define __COUT__  if(0) std::cout
      68              : ///
      69            0 : int main(int argc, char** argv)
      70              : {
      71            0 :         __COUT__ << "Starting doxygen main.html editor..." << __E__;
      72              : 
      73            0 :         if(argc < 4)
      74              :         {
      75            0 :                 __COUT__ << "Need 3 arguments: for the full path to main.html AND to "
      76            0 :                             "ARRAY:<html-to-inject>"
      77            0 :                          << __E__;
      78            0 :                 return 0;
      79              :         }
      80            0 :         std::string mainfn    = argv[1];
      81            0 :         std::string injectfn  = argv[2];
      82            0 :         std::string inject2fn = argv[3];
      83            0 :         __COUT__ << "main.html destination full path: " << mainfn << __E__;
      84            0 :         __COUT__ << "main.html source full path: " << mainfn + ".bk" << __E__;
      85            0 :         __COUT__ << "inject.html source full path: " << injectfn << __E__;
      86            0 :         __COUT__ << "inject2.html source full path: " << inject2fn << __E__;
      87              : 
      88            0 :         FILE* mainSrc = fopen((mainfn + ".bk").c_str(), "r");
      89            0 :         if(!mainSrc)
      90              :         {
      91            0 :                 __COUT__ << "Failed to open... " << mainfn + ".bk" << __E__;
      92            0 :                 return 0;
      93              :         }
      94            0 :         FILE* injectSrc = fopen((injectfn).c_str(), "r");
      95            0 :         if(!injectSrc)
      96              :         {
      97            0 :                 __COUT__ << "Failed to open... " << injectfn << __E__;
      98            0 :                 return 0;
      99              :         }
     100            0 :         FILE* inject2Src = fopen((inject2fn).c_str(), "r");
     101            0 :         if(!inject2Src)
     102              :         {
     103            0 :                 __COUT__ << "Failed to open... " << inject2fn << __E__;
     104            0 :                 return 0;
     105              :         }
     106            0 :         FILE* mainDest = fopen((mainfn).c_str(), "w");
     107            0 :         if(!mainSrc)
     108              :         {
     109            0 :                 __COUT__ << "Failed to open... " << mainfn << __E__;
     110            0 :                 return 0;
     111              :         }
     112              : 
     113              :         char         line[1000];
     114            0 :         unsigned int countdown = -1;
     115              : 
     116            0 :         unsigned int injectIndex = 0;
     117              : 
     118            0 :         bool injected = true;
     119            0 :         while(fgets(line, 1000, mainSrc))
     120              :         {
     121            0 :                 fputs(line, mainDest);  // output main line to file
     122            0 :                 __COUT__ << line << (line[strlen(line) - 1] == '\n' ? "" : "\n");
     123              : 
     124            0 :                 if(injected && !strcmp(line, "<div class=\"contents\">\n"))
     125              :                 {
     126            0 :                         injected    = false;
     127            0 :                         countdown   = 0;
     128            0 :                         injectIndex = 1;
     129              :                         // continue;
     130              :                 }
     131            0 :                 else if(injected && !strcmp(line, "<head>\n"))
     132              :                 {
     133            0 :                         injected    = false;
     134            0 :                         countdown   = 0;
     135            0 :                         injectIndex = 2;
     136              :                         // continue;
     137              :                 }
     138              : 
     139            0 :                 if(!injected && countdown == 0)  // inject file
     140              :                 {
     141            0 :                         injected = true;
     142              : 
     143            0 :                         switch(injectIndex)
     144              :                         {
     145            0 :                         case 1: {
     146              :                                 // get one more line and modify it, ie, clip ugly start and delete close
     147              :                                 // tag for content div                          fgets(line,1000,mainSrc);
     148              :                                 //                              __COUT__ << "MOD " << line << (line[strlen(line)-1] ==
     149              :                                 //'\n'?"":"\n");                            line[strlen(line)-7] = '\0';
     150              :                                 //                              for(countdown=strlen(line)-16;countdown<strlen(line);++countdown)
     151              :                                 //                                      if(line[countdown]=='v') break;
     152              :                                 //
     153              :                                 //                              //keep version number
     154              :                                 //                              fputs("<h3>",mainDest);
     155              :                                 //                              __COUT__ << "<h3>" << __E__;
     156              :                                 //                              fputs(&line[countdown],mainDest); //output main line to
     157              :                                 // file
     158              :                                 //                              __COUT__ << &line[countdown] << __E__;
     159              : 
     160            0 :                                 while(fgets(line, 1000, injectSrc))
     161              :                                 {
     162            0 :                                         fputs(line, mainDest);  // output inject line to file
     163            0 :                                         __COUT__ << line << (line[strlen(line) - 1] == '\n' ? "" : "\n");
     164              :                                 }
     165              : 
     166              :                                 // add close content div
     167              :                                 //                              fputs("</div>",mainDest);
     168              :                                 //                              __COUT__ << "</div>" << __E__;
     169              : 
     170            0 :                                 break;
     171              :                         }
     172            0 :                         case 2: {
     173            0 :                                 while(fgets(line, 1000, inject2Src))
     174              :                                 {
     175            0 :                                         fputs(line, mainDest);  // output inject line to file
     176            0 :                                         __COUT__ << line << (line[strlen(line) - 1] == '\n' ? "" : "\n");
     177              :                                 }
     178            0 :                                 break;
     179              :                         }
     180            0 :                         default:
     181            0 :                                 __COUT__ << "Unknown injection!" << __E__;
     182              :                         }
     183              :                 }
     184            0 :                 else if(!injected)
     185              :                 {
     186            0 :                         --countdown;
     187              :                 }
     188              :         }
     189              : 
     190            0 :         fclose(mainDest);
     191            0 :         fclose(injectSrc);
     192            0 :         fclose(mainSrc);
     193              : 
     194            0 :         __COUT__ << "Doxygen main.html editor complete!" << __E__;
     195              : 
     196            0 :         return 0;
     197            0 : }
        

Generated by: LCOV version 2.0-1