[4077] | 1 | #ifndef __PIWQUARTZ__
|
---|
| 2 | #ifndef __MWERKS__
|
---|
| 3 |
|
---|
[2] | 4 | #include <stdio.h>
|
---|
[18] | 5 | #include <X11/cursorfont.h>
|
---|
[1074] | 6 | #include <X11/IntrinsicP.h>
|
---|
[1263] | 7 | #include <X11/Shell.h>
|
---|
| 8 | #include <X11/StringDefs.h>
|
---|
| 9 | #include <Xm/Xm.h>
|
---|
[2615] | 10 | #include "sopnamsp.h"
|
---|
[2] | 11 | #include "piapplx.h"
|
---|
| 12 | #include "picontainerx.h"
|
---|
[3475] | 13 | #include "picons.h"
|
---|
[2] | 14 |
|
---|
[365] | 15 | // $CHECK$ - Reza Aout 99
|
---|
| 16 | // Il y a un probleme sur la gestion de la taille de la fenetre principale
|
---|
| 17 | // SetBinding(elastic) ne marche correctement pas sur la fenetre principale
|
---|
| 18 | // et Des SetSize intempestive peuvent generer des comportements bizarres !
|
---|
[2] | 19 |
|
---|
[78] | 20 | // Pour rediriger stdout
|
---|
| 21 | #include <unistd.h>
|
---|
| 22 | #include <fcntl.h>
|
---|
[3369] | 23 | #include <sys/types.h>
|
---|
| 24 | #include <sys/stat.h>
|
---|
[2] | 25 |
|
---|
[2322] | 26 | #include <iostream>
|
---|
[78] | 27 |
|
---|
[135] | 28 |
|
---|
[78] | 29 | // #define DEBUG_APPLX
|
---|
| 30 |
|
---|
[18] | 31 | static Cursor a_curs[3];
|
---|
| 32 | static bool a_fgcur=false;
|
---|
| 33 |
|
---|
[60] | 34 | // Voir fichier pimenux.cc , Pour resoudre certains conflits avec les WindowManagers
|
---|
| 35 | void SetTopWdgForMenuX(SysDWdg mtw);
|
---|
| 36 |
|
---|
[111] | 37 | static PIApplication* cur_piapp = NULL;
|
---|
| 38 | PIApplication* PIApplicationGetApp() { return cur_piapp; }
|
---|
| 39 |
|
---|
[126] | 40 |
|
---|
[132] | 41 | // Classe de container special pour top-container de Application X
|
---|
[126] | 42 |
|
---|
[132] | 43 | class PITopContAppX : public PIContainer {
|
---|
| 44 | public :
|
---|
[4083] | 45 | PITopContAppX(PIContainer *par, const char *nom, PIWdg* topw,
|
---|
[132] | 46 | int sx=10, int sy=10, int px=0, int py=0);
|
---|
| 47 | virtual ~PITopContAppX();
|
---|
| 48 |
|
---|
| 49 | virtual void SetSize(int sx, int sy);
|
---|
| 50 | virtual void SetPos(int px, int py);
|
---|
[457] | 51 |
|
---|
| 52 | PIWdg* mTopWdg;
|
---|
[132] | 53 | };
|
---|
| 54 |
|
---|
[1074] | 55 |
|
---|
[2] | 56 | /* --Methode-- */
|
---|
[4083] | 57 | PITopContAppX::PITopContAppX(PIContainer *par, const char *nom, PIWdg* topw, int sx, int sy, int px, int py)
|
---|
[365] | 58 | : PIContainer(par, nom, (sx>10)?sx:10, (sy>10)?sy:10, px, py)
|
---|
[132] | 59 | {
|
---|
[457] | 60 | mTopWdg = topw;
|
---|
[365] | 61 | SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_fixed);
|
---|
[132] | 62 | }
|
---|
| 63 |
|
---|
| 64 | /* --Methode-- */
|
---|
| 65 | PITopContAppX::~PITopContAppX()
|
---|
| 66 | {
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /* --Methode-- */
|
---|
| 70 | void PITopContAppX::SetSize(int sx, int sy)
|
---|
| 71 | {
|
---|
[365] | 72 | if ((sx <10) || (sy < 10) ) return;
|
---|
[1074] | 73 |
|
---|
| 74 | int px = XPos();
|
---|
| 75 | int py = YPos();
|
---|
[1133] | 76 | // Probleme sur Sun - Reza 10/99 , REGLE 08/2000
|
---|
| 77 |
|
---|
[1074] | 78 | mTopWdg->SetSize(sx+px, sy+py);
|
---|
| 79 |
|
---|
| 80 | XtConfigureWidget(Parent()->XtWdg(), 0, 0, sx+px, sy+py, 0);
|
---|
| 81 | XtConfigureWidget(XtWdg(), px, py, sx, sy, 0);
|
---|
| 82 | // SetPos(px, py);
|
---|
| 83 | // PIContainer::SetSize(sx, sy);
|
---|
[132] | 84 | }
|
---|
| 85 |
|
---|
[365] | 86 |
|
---|
[132] | 87 | /* --Methode-- */
|
---|
| 88 | void PITopContAppX::SetPos(int px, int py)
|
---|
| 89 | {
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[1263] | 92 | // ---------------------------------------------
|
---|
| 93 | // Fonction pour gestion des close-window
|
---|
| 94 |
|
---|
| 95 | /* Nouvelle-Fonction */
|
---|
| 96 | static int fgactl = 0;
|
---|
| 97 |
|
---|
| 98 | static void CloseWindow (Widget w, XEvent*, String*,Cardinal*)
|
---|
| 99 | {
|
---|
| 100 | XtCallCallbacks(w, XtNpopdownCallback, NULL);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | /* Nouvelle-Fonction */
|
---|
| 104 | static void popdwn_cb_app(Widget /*w*/, XtPointer *usd, XtPointer * )
|
---|
| 105 | {
|
---|
| 106 | PIApplicationX * app = (PIApplicationX *) usd;
|
---|
| 107 | app->SendSelf(0,PIMsg_Close, NULL) ;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
[132] | 111 | /* --Methode-- */
|
---|
[2] | 112 | PIApplicationX::PIApplicationX(int sx, int sy, int narg, char *arg[])
|
---|
| 113 | : PIApplicationGen()
|
---|
| 114 | {
|
---|
| 115 | int sxt, syt;
|
---|
| 116 |
|
---|
| 117 | #ifdef DEBUG_APPLX
|
---|
| 118 | puts("PIApplicationX::PIApplicationX()_info : App creation");
|
---|
| 119 | #endif
|
---|
| 120 | mStop = true;
|
---|
[365] | 121 |
|
---|
| 122 |
|
---|
[2] | 123 | topwdg = new PIWdgX(narg, arg);
|
---|
| 124 |
|
---|
[365] | 125 | int msx,msy;
|
---|
[1592] | 126 | PrefCompSize(msx, msy);
|
---|
[365] | 127 | msy+=5;
|
---|
| 128 | topwdg->SetSize(sx, sy+msy);
|
---|
[4086] | 129 | printf("PIApplicationX-DBG:: Size=%d %d \n", topwdg->XSize(), topwdg->YSize());
|
---|
[365] | 130 |
|
---|
[2] | 131 | intcont = new PIContainerX((PIMsgHandler *)this, topwdg, "MBCont",
|
---|
[365] | 132 | sx, sy+msy, 0, 0);
|
---|
[60] | 133 | // Pb avec les Popup MenuX et certains Window Manager , voir pimenux.cc
|
---|
| 134 | SetTopWdgForMenuX(intcont->XtWdg());
|
---|
| 135 |
|
---|
[2] | 136 | menubar = new PIMenubar(this, "DefMenubar");
|
---|
[23] | 137 | Menubar()->SetBinding(PIBK_fixed, PIBK_fixed, PIBK_fixed, PIBK_free);
|
---|
[2] | 138 | sxt = ( sx > Menubar()->XSize() ) ? sx : Menubar()->XSize();
|
---|
[365] | 139 | syt = ( sy > 10 ) ? sy : 10;
|
---|
| 140 | // syt += Menubar()->YSize();
|
---|
| 141 | // syt += msy;
|
---|
| 142 | // topwdg->SetSize(sxt, syt);
|
---|
| 143 | // MBCont()->SetSize(sxt, syt);
|
---|
[132] | 144 | if (sx < sxt) sx = sxt;
|
---|
| 145 | if (sy < 10) sy = 10;
|
---|
[4083] | 146 | topcont = new PITopContAppX(MBCont(), "TopLevelCont", topwdg,sx, sy, 0, msy);
|
---|
[163] | 147 | MBCont()->Show();
|
---|
[3216] | 148 | //DBG printf("PIApplicationX-DBG2:: MBContSize=%d %d \n", MBCont()->XSize(), MBCont()->YSize());
|
---|
[2] | 149 |
|
---|
[1074] | 150 |
|
---|
[365] | 151 | topcont->Show();
|
---|
[18] | 152 |
|
---|
[365] | 153 |
|
---|
[18] | 154 | if (!a_fgcur)
|
---|
| 155 | {
|
---|
| 156 | Display *mdsp;
|
---|
| 157 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 158 | a_curs[0] = XCreateFontCursor(mdsp, XC_arrow);
|
---|
| 159 | a_curs[1] = XCreateFontCursor(mdsp, XC_X_cursor);
|
---|
| 160 | a_curs[2] = XCreateFontCursor(mdsp, XC_watch);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[365] | 163 | topwdg->Manage();
|
---|
[1263] | 164 |
|
---|
| 165 | // ------------------------------------------------------
|
---|
| 166 | // Pour la gestion des close window des Window manager
|
---|
| 167 |
|
---|
| 168 | if (fgactl == 0) {
|
---|
| 169 | XtActionsRec desact = {(char *)"CloseWindow" ,CloseWindow};
|
---|
| 170 | int szx, szy, szf;
|
---|
| 171 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
| 172 | XtAppAddActions(*appctx, &desact, 1);
|
---|
| 173 | Display *mdsp;
|
---|
| 174 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
| 175 | Atom wmd;
|
---|
| 176 | wmd = XInternAtom(mdsp, "WM_DELETE_WINDOW",False);
|
---|
| 177 | XSetWMProtocols(mdsp, XtWindow(topwdg->XtWdg()), &wmd, 1);
|
---|
| 178 | fgactl = 1;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | XtTranslations trans;
|
---|
| 182 | trans = XtParseTranslationTable("<Message>WM_PROTOCOLS:CloseWindow()");
|
---|
| 183 | XtOverrideTranslations(topwdg->XtWdg() , trans);
|
---|
| 184 | Arg warg[2];
|
---|
| 185 | XtSetArg(warg[0], XmNdeleteResponse, XmDO_NOTHING);
|
---|
| 186 | XtSetValues(topwdg->XtWdg(), warg, 1);
|
---|
| 187 |
|
---|
| 188 | XtAddCallback(topwdg->XtWdg(), XtNpopdownCallback,
|
---|
| 189 | (XtCallbackProc)popdwn_cb_app, (XtPointer)this);
|
---|
| 190 |
|
---|
| 191 | // ------------------------------------------------------
|
---|
| 192 |
|
---|
[111] | 193 | cur_piapp = this;
|
---|
[18] | 194 | mState = -1;
|
---|
| 195 | SetReady();
|
---|
[2] | 196 | }
|
---|
| 197 |
|
---|
| 198 | /* --Methode-- */
|
---|
| 199 | PIApplicationX::~PIApplicationX()
|
---|
| 200 | {
|
---|
| 201 | #ifdef DEBUG_APPLX
|
---|
| 202 | puts("PIApplicationX::~PIApplicationX()_info : App delete");
|
---|
| 203 | #endif
|
---|
[18] | 204 | Display *mdsp;
|
---|
| 205 | mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[52] | 206 | topwdg->UnManage();
|
---|
[6] | 207 | delete menubar;
|
---|
| 208 | if (topcont != MBCont()) delete topcont;
|
---|
| 209 | delete intcont;
|
---|
[2] | 210 | delete topwdg;
|
---|
[18] | 211 | XtCloseDisplay(mdsp);
|
---|
[111] | 212 | cur_piapp = NULL;
|
---|
[18] | 213 | return;
|
---|
[2] | 214 | }
|
---|
| 215 |
|
---|
| 216 | /* --Methode-- */
|
---|
| 217 | void PIApplicationX::Run()
|
---|
| 218 | {
|
---|
| 219 | XEvent evt;
|
---|
| 220 | #ifdef DEBUG_APPLX
|
---|
| 221 | puts("PIApplicationX::Run()_info : App Run ");
|
---|
| 222 | #endif
|
---|
| 223 |
|
---|
| 224 |
|
---|
[114] | 225 | int szx, szy, szf;
|
---|
| 226 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[90] | 227 |
|
---|
[110] | 228 | // Pour appeler FinishCreate() des objets dans la fenetre principale
|
---|
[365] | 229 | if (mStop) { // C'est la premiere fois
|
---|
[1074] | 230 | topcont->SetSize(topcont->XSize(), topcont->YSize());
|
---|
| 231 | // topwdg->SetSize(MBCont()->XSize(), MBCont()->YSize());
|
---|
[365] | 232 | MBCont()->FinishCreate();
|
---|
| 233 | }
|
---|
[141] | 234 | else mStop = true; // On rerentre apres un stop
|
---|
[2] | 235 | while (mStop)
|
---|
| 236 | {
|
---|
[90] | 237 | XtAppNextEvent(*appctx, &evt);
|
---|
[2] | 238 | XtDispatchEvent(&evt);
|
---|
| 239 | }
|
---|
| 240 | return;
|
---|
| 241 | }
|
---|
[18] | 242 |
|
---|
| 243 |
|
---|
| 244 | /* --Methode-- */
|
---|
| 245 | void PIApplicationX::SetReady()
|
---|
| 246 | {
|
---|
[138] | 247 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 248 | if (mState != kReadyState)
|
---|
| 249 | {
|
---|
| 250 | mState = kReadyState;
|
---|
[106] | 251 | Menubar()->SetSensitive();
|
---|
[18] | 252 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[0]);
|
---|
| 253 | }
|
---|
[138] | 254 | XFlush(mdsp);
|
---|
[18] | 255 | }
|
---|
| 256 |
|
---|
| 257 | /* --Methode-- */
|
---|
| 258 | void PIApplicationX::SetBusy()
|
---|
| 259 | {
|
---|
[138] | 260 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 261 | if (mState != kBusyState)
|
---|
| 262 | {
|
---|
| 263 | mState = kBusyState;
|
---|
[106] | 264 | Menubar()->SetSensitive();
|
---|
[18] | 265 | // if ( XtIsRealized(topwdg->XtWdg()) )
|
---|
| 266 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[2]);
|
---|
| 267 | }
|
---|
[138] | 268 | XFlush(mdsp);
|
---|
[18] | 269 | }
|
---|
| 270 |
|
---|
| 271 | /* --Methode-- */
|
---|
| 272 | void PIApplicationX::SetBlocked()
|
---|
| 273 | {
|
---|
[138] | 274 | Display * mdsp = XtDisplay (topwdg->XtWdg());
|
---|
[18] | 275 | if (mState != kBlockedState)
|
---|
| 276 | {
|
---|
| 277 | mState = kBlockedState;
|
---|
[106] | 278 | Menubar()->SetUnSensitive();
|
---|
[18] | 279 | XDefineCursor(mdsp, XtWindow(topwdg->XtWdg()), a_curs[1]);
|
---|
| 280 | }
|
---|
[138] | 281 | XFlush(mdsp);
|
---|
| 282 | return;
|
---|
[18] | 283 | }
|
---|
[75] | 284 |
|
---|
| 285 |
|
---|
| 286 | /* --Methode-- */
|
---|
[1592] | 287 | void PIApplicationX::PrefCompSize(int& szx, int& szy)
|
---|
[75] | 288 | {
|
---|
[114] | 289 | int szf;
|
---|
[4083] | 290 | printf("XtAppContext* PIXtAppCtx :szx=%d szy=%d szf=%d\n",szx,szy,szf);
|
---|
[114] | 291 | PIXtAppCtx(szx, szy, szf);
|
---|
[4083] | 292 | printf("XtAppContext* PIXtAppCtx :szx=%d szy=%d szf=%d\n",szx,szy,szf);
|
---|
[90] | 293 | return;
|
---|
[75] | 294 | }
|
---|
| 295 |
|
---|
[92] | 296 | /* --Methode-- */
|
---|
[1592] | 297 | void PIApplicationX::ScreenSize(int& szx, int& szy)
|
---|
[92] | 298 | {
|
---|
| 299 | Display * dsp = PIXDisplay();
|
---|
| 300 | szx = DisplayWidth(dsp, DefaultScreen(dsp));
|
---|
| 301 | szy = DisplayHeight(dsp, DefaultScreen(dsp));
|
---|
| 302 | }
|
---|
[75] | 303 |
|
---|
[1592] | 304 | /* --Methode-- */
|
---|
| 305 | void PIApplicationX::ScreenSizeMM(int& szx, int& szy)
|
---|
| 306 | {
|
---|
| 307 | Display * dsp = PIXDisplay();
|
---|
| 308 | szx = DisplayWidthMM(dsp, DefaultScreen(dsp));
|
---|
| 309 | szy = DisplayHeightMM(dsp, DefaultScreen(dsp));
|
---|
| 310 | }
|
---|
[92] | 311 |
|
---|
[1592] | 312 | /* --Methode-- */
|
---|
| 313 | void PIApplicationX::ScreenResolution(int& resolx, int& resoly)
|
---|
| 314 | {
|
---|
| 315 | Display * dsp = PIXDisplay();
|
---|
| 316 | resolx = (int)((double)DisplayWidth(dsp, DefaultScreen(dsp))*10./
|
---|
| 317 | (double)DisplayWidthMM(dsp, DefaultScreen(dsp)));
|
---|
| 318 | resoly = (int)((double)DisplayHeight(dsp, DefaultScreen(dsp))*10./
|
---|
| 319 | (double)DisplayHeightMM(dsp, DefaultScreen(dsp)));
|
---|
| 320 | }
|
---|
[92] | 321 |
|
---|
[1592] | 322 |
|
---|
| 323 |
|
---|
| 324 |
|
---|
| 325 |
|
---|
[78] | 326 | /* Call-Back - Fonction privee de ce fichier */
|
---|
[81] | 327 | static void redirectstream_callback(XtPointer, int *, XtInputId*);
|
---|
[78] | 328 |
|
---|
[81] | 329 | static PIConsole* consstream[2] = {NULL, NULL};
|
---|
| 330 | static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
|
---|
| 331 | static int streamno[2] = {0,1};
|
---|
[135] | 332 | static XtInputId inputid[2];
|
---|
| 333 | static int origfiledes[2]={-1, -1}; // descripteurs de fichiers de depart
|
---|
[3369] | 334 | static bool fgcopieos[2]={false, false}; // Si true, recopie sur descripteurs de depart, en plus de redirection
|
---|
| 335 | static int readfiledes[2]={-1, -1}; // descripteurs de fichiers ouvert en lecture , si redirection a travers fichier
|
---|
| 336 | static XtIntervalId intervid[2];
|
---|
| 337 | static unsigned long tm_interv = 40; // intervalle timer = 40 ms
|
---|
[78] | 338 |
|
---|
[3369] | 339 | //DBG static FILE * dbgfip = NULL;
|
---|
| 340 |
|
---|
| 341 | // call-back pour gestion de redirection stdout/stderr avec pipe
|
---|
[81] | 342 | static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
|
---|
[78] | 343 | {
|
---|
[2607] | 344 | char buff[512];
|
---|
[3369] | 345 | int nr, tnr;
|
---|
[81] | 346 |
|
---|
| 347 | int idx = *((int*)cld);
|
---|
| 348 | if (idx != 1) idx = 0;
|
---|
[135] | 349 | if (!consstream[idx]) return;
|
---|
[3369] | 350 | tnr = 0;
|
---|
| 351 | while ( (nr=read(*fd, buff, 511)) > 0 ) {
|
---|
[81] | 352 | buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
|
---|
[3369] | 353 | tnr += nr;
|
---|
[78] | 354 | }
|
---|
[3369] | 355 | if (tnr > 0) consstream[idx]->Refresh();
|
---|
[78] | 356 | }
|
---|
| 357 |
|
---|
[3369] | 358 | // call-back pour gestion de redirection stdout/stderr avec pipe
|
---|
| 359 | static void redirectstream_timeout_callback(XtPointer cld, XtIntervalId * /*tid*/)
|
---|
| 360 | {
|
---|
| 361 | char buff[512];
|
---|
| 362 | int nr, tnr;
|
---|
| 363 |
|
---|
| 364 | int idx = *((int*)cld);
|
---|
| 365 | if (idx != 1) idx = 0;
|
---|
| 366 | if (!consstream[idx]) return;
|
---|
| 367 | tnr = 0;
|
---|
| 368 | while ( (nr=read(readfiledes[idx], buff, 511)) > 0 ) {
|
---|
| 369 | buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
|
---|
| 370 | tnr += nr;
|
---|
| 371 | if (fgcopieos[idx]) write(origfiledes[idx], buff, nr); // recopie sur filedesc original
|
---|
| 372 | }
|
---|
| 373 | if (tnr > 0) consstream[idx]->Refresh();
|
---|
| 374 | int szx, szy, szf;
|
---|
| 375 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
| 376 | intervid[idx] = XtAppAddTimeOut(*appctx, tm_interv, redirectstream_timeout_callback, (XtPointer)(streamno+idx));
|
---|
| 377 | }
|
---|
| 378 |
|
---|
[78] | 379 | /* --Methode-- */
|
---|
[81] | 380 | void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
|
---|
[78] | 381 | {
|
---|
[3369] | 382 | if ( origfiledes[0]<0 ) origfiledes[0] = fcntl(1, F_DUPFD, 0);
|
---|
| 383 | if ( cons == consstream[0]) {
|
---|
| 384 | streamva[0] = va;
|
---|
| 385 | return;
|
---|
| 386 | }
|
---|
[135] | 387 | if ( (consstream[0]) && (cons) ) { consstream[0] = cons; streamva[0] = va; return; }
|
---|
| 388 | else if (!cons) {
|
---|
| 389 | consstream[0] = NULL;
|
---|
| 390 | XtRemoveInput(inputid[0]);
|
---|
| 391 | dup2(origfiledes[0], 1);
|
---|
| 392 | return;
|
---|
| 393 | }
|
---|
[78] | 394 |
|
---|
[81] | 395 | consstream[0] = cons; streamva[0] = va;
|
---|
| 396 |
|
---|
[78] | 397 | int p[2];
|
---|
| 398 | pipe(p);
|
---|
[90] | 399 | // Redirection de stdout (fid=1) :
|
---|
[78] | 400 | close(1);
|
---|
| 401 | dup(p[1]);
|
---|
| 402 | close(p[1]);
|
---|
| 403 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[135] | 404 |
|
---|
[365] | 405 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
[85] | 406 | setlinebuf(stdout);
|
---|
[163] | 407 | #endif
|
---|
[135] | 408 | ios::sync_with_stdio();
|
---|
[78] | 409 |
|
---|
[114] | 410 | int szx, szy, szf;
|
---|
| 411 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[135] | 412 | inputid[0] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
|
---|
| 413 | redirectstream_callback, (XtPointer) streamno);
|
---|
[3369] | 414 | //DBG if (dbgfip == NULL) dbgfip = fopen("debug.log","w");
|
---|
[78] | 415 | }
|
---|
[81] | 416 |
|
---|
| 417 | /* --Methode-- */
|
---|
| 418 | void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
|
---|
| 419 | {
|
---|
[3369] | 420 | if ( origfiledes[1]<0 ) origfiledes[1] = fcntl(2, F_DUPFD, 0);
|
---|
| 421 | if ( cons == consstream[1]) {
|
---|
| 422 | streamva[1] = va;
|
---|
| 423 | return;
|
---|
| 424 | }
|
---|
[135] | 425 | if ( (consstream[1]) && (cons) ) { consstream[1] = cons; streamva[1] = va; return; }
|
---|
| 426 | else if (!cons) {
|
---|
| 427 | consstream[1] = NULL;
|
---|
| 428 | XtRemoveInput(inputid[1]);
|
---|
| 429 | dup2(origfiledes[1], 2);
|
---|
| 430 | return;
|
---|
| 431 | }
|
---|
[81] | 432 |
|
---|
| 433 | consstream[1] = cons; streamva[1] = va;
|
---|
| 434 |
|
---|
| 435 | int p[2];
|
---|
| 436 | pipe(p);
|
---|
[135] | 437 | // Redirection de stderr (fid=2) :
|
---|
[81] | 438 | close(2);
|
---|
| 439 | dup(p[1]);
|
---|
| 440 | close(p[1]);
|
---|
| 441 | fcntl(p[0], F_SETFL, O_NONBLOCK);
|
---|
[135] | 442 |
|
---|
[365] | 443 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
[85] | 444 | setlinebuf(stderr);
|
---|
[163] | 445 | #endif
|
---|
[135] | 446 | ios::sync_with_stdio();
|
---|
[81] | 447 |
|
---|
[114] | 448 | int szx, szy, szf;
|
---|
| 449 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
[135] | 450 | inputid[1] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
|
---|
| 451 | redirectstream_callback, (XtPointer) (streamno+1));
|
---|
[81] | 452 | }
|
---|
| 453 |
|
---|
[3369] | 454 | /* --Methode-- */
|
---|
| 455 | void PIApplicationX::RedirectOutStream(PIConsole* cons, string const & flnm, bool fgcpos, unsigned char va)
|
---|
| 456 | {
|
---|
| 457 | if (origfiledes[0] < 0) {
|
---|
| 458 | origfiledes[0] = dup(1);
|
---|
| 459 | if (origfiledes[0] < 0) { perror("RedirectOutStream()/ERROR ofd[0]<0 "); return; }
|
---|
| 460 | }
|
---|
| 461 | if (readfiledes[0] > -1) { close(readfiledes[0]); readfiledes[0] = -1;}
|
---|
| 462 | if (!cons) { // requete d'annulation de redirection
|
---|
| 463 | if (origfiledes[0] > -1) dup2(origfiledes[0], 1);
|
---|
| 464 | XtRemoveTimeOut(intervid[0]);
|
---|
| 465 | consstream[0] = NULL;
|
---|
| 466 | return;
|
---|
| 467 | }
|
---|
| 468 |
|
---|
| 469 | int fidso = open(flnm.c_str(), O_CREAT|O_WRONLY|O_NONBLOCK, S_IRUSR|S_IWUSR);
|
---|
| 470 | if (fidso < 0) {
|
---|
| 471 | printf("PIApplicationX::RedirectOutStream()/ERROR creating file %s \n", flnm.c_str());
|
---|
| 472 | return;
|
---|
| 473 | }
|
---|
| 474 | int rdfid = open(flnm.c_str(), O_RDONLY|O_NONBLOCK, 0);
|
---|
| 475 | if (rdfid < 0) {
|
---|
| 476 | printf("PIApplicationX::RedirectOutStream()/ERROR opening file %s for read \n", flnm.c_str());
|
---|
| 477 | return;
|
---|
| 478 | }
|
---|
| 479 | readfiledes[0] = rdfid;
|
---|
| 480 | dup2(fidso, 1); // close(1=stdout), recopie fidso en fd=1
|
---|
| 481 | close(fidso); // on ferme le fidso (on l'a recopie en fd=1)
|
---|
| 482 | consstream[0] = cons; streamva[0] = va; fgcopieos[0] = fgcpos;
|
---|
| 483 |
|
---|
| 484 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
| 485 | setlinebuf(stdout);
|
---|
| 486 | #endif
|
---|
| 487 | ios::sync_with_stdio();
|
---|
| 488 |
|
---|
| 489 | int szx, szy, szf;
|
---|
| 490 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
| 491 | intervid[0] = XtAppAddTimeOut(*appctx, tm_interv, redirectstream_timeout_callback,
|
---|
| 492 | (XtPointer)(streamno+0));
|
---|
| 493 |
|
---|
| 494 | //DBG if (dbgfip == NULL) dbgfip = fopen("debug.log","w");
|
---|
| 495 | }
|
---|
| 496 |
|
---|
| 497 | /* --Methode-- */
|
---|
| 498 | void PIApplicationX::RedirectErrStream(PIConsole* cons, string const & flnm, bool fgcpos, unsigned char va)
|
---|
| 499 | {
|
---|
| 500 | if (origfiledes[1] < 0) {
|
---|
| 501 | origfiledes[1] = dup(2);
|
---|
| 502 | if (origfiledes[1] < 0) { perror("RedirectOutStream()/ERROR ofd[1]<0 "); return; }
|
---|
| 503 | }
|
---|
| 504 | if (readfiledes[1] > -1) { close(readfiledes[1]); readfiledes[1] = -1;}
|
---|
| 505 | if (!cons) { // requete d'annulation de redirection
|
---|
[3372] | 506 | if (origfiledes[1] > -1) dup2(origfiledes[1], 2);
|
---|
[3369] | 507 | XtRemoveTimeOut(intervid[1]);
|
---|
| 508 | consstream[1] = NULL;
|
---|
| 509 | return;
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | int fidso = open(flnm.c_str(), O_CREAT|O_WRONLY|O_NONBLOCK, S_IRUSR|S_IWUSR);
|
---|
| 513 | if (fidso < 0) {
|
---|
| 514 | printf("PIApplicationX::RedirectOutStream()/ERROR creating file %s \n", flnm.c_str());
|
---|
| 515 | return;
|
---|
| 516 | }
|
---|
| 517 | int rdfid = open(flnm.c_str(), O_RDONLY|O_NONBLOCK, 0);
|
---|
| 518 | if (rdfid < 0) {
|
---|
| 519 | printf("PIApplicationX::RedirectOutStream()/ERROR opening file %s for read \n", flnm.c_str());
|
---|
| 520 | return;
|
---|
| 521 | }
|
---|
| 522 | readfiledes[1] = rdfid;
|
---|
| 523 | dup2(fidso, 2); // close(2=stderr), recopie fidso en fd=2
|
---|
| 524 | close(fidso); // on ferme le fidso (on l'a recopie en fd=2)
|
---|
| 525 | consstream[1] = cons; streamva[1] = va; fgcopieos[1] = fgcpos;
|
---|
| 526 |
|
---|
| 527 | #if (!defined(__GNUG__) && !defined(HPUX))
|
---|
| 528 | setlinebuf(stderr);
|
---|
| 529 | #endif
|
---|
| 530 | ios::sync_with_stdio();
|
---|
| 531 |
|
---|
| 532 | int szx, szy, szf;
|
---|
| 533 | XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
|
---|
| 534 | intervid[1] = XtAppAddTimeOut(*appctx, tm_interv, redirectstream_timeout_callback,
|
---|
| 535 | (XtPointer)(streamno+1));
|
---|
| 536 | }
|
---|
| 537 |
|
---|
[4077] | 538 | #endif
|
---|
| 539 | #endif
|
---|
| 540 |
|
---|