1 | #include <stdlib.h>
|
---|
2 | #include <stdio.h>
|
---|
3 |
|
---|
4 | #include "pistdimgapp.h"
|
---|
5 | #include "piacmd.h"
|
---|
6 | #include "piversion.h"
|
---|
7 | #include "piaversion.h"
|
---|
8 |
|
---|
9 | #include "timing.h"
|
---|
10 | #include "outilsinit.h"
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 | /* ================================ MAIN() ================================= */
|
---|
16 |
|
---|
17 | int main(int narg, char *arg[])
|
---|
18 | {
|
---|
19 | int ofa;
|
---|
20 | int fgfpe, fgsegv, fgred, fgexec;
|
---|
21 |
|
---|
22 | PeidaInit();
|
---|
23 |
|
---|
24 | InitTim();
|
---|
25 |
|
---|
26 | ofa = 1;
|
---|
27 | if (narg > 1)
|
---|
28 | {
|
---|
29 | if (strcmp(arg[1],"-h") == 0)
|
---|
30 | {
|
---|
31 | puts("\n piapp: Programme d'analyse interactive ");
|
---|
32 | puts("Usage: piapp [-nored] [-nosig] [-nosigfpe] [-nosigsegv] [-help2tex] [-exec file [args]]");
|
---|
33 | puts(" -nored : NoRedirect StdOut/StdErr");
|
---|
34 | puts(" -nosig : Don't catch SigFPE, SigSEGV");
|
---|
35 | puts(" -nosigfpe -nosigsegv: Don't catch SigFPE / SigSEGV");
|
---|
36 | puts(" -help2tex: Create a LaTeX help file (piahelp.tex)");
|
---|
37 | puts(" -exec file [args] : Execute command file \n");
|
---|
38 | exit(0);
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | ofa = 1;
|
---|
43 | fgred = fgfpe = fgsegv = true;
|
---|
44 | fgexec = false;
|
---|
45 | string exfc;
|
---|
46 | // Pour fabriquer le help
|
---|
47 | bool fgtexh = false;
|
---|
48 | int ka;
|
---|
49 | for(ka=1; ka<narg; ka++) {
|
---|
50 | if (strcmp(arg[ka],"-nored") == 0) fgred=false;
|
---|
51 | else if (strcmp(arg[ka],"-nosig") == 0) fgfpe=fgsegv=false;
|
---|
52 | else if (strcmp(arg[ka],"-nosigfpe") == 0) fgfpe=false;
|
---|
53 | else if (strcmp(arg[ka],"-nosigsegv") == 0) fgsegv=false;
|
---|
54 | else if (strcmp(arg[ka],"-help2tex") == 0) { fgtexh=true; fgred=false; }
|
---|
55 | else if (strcmp(arg[ka],"-exec") == 0) {
|
---|
56 | if (ka < narg-1) {
|
---|
57 | fgexec = true;
|
---|
58 | exfc = "exec";
|
---|
59 | for(int kaa=ka+1; kaa<narg; kaa++) { exfc += ' '; exfc += arg[kaa]; }
|
---|
60 | }
|
---|
61 | break;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
|
---|
66 | else printf(">>>>> Starting piapp <<<<< \n");
|
---|
67 | printf("Version: piapp=%g PI=%g PEIDA=%g \n", (double)PIAPP_VERSIONNUMBER,
|
---|
68 | (double)PI_VERSIONNUMBER, (float)PeidaVersion());
|
---|
69 |
|
---|
70 | PIStdImgApp * app = new PIStdImgApp(narg, arg);
|
---|
71 |
|
---|
72 | // Gestion de redirection stdout/err et Signaux
|
---|
73 | if (fgred) app->RedirectStdOutErr(true);
|
---|
74 | else app->RedirectStdOutErr(false);
|
---|
75 | app->CatchSignals(fgfpe, fgsegv);
|
---|
76 |
|
---|
77 | // S'il y a un fichier de commande a executer
|
---|
78 | if (fgexec) app->CmdInterpreter()->Interpret(exfc);
|
---|
79 |
|
---|
80 | // S'il y a besoin de faire le fichier Help
|
---|
81 | if (fgtexh) {
|
---|
82 | string thf = "piahelp.tex";
|
---|
83 | app->CmdInterpreter()->HelptoLaTex(thf);
|
---|
84 | printf("piapp : Help file piahelp.tex created --> exit(0) \n");
|
---|
85 | delete app;
|
---|
86 | exit(0);
|
---|
87 | }
|
---|
88 |
|
---|
89 | int rc = 0;
|
---|
90 | bool cont = true;
|
---|
91 | while(cont) {
|
---|
92 | rc = 0; cont = false;
|
---|
93 | app->SetReady();
|
---|
94 | if (fgred) app->RedirectStdOutErr(true);
|
---|
95 | try {
|
---|
96 | app->Run();
|
---|
97 | } catch ( PException exc ) {
|
---|
98 | char ans[32],rep;
|
---|
99 | app->Stop();
|
---|
100 | app->RedirectStdOutErr(false);
|
---|
101 | fflush(stdout);
|
---|
102 | cout << endl;
|
---|
103 | cerr << endl;
|
---|
104 | cerr << "PIStdImg/main() Exception catched ! " << exc.Msg() << endl;
|
---|
105 | cerr << " continue <CR> , Stop program S<CR> ? " << endl; gets(ans);
|
---|
106 | rc = 9;
|
---|
107 | rep = toupper(ans[0]);
|
---|
108 | if (rep == 'S') {
|
---|
109 | printf(" !!!! Stopping piapp !!!! \n");
|
---|
110 | cont = false;
|
---|
111 | }
|
---|
112 | else {
|
---|
113 | printf(" *** piapp - Continuing event loop *** \n");
|
---|
114 | cont = true;
|
---|
115 | }
|
---|
116 | // else { cont = true; if (rep == 'K') app->CloseAllWindows(); }
|
---|
117 | } ENDTRY;
|
---|
118 | }
|
---|
119 |
|
---|
120 | app->RedirectStdOutErr(false);
|
---|
121 | // On de-charge le module erospiamodule
|
---|
122 | delete app;
|
---|
123 |
|
---|
124 | printf("piapp : Exiting .... Rc= %d \n", rc);
|
---|
125 | exit(rc);
|
---|
126 | }
|
---|
127 |
|
---|