Changeset 135 in Sophya for trunk/SophyaPI


Ignore:
Timestamp:
Aug 14, 1998, 7:17:15 PM (27 years ago)
Author:
ercodmgr
Message:

Petits bugs + modir App::Redirect() 14/08/98 Reza

Location:
trunk/SophyaPI/PI
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PI/piapplgen.cc

    r110 r135  
    116116// void  RedirectOutStream(PIConsole* cons, unsigned char va= PIVA_Def)
    117117//      Redirige le flot de sortie ("stdout" sous Unix) vers l'objet
    118 //      PIConsole "cons". 
     118//      PIConsole "cons". si "cons==NULL", redirection
     119//      sur le flot original.
    119120//
    120121// void  RedirectErrStream(PIConsole* cons, unsigned char va= PIVA_Def)
    121122//      Redirige le flot des messages d'erreur ("stderr" sous Unix)
    122 //      vers l'objet PIConsole "cons". 
     123//      vers l'objet PIConsole "cons". si "cons==NULL", redirection
     124//       sur le flot original.
    123125//--
    124126
  • trunk/SophyaPI/PI/piapplx.cc

    r132 r135  
    88#include <unistd.h>
    99#include <fcntl.h>
     10
     11#include <iostream.h>
    1012
    1113
     
    218220static unsigned char streamva[2] = { PIVA_Def, PIVA_Ital};
    219221static int streamno[2] = {0,1};
     222static XtInputId inputid[2];
     223static int origfiledes[2]={-1, -1};   // descripteurs de fichiers de depart
     224static bool firstcall[2]={true, true};    // 1er appel a Redirect
    220225
    221226static void redirectstream_callback(XtPointer cld, int * fd, XtInputId* /*iid*/)
     
    226231int idx = *((int*)cld);
    227232if (idx != 1) idx = 0;
     233if (!consstream[idx]) return;
    228234while ( (nr=read(*fd, buff, 127)) > 0 ) {
    229235  buff[nr] = '\0'; consstream[idx]->AddStr(buff, streamva[idx], false);
     
    235241void PIApplicationX::RedirectOutStream(PIConsole* cons, unsigned char va)
    236242{
    237 if (!cons) return;
    238 
    239 if (consstream[0]) { consstream[0] = cons; streamva[0] = va; return; }
     243if ( origfiledes[0]<0 )  origfiledes[0] = fcntl(1, F_DUPFD);     
     244if ( cons == consstream[0]) return;
     245if ( (consstream[0]) && (cons) ) { consstream[0] = cons; streamva[0] = va; return; }
     246else if (!cons) {
     247  consstream[0] = NULL; 
     248  XtRemoveInput(inputid[0]);
     249  dup2(origfiledes[0], 1);
     250  return;
     251  }
     252
    240253consstream[0] = cons; streamva[0] = va;
    241254
     
    247260close(p[1]);
    248261fcntl(p[0], F_SETFL, O_NONBLOCK);
     262
    249263setlinebuf(stdout);
     264ios::sync_with_stdio();
    250265
    251266int szx, szy, szf;
    252267XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
    253 XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) streamno);
     268inputid[0] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
     269                           redirectstream_callback, (XtPointer) streamno);
    254270}
    255271
     
    257273void PIApplicationX::RedirectErrStream(PIConsole* cons, unsigned char va)
    258274{
    259 if (!cons) return;
    260 
    261 if (consstream[1]) { consstream[1] = cons; streamva[1] = va; return; }
     275if ( origfiledes[1]<0 )  origfiledes[1] = fcntl(2, F_DUPFD);     
     276if ( cons == consstream[1]) return;
     277if ( (consstream[1]) && (cons) ) { consstream[1] = cons; streamva[1] = va; return; }
     278else if (!cons) {
     279  consstream[1] = NULL; 
     280  XtRemoveInput(inputid[1]);
     281  dup2(origfiledes[1], 2);
     282  return;
     283  }
     284
    262285consstream[1] = cons; streamva[1] = va;
    263286
    264287int p[2];
    265288pipe(p);
    266 // Redirection de stderr (fid=0) :
     289// Redirection de stderr (fid=2) :
    267290close(2);
    268291dup(p[1]);
    269292close(p[1]);
    270293fcntl(p[0], F_SETFL, O_NONBLOCK);
     294
    271295setlinebuf(stderr);
     296ios::sync_with_stdio();
    272297
    273298int szx, szy, szf;
    274299XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
    275 XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask, redirectstream_callback, (XtPointer) (streamno+1));
    276 }
    277 
     300inputid[1] = XtAppAddInput(*appctx, p[0], (XtPointer) XtInputReadMask,
     301                           redirectstream_callback, (XtPointer) (streamno+1));
     302}
     303
  • trunk/SophyaPI/PI/piwdgx.cc

    r132 r135  
    3030static XFontStruct * stdfnt = NULL;
    3131
     32// Variable globale Widget qui possede la selection pour le copier-coller
     33static PIWdgX* curselwdg = NULL;    // Le PIWdg qui possede la selection
     34
    3235/* Nouvelle-Fonction */
    3336XtAppContext* PIXtAppCtx(int& szx, int& szy, int& szf)
     
    179182printf("Debug_PIWdgX::~PIWdgX()  %lx %lx \n", (long)this, (long)sdw);
    180183#endif
     184if (curselwdg == this)  { SelectionLost(); curselwdg = NULL; }
    181185if (!sdw)  XtDestroyWidget(sdw);
    182186}
     
    592596                                 XtPointer value, unsigned long* len, int* format );
    593597
    594 static PIWdgX* curselwdg = NULL;    // Le PIWdg qui possede la selection
    595598static unsigned int curseltype = PICP_string; // Type de selcetion qu'il peut fournir
    596599static unsigned int reqseltype = PICP_string; // Type de selection demande
Note: See TracChangeset for help on using the changeset viewer.