CVS: setedit/setedit editmain.cc,1.130,1.131
Brought to you by:
set
From: Salvador E. T. <se...@us...> - 2010-07-07 13:25:51
|
Update of /cvsroot/setedit/setedit/setedit In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv26667/setedit Modified Files: editmain.cc Log Message: * Added: A mechanism to control the editor from another program using named pipes. Currently you can jump to an error or quit the editor. * Added: Editors now report to belong to a window class called SETEdit. Index: editmain.cc =================================================================== RCS file: /cvsroot/setedit/setedit/setedit/editmain.cc,v retrieving revision 1.130 retrieving revision 1.131 diff -C2 -d -r1.130 -r1.131 *** editmain.cc 25 Feb 2009 16:11:31 -0000 1.130 --- editmain.cc 7 Jul 2010 13:25:42 -0000 1.131 *************** *** 1,3 **** ! /* Copyright (C) 1996-2005 by Salvador E. Tropea (SET), see copyrigh file for details */ #define Uses_BestWrite --- 1,3 ---- ! /* Copyright (C) 1996-2010 by Salvador E. Tropea (SET), see copyrigh file for details */ #define Uses_BestWrite *************** *** 80,83 **** --- 80,84 ---- #include <fcntl.h> #include <loadkbin.h> + #define DEF_PARSE_FUNC #include <runprog.h> #include <loadcle.h> *************** *** 128,131 **** --- 129,138 ---- uint32 TSetEditorApp::modifFilesOps=0; + // Control pipe + const unsigned maxCommandLen=PATH_MAX+64; + char *TSetEditorApp::controlPipeName=NULL; + FILE *TSetEditorApp::controlPipeFILE=NULL; + Boolean TSetEditorApp::forceQuit=False; + XYFStack stkPos; const char *KeyBindFName="keybind.dat"; *************** *** 892,895 **** --- 899,907 ---- event.message.command=cmHelp; } + else if (forceQuit && event.what==evNothing) + { + event.what=evCommand; + event.message.command=cmeQuit; + } switch (event.what) { *************** *** 2337,2340 **** --- 2349,2388 ---- multiMenuBar->update(); TApplication::idle(); + + // Control pipe + if (TSetEditorApp::controlPipeFILE) + { + char b[maxCommandLen]; + if (fgets(b,maxCommandLen-1,TSetEditorApp::controlPipeFILE)) + { + //printf("Command: %s\n",b); + char *s=b; + if (*s=='$') + { + char *end; + for (end=s+1; *end && *end!=':'; end++); + if (*end==':') + { + *end=0; + s=end+1; + if (strcmp(b+1,"quit")==0) + { + TSetEditorApp::forceQuit=True; + } + else if (strcmp(b+1,"jump")==0) + { + FileInfo fI; + char *fileName; + char *msg=ParseFun(s,fI,fileName); + if (fileName && fI.Line>=0) + GotoFileLine(fI.Line,fI.Column,fileName,msg,fI.offset,fI.len); + free(msg); + free(fileName); + } + } + } + } + } + clock_t DifLastTime=lastIdleClock-LastTimeUpdate; *************** *** 2795,2798 **** --- 2843,2847 ---- { "no-bios-keyb", 0, 0, 'B' }, // obsolete { "cascade", 0, 0, 'c' }, + { "control-pipe", 1, 0, 'C' }, { "stack-dbg", 1, 0, 'd' }, { "file-list", 1, 0, 'f' }, *************** *** 2853,2857 **** StackDbgStrategy=atoi(ExtraCMDLine); ! while ((optc=CLY_getopt_long(Argc,Argv,"b:Bcd:fhkK:lLmMp:rStT:",longopts,0))!=EOF) { switch (optc) --- 2902,2906 ---- StackDbgStrategy=atoi(ExtraCMDLine); ! while ((optc=CLY_getopt_long(Argc,Argv,"b:BcC:d:fhkK:lLmMp:rStT:",longopts,0))!=EOF) { switch (optc) *************** *** 2860,2863 **** --- 2909,2915 ---- SE_CascadeWindows=1; break; + case 'C': + TSetEditorApp::controlPipeName=newStr(CLY_optarg); + break; case 'd': StackDbgStrategy=atoi(CLY_optarg); *************** *** 2929,2932 **** --- 2981,2987 ---- " the end of the text. Example: +6 file\n")); PrintHelp(_("-c, --cascade: arranges the windows using cascade style.\n")); + #ifdef SEOS_UNIX + PrintHelp(_("-C, --control-pipe fn opens fn as a named pipe (FIFO) to receive commands.\n")); + #endif PrintHelp(_("-d, --stack-dbg=n: indicates which method will be used in the event of a\n" " crash. The default method is 0.\n" *************** *** 3096,3099 **** --- 3151,3170 ---- } + static + void OpenControlPipe() + { + if (!TSetEditorApp::controlPipeName) + return; + FILE *f=fopen(TSetEditorApp::controlPipeName,"rt"); + if (f) + { + int h=fileno(f); + int old=fcntl(h,F_GETFL,0); + fcntl(h,F_SETFL,old|O_NONBLOCK); + TSetEditorApp::controlPipeFILE=f; + unlink(TSetEditorApp::controlPipeName); + } + } + int main(int argc, char *argv[]) { *************** *** 3101,3105 **** // Avoid handling Alt+N for window selection in TV core. TProgram::doNotHandleAltNumber=1; ! ParseCommandLine(argc,argv); CheckIfCurDirValid(); --- 3172,3178 ---- // Avoid handling Alt+N for window selection in TV core. TProgram::doNotHandleAltNumber=1; ! ! TScreen::windowClass="SETEdit"; ! ParseCommandLine(argc,argv); CheckIfCurDirValid(); *************** *** 3348,3351 **** --- 3421,3425 ---- ShowTips(ExpandHome(TipsFName)); ShowSHLLoadErrors(); + OpenControlPipe(); editorApp->run(); |