source: Sophya/trunk/SophyaPI/ProgPI/piapp.cc@ 776

Last change on this file since 776 was 722, checked in by ansari, 26 years ago

Creation module ProgPI pour piapp/SOPHYA Reza 6/2/2000

File size: 4.5 KB
Line 
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
15extern "C" {
16void sopiamodule_init();
17void sopiamodule_end();
18}
19
20
21/* ================================ MAIN() ================================= */
22
23int main(int narg, char *arg[])
24{
25int ofa;
26int fgfpe, fgsegv, fgred, fgexec;
27
28SkyTInitiator skyinit;
29
30InitTim();
31
32ofa = 1;
33if (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
48ofa = 1;
49fgred = fgfpe = fgsegv = true;
50fgexec = false;
51string exfc;
52// Pour fabriquer le help
53bool fgtexh = false;
54int ka;
55for(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
71if (fgexec) printf(">>>>> Starting piapp , Executing %s \n", exfc.c_str());
72else printf(">>>>> Starting piapp <<<<< \n");
73printf("Version: piapp=%g PI=%g SOPHYA=%g \n", (double)PIAPP_VERSIONNUMBER,
74 (double)PI_VERSIONNUMBER, (double)skyinit.Version());
75
76PIStdImgApp * app = new PIStdImgApp(narg, arg);
77
78// Gestion de redirection stdout/err et Signaux
79if (fgred) app->RedirectStdOutErr(true);
80else app->RedirectStdOutErr(false);
81app->CatchSignals(fgfpe, fgsegv);
82
83// S'il y a un fichier de commande a executer
84if (fgexec) app->CmdInterpreter()->Interpret(exfc);
85
86// On charge le module sopiamodule
87sopiamodule_init();
88
89// S'il y a besoin de faire le fichier Help
90if (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
98int rc = 0;
99bool cont = true;
100char ans[32],rep;
101int excnt = 0;
102while(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
158app->RedirectStdOutErr(false);
159// On de-charge le module sopiamodule
160sopiamodule_end();
161delete app;
162
163cout << "\n------------------------------------------------ \n"
164 << "-------- piapp : Exiting .... Rc= " << rc << " -----------\n"
165 << "------------------------------------------------ " << endl;
166return(rc);
167}
168
Note: See TracBrowser for help on using the repository browser.