| [722] | 1 | #include <stdlib.h> | 
|---|
|  | 2 | #include <stdio.h> | 
|---|
|  | 3 | #include <iostream.h> | 
|---|
|  | 4 |  | 
|---|
|  | 5 | #include "pistdimgapp.h" | 
|---|
|  | 6 | #include "piacmd.h" | 
|---|
|  | 7 | #include "piversion.h" | 
|---|
|  | 8 | #include "piaversion.h" | 
|---|
|  | 9 |  | 
|---|
|  | 10 | #include "timing.h" | 
|---|
|  | 11 | #include "skyinit.h" | 
|---|
|  | 12 |  | 
|---|
|  | 13 |  | 
|---|
|  | 14 | // ---- Pour charger automatiquement le module sopiamodule | 
|---|
|  | 15 | extern "C" { | 
|---|
|  | 16 | void sopiamodule_init(); | 
|---|
|  | 17 | void sopiamodule_end(); | 
|---|
|  | 18 | } | 
|---|
|  | 19 |  | 
|---|
|  | 20 |  | 
|---|
|  | 21 | /*  ================================ MAIN() =================================  */ | 
|---|
|  | 22 |  | 
|---|
|  | 23 | int main(int narg, char *arg[]) | 
|---|
|  | 24 | { | 
|---|
|  | 25 | int ofa; | 
|---|
|  | 26 | int fgfpe, fgsegv, fgred, fgexec; | 
|---|
|  | 27 |  | 
|---|
|  | 28 | SkyTInitiator skyinit; | 
|---|
|  | 29 |  | 
|---|
|  | 30 | InitTim(); | 
|---|
|  | 31 |  | 
|---|
|  | 32 | ofa = 1; | 
|---|
|  | 33 | if (narg > 1) | 
|---|
|  | 34 | { | 
|---|
|  | 35 | if (strcmp(arg[1],"-h") == 0) | 
|---|
|  | 36 | { | 
|---|
|  | 37 | puts("\n piapp: Programme d'analyse interactive "); | 
|---|
|  | 38 | puts("Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-help2tex] [-exec file [args]]"); | 
|---|
|  | 39 | puts("  -nored : NoRedirect StdOut/StdErr"); | 
|---|
|  | 40 | puts("  -nosig : Don't catch SigFPE, SigSEGV"); | 
|---|
|  | 41 | puts("  -nosigfpe -nosigsegv: Don't catch SigFPE / SigSEGV"); | 
|---|
|  | 42 | puts("  -help2tex: Create a LaTeX help file (piahelp.tex)"); | 
|---|
|  | 43 | puts("  -exec file [args] : Execute command file \n"); | 
|---|
|  | 44 | exit(0); | 
|---|
|  | 45 | } | 
|---|
|  | 46 | } | 
|---|
|  | 47 |  | 
|---|
|  | 48 | ofa = 1; | 
|---|
|  | 49 | fgred = fgfpe = fgsegv = true; | 
|---|
|  | 50 | fgexec = false; | 
|---|
|  | 51 | string exfc; | 
|---|
|  | 52 | // Pour fabriquer le help | 
|---|
|  | 53 | bool fgtexh = false; | 
|---|
|  | 54 | int ka; | 
|---|
|  | 55 | for(ka=1; ka<narg; ka++) { | 
|---|
|  | 56 | if (strcmp(arg[ka],"-nored") == 0)   fgred=false; | 
|---|
|  | 57 | else if (strcmp(arg[ka],"-nosig") == 0)   fgfpe=fgsegv=false; | 
|---|
|  | 58 | else if (strcmp(arg[ka],"-nosigfpe") == 0)   fgfpe=false; | 
|---|
|  | 59 | else if (strcmp(arg[ka],"-nosigsegv") == 0)   fgsegv=false; | 
|---|
|  | 60 | else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; } | 
|---|
|  | 61 | else if (strcmp(arg[ka],"-exec") == 0) { | 
|---|
|  | 62 | if (ka < narg-1) { | 
|---|
|  | 63 | fgexec = true; | 
|---|
|  | 64 | exfc = "exec"; | 
|---|
|  | 65 | for(int kaa=ka+1; kaa<narg; kaa++)  { exfc += ' ';  exfc +=  arg[kaa]; } | 
|---|
|  | 66 | } | 
|---|
|  | 67 | break; | 
|---|
|  | 68 | } | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str()); | 
|---|
|  | 72 | else printf(">>>>> Starting piapp <<<<< \n"); | 
|---|
|  | 73 | printf("Version: piapp=%g  PI=%g  SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER, | 
|---|
|  | 74 | (double)PI_VERSIONNUMBER, (double)skyinit.Version()); | 
|---|
|  | 75 |  | 
|---|
|  | 76 | PIStdImgApp * app = new PIStdImgApp(narg, arg); | 
|---|
|  | 77 |  | 
|---|
|  | 78 | // Gestion de redirection stdout/err et Signaux | 
|---|
|  | 79 | if (fgred) app->RedirectStdOutErr(true); | 
|---|
|  | 80 | else app->RedirectStdOutErr(false); | 
|---|
|  | 81 | app->CatchSignals(fgfpe, fgsegv); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | // S'il y a un fichier de commande a executer | 
|---|
|  | 84 | if (fgexec) app->CmdInterpreter()->Interpret(exfc); | 
|---|
|  | 85 |  | 
|---|
|  | 86 | // On charge le module sopiamodule | 
|---|
|  | 87 | sopiamodule_init(); | 
|---|
|  | 88 |  | 
|---|
|  | 89 | // S'il y a besoin de faire le fichier Help | 
|---|
|  | 90 | if (fgtexh) { | 
|---|
|  | 91 | string thf = "piahelp.tex"; | 
|---|
|  | 92 | app->CmdInterpreter()->HelptoLaTex(thf); | 
|---|
|  | 93 | printf("piapp : Help file piahelp.tex created --> exit(0) \n"); | 
|---|
|  | 94 | delete app; | 
|---|
|  | 95 | exit(0); | 
|---|
|  | 96 | } | 
|---|
|  | 97 |  | 
|---|
|  | 98 | int rc = 0; | 
|---|
|  | 99 | bool cont = true; | 
|---|
|  | 100 | char ans[32],rep; | 
|---|
|  | 101 | int excnt = 0; | 
|---|
|  | 102 | while(cont) { | 
|---|
|  | 103 | rc = 0;   cont = false; | 
|---|
|  | 104 | app->SetReady(); | 
|---|
|  | 105 | if (fgred) app->RedirectStdOutErr(true); | 
|---|
|  | 106 | try { | 
|---|
|  | 107 | app->Run(); | 
|---|
|  | 108 | } | 
|---|
|  | 109 | catch(PThrowable exc) {  // Catching SOPHYA exceptions | 
|---|
|  | 110 | app->Stop(); | 
|---|
|  | 111 | app->RedirectStdOutErr(false); | 
|---|
|  | 112 | //BUG ? fait planter OSF-cxx     fflush(stdout); | 
|---|
|  | 113 | cout << endl;      cerr << endl; | 
|---|
|  | 114 | cout << "\n piapp/main() PThrowable catched ! " << exc.Msg() << endl; | 
|---|
|  | 115 | cout << ++excnt << "- continue <CR>, Close Windows, " | 
|---|
|  | 116 | << " continue C<CR> Stop program S<CR> ? " << endl; | 
|---|
|  | 117 | gets(ans); | 
|---|
|  | 118 | rep = toupper(ans[0]); | 
|---|
|  | 119 | if (rep == 'S')  { | 
|---|
|  | 120 | cout << " !!!! Stopping piapp !!!! " << endl; | 
|---|
|  | 121 | rc = 78; | 
|---|
|  | 122 | cont = false; | 
|---|
|  | 123 | } | 
|---|
|  | 124 | else { | 
|---|
|  | 125 | if (rep == 'C') { | 
|---|
|  | 126 | cout << "piapp/main() Closing all windows ... " << endl; | 
|---|
|  | 127 | app->CloseAllWindows(); | 
|---|
|  | 128 | } | 
|---|
|  | 129 | cout << " *** piapp - Continuing event loop *** " << endl; | 
|---|
|  | 130 | cont = true; | 
|---|
|  | 131 | } | 
|---|
|  | 132 | } | 
|---|
|  | 133 | catch(...) { // Catching all other exceptions | 
|---|
|  | 134 | app->Stop(); | 
|---|
|  | 135 | app->RedirectStdOutErr(false); | 
|---|
|  | 136 | cout << endl;      cerr << endl; | 
|---|
|  | 137 | cout << "\n piapp/main() exception catched ! " << endl; | 
|---|
|  | 138 | cout << ++excnt << "- continue <CR>, Close Windows, " | 
|---|
|  | 139 | << " continue C<CR> Stop program S<CR> ? " << endl; | 
|---|
|  | 140 | gets(ans); | 
|---|
|  | 141 | rep = toupper(ans[0]); | 
|---|
|  | 142 | if (rep == 'S')  { | 
|---|
|  | 143 | cout << " !!!! Stopping piapp !!!! " << endl; | 
|---|
|  | 144 | rc = 78; | 
|---|
|  | 145 | cont = false; | 
|---|
|  | 146 | } | 
|---|
|  | 147 | else { | 
|---|
|  | 148 | if (rep == 'C') { | 
|---|
|  | 149 | cout << "piapp/main() Closing all windows ... " << endl; | 
|---|
|  | 150 | app->CloseAllWindows(); | 
|---|
|  | 151 | } | 
|---|
|  | 152 | cout << " *** piapp - Continuing event loop *** " << endl; | 
|---|
|  | 153 | cont = true; | 
|---|
|  | 154 | } | 
|---|
|  | 155 | } | 
|---|
|  | 156 | } | 
|---|
|  | 157 |  | 
|---|
|  | 158 | app->RedirectStdOutErr(false); | 
|---|
|  | 159 | // On de-charge le module sopiamodule | 
|---|
|  | 160 | sopiamodule_end(); | 
|---|
|  | 161 | delete app; | 
|---|
|  | 162 |  | 
|---|
|  | 163 | cout << "\n------------------------------------------------ \n" | 
|---|
|  | 164 | << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n" | 
|---|
|  | 165 | << "------------------------------------------------ " << endl; | 
|---|
|  | 166 | return(rc); | 
|---|
|  | 167 | } | 
|---|
|  | 168 |  | 
|---|