|
From: Andre R. <and...@us...> - 2006-03-09 11:08:55
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22903/Common/source Modified Files: CallMachOFrameWork.c langstartup.c shellsysverbs.c sysshellcall.c Log Message: Moved unixshellcall from CallMachOFrameWork.c to sysshellcall.c Index: sysshellcall.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/sysshellcall.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** sysshellcall.c 9 Mar 2006 09:46:29 -0000 1.1 --- sysshellcall.c 9 Mar 2006 11:08:50 -0000 1.2 *************** *** 33,39 **** --- 33,225 ---- #include "sysshellcall.h" + + #if defined(MACVERSION) && (TARGET_API_MAC_CARBON == 1) + + #include "shell.h" + #include "lang.h" + #include "CallMachOFramework.h" + #include <fcntl.h> /* 2006-01-10 creedon */ + + /* 2006-01-29 creedon - define the following for CodeWarrior compilation because it doesn't have these defined in its headers, as Xcode does */ + #ifdef __MWERKS__ + #define F_GETFL 3 /* get file status flags */ + #define F_SETFL 4 /* set file status flags */ + #define O_NONBLOCK 0x0004 /* no delay */ + #endif //__MWERKS__ + #endif //MACVERSION && TARGET_API_MAC_CARBON + + + #ifdef WIN95VERSION + #include <stdio.h> #include <stdlib.h> + #endif //WIN95VERSION + + + #if defined(MACVERSION) && (TARGET_API_MAC_CARBON == 1) + + /*System.framework functions: popen, pclose, fread, fcntl, feof, and fileno.*/ + + typedef FILE* (*popenptr) (const char* command, const char *type); + typedef int (*pcloseptr) (FILE* f); + typedef size_t (*freadptr) (void *ptr, size_t size, size_t nobj, FILE* f); + typedef int (*fcntlptr) (int fd, int cmd, int arg); /* 2006-01-10 creedon */ + typedef int (*feofptr) (FILE *f); /* 2006-01-10 creedon */ + typedef int (*filenoptr) (FILE *f); /* 2006-01-10 creedon */ + + static popenptr popenfunc; + static pcloseptr pclosefunc; + static freadptr freadfunc; + static fcntlptr fcntlfunc; /* 2006-01-10 creedon */ + static feofptr feoffunc; /* 2006-01-10 creedon */ + static filenoptr filenofunc; /* 2006-01-10 creedon */ + + static boolean unixshellcallinited = false; + static CFBundleRef sysBundle = nil; + + + static boolean unixshellcallinit (void) { + + /* + 2006-01-10 creedon: added fcntlfunc, feoffunc and filenofunc + + 7.0b51 PBS: load the bundle and get the function pointers the first time called. + */ + + if (unixshellcallinited) /*already inited*/ + return (true); + + if (sysBundle == nil) + if (LoadFrameworkBundle (CFSTR ("System.framework"), &sysBundle) != noErr) + return (false); + + popenfunc = (popenptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("popen")); + + if (popenfunc == nil) + return (false); + + freadfunc = (freadptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fread")); + + if (freadfunc == nil) + return (false); + + pclosefunc = (pcloseptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("pclose")); + + if (pclosefunc == nil) + return (false); + + fcntlfunc = (fcntlptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fcntl")); + + if (fcntlfunc == nil) + return (false); + + feoffunc = (feofptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("feof")); + + if (feoffunc == nil) + return (false); + + filenofunc = (filenoptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fileno")); + + if (filenofunc == nil) + return (false); + + unixshellcallinited = true; + + return (true); + } /*unixshellcallinit*/ + + + static boolean unixshellcallbackgroundtask (void) { + + /* + 2005-10-02 creedon: created, cribbed from OpenTransportNetEvents.c: fwsbackgroundtask + */ + + boolean fl = true; + + if (inmainthread ()) { + EventRecord ev; + short mask = osMask|activMask|mDownMask|keyDownMask; // |highLevelEventMask|updateMask + long sleepTime = 6; // 1/10 of a second by default + + if (WaitNextEvent (mask, &ev, sleepTime, nil)) /* might return false to indicate a null event, but that's not an error */ + fl = shellprocessevent (&ev); + } + else + fl = langbackgroundtask (true); + + return (fl); + }/* unixshellcallbackgroundtask */ + + + boolean unixshellcall (Handle hcommand, Handle hreturn) { + + /* + 2006-01-29 creedon: change buf from 32 to 1024 to increase performance of function, we can do this now because fread is now in non-blocking mode, kernel remains repsonsive + + 2006-01-10 creedon: laid down the groundwork for a timeoutsecs parameter, what is a good default? longinfinity? several minutes? I know that some commands I've done have taken 15 - 30 minutes + fread now reads in non-blocking mode, no error checking + + 2005-10-02 creedon: changed buf size from 256 to 32, makes envrionment more responsive + added call to new unixshellcallbackgroundtask function so kernel doesn't lock up while waiting for a lot of data to be read + + 7.0b51: Call the UNIX popen command, which evaluates a string as if it were typed on the command line. Verb: sys.unixShellCommand. + Code adapted by Timothy Paustian from Apple sample code. + This routine by PBS. + */ + + FILE *f; + char buf [1024]; + long ct = 0; + // unsigned long timeoutsecs = 60 * 5; + // long timeoutticks = gettickcount () + (timeoutsecs * 60); + + if (!unixshellcallinit ()) + return (false); + + if (!enlargehandle (hcommand, 1, "\0")) + return (false); + + lockhandle (hcommand); + + f = popenfunc (*hcommand, "r"); /*popen*/ + + unlockhandle (hcommand); + + fcntlfunc (filenofunc (f), F_SETFL, fcntlfunc (filenofunc (f), F_GETFL, 0) | O_NONBLOCK); + + while (true) { + + ct = freadfunc (buf, 1, sizeof buf, f); /*fread*/ + + if (ct > 0) // { + + if (!insertinhandle (hreturn, gethandlesize (hreturn), buf, ct)) + break; + + // timeoutticks = gettickcount () + (timeoutsecs * 60); + // } + + if (feoffunc (f)) + break; + + /* if (gettickcount () > timeoutticks) + break; */ + + if (!unixshellcallbackgroundtask ()) + break; + + } /*while*/ + + pclosefunc (f); /*pclose*/ + + return (true); + } /*unixshellcall*/ + + #endif //MACVERSION + + + #ifdef WIN95VERSION boolean winshellcall (Handle hcommand, Handle hreturn) { *************** *** 83,84 **** --- 269,272 ---- } /*winshellcall*/ + #endif //WIN95VERSION + Index: langstartup.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/langstartup.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** langstartup.c 18 Feb 2006 15:02:13 -0000 1.8 --- langstartup.c 9 Mar 2006 11:08:50 -0000 1.9 *************** *** 42,48 **** #include "resources.h" #include "WinSockNetEvents.h" ! #if TARGET_API_MAC_CARBON == 1 ! #include "CallMachOFrameWork.h" /* 2004-11-19 creedon */ ! #endif --- 42,46 ---- #include "resources.h" #include "WinSockNetEvents.h" ! #include "sysshellcall.h" /* 2006-03-09 aradke: unixshellcall moved from CallMachOFramework.h */ Index: CallMachOFrameWork.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/CallMachOFrameWork.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** CallMachOFrameWork.c 30 Jan 2006 01:42:04 -0000 1.10 --- CallMachOFrameWork.c 9 Mar 2006 11:08:50 -0000 1.11 *************** *** 28,179 **** #include "frontier.h" #include "standard.h" - #include "threads.h" - #include "shell.h" - #include "lang.h" #include "CallMachOFrameWork.h" - #include "memory.h" - #include "fcntl.h" /* 2006-01-10 creedon */ - - - /*System.framework functions: popen, pclose, fread, fcntl, feof, and fileno.*/ - - typedef FILE* (*popenptr) (const char* command, const char *type); - typedef int (*pcloseptr) (FILE* f); - typedef size_t (*freadptr) (void *ptr, size_t size, size_t nobj, FILE* f); - typedef int (*fcntlptr) (int fd, int cmd, int arg); /* 2006-01-10 creedon */ - typedef int (*feofptr) (FILE *f); /* 2006-01-10 creedon */ - typedef int (*filenoptr) (FILE *f); /* 2006-01-10 creedon */ - - static popenptr popenfunc; - static pcloseptr pclosefunc; - static freadptr freadfunc; - static fcntlptr fcntlfunc; /* 2006-01-10 creedon */ - static feofptr feoffunc; /* 2006-01-10 creedon */ - static filenoptr filenofunc; /* 2006-01-10 creedon */ - - static boolean unixshellcallinited = false; - static CFBundleRef sysBundle = nil; - - - /* prototypes */ - static boolean unixshellcallinit (void); - static boolean unixshellcallbackgroundtask (void); - - - boolean unixshellcall (Handle hcommand, Handle hreturn) { - - /* - 2006-01-29 creedon: change buf from 32 to 1024 to increase performance of function, we can do this now because fread is now in non-blocking mode, kernel remains repsonsive - - 2006-01-10 creedon: laid down the groundwork for a timeoutsecs parameter, what is a good default? longinfinity? several minutes? I know that some commands I've done have taken 15 - 30 minutes - fread now reads in non-blocking mode, no error checking - - 2005-10-02 creedon: changed buf size from 256 to 32, makes envrionment more responsive - added call to new unixshellcallbackgroundtask function so kernel doesn't lock up while waiting for a lot of data to be read - - 7.0b51: Call the UNIX popen command, which evaluates a string as if it were typed on the command line. Verb: sys.unixShellCommand. - Code adapted by Timothy Paustian from Apple sample code. - This routine by PBS. - */ - - FILE *f; - char buf [1024]; - long ct = 0; - // unsigned long timeoutsecs = 60 * 5; - // long timeoutticks = gettickcount () + (timeoutsecs * 60); - - if (!unixshellcallinit ()) - return (false); - - if (!enlargehandle (hcommand, 1, "\0")) - return (false); - - lockhandle (hcommand); - - f = popenfunc (*hcommand, "r"); /*popen*/ - - unlockhandle (hcommand); - - fcntlfunc (filenofunc (f), F_SETFL, fcntlfunc (filenofunc (f), F_GETFL, 0) | O_NONBLOCK); - - while (true) { - - ct = freadfunc (buf, 1, sizeof buf, f); /*fread*/ - - if (ct > 0) // { - - if (!insertinhandle (hreturn, gethandlesize (hreturn), buf, ct)) - break; - - // timeoutticks = gettickcount () + (timeoutsecs * 60); - // } - - if (feoffunc (f)) - break; - - /* if (gettickcount () > timeoutticks) - break; */ - - if (!unixshellcallbackgroundtask ()) - break; - - } /*while*/ - - pclosefunc (f); /*pclose*/ - - return (true); - } /*unixshellcall*/ - - - static boolean unixshellcallinit (void) { - - /* - 2006-01-10 creedon: added fcntlfunc, feoffunc and filenofunc - - 7.0b51 PBS: load the bundle and get the function pointers the first time called. - */ - - if (unixshellcallinited) /*already inited*/ - return (true); - - if (sysBundle == nil) - if (LoadFrameworkBundle (CFSTR ("System.framework"), &sysBundle) != noErr) - return (false); - - popenfunc = (popenptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("popen")); - - if (popenfunc == nil) - return (false); - - freadfunc = (freadptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fread")); - - if (freadfunc == nil) - return (false); - - pclosefunc = (pcloseptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("pclose")); - - if (pclosefunc == nil) - return (false); - - fcntlfunc = (fcntlptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fcntl")); - - if (fcntlfunc == nil) - return (false); - - feoffunc = (feofptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("feof")); - - if (feoffunc == nil) - return (false); - - filenofunc = (filenoptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fileno")); - - if (filenofunc == nil) - return (false); - - unixshellcallinited = true; - - return (true); - } /*unixshellcallinit*/ --- 28,33 ---- *************** *** 316,341 **** DisposePtr (cfmfp); } /*disposecfmfuncptr*/ - - - static boolean unixshellcallbackgroundtask (void) { - - /* - 2005-10-02 creedon: created, cribbed from OpenTransportNetEvents.c: fwsbackgroundtask - */ - - boolean fl = true; - - if (inmainthread ()) { - EventRecord ev; - short mask = osMask|activMask|mDownMask|keyDownMask; // |highLevelEventMask|updateMask - long sleepTime = 6; // 1/10 of a second by default - - if (WaitNextEvent (mask, &ev, sleepTime, nil)) /* might return false to indicate a null event, but that's not an error */ - fl = shellprocessevent (&ev); - } - else - fl = langbackgroundtask (true); - - return (fl); - }/* unixshellcallbackgroundtask */ - --- 170,171 ---- Index: shellsysverbs.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/shellsysverbs.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** shellsysverbs.c 9 Mar 2006 09:46:29 -0000 1.8 --- shellsysverbs.c 9 Mar 2006 11:08:50 -0000 1.9 *************** *** 59,68 **** #include "process.h" #include "processinternal.h" ! #if TARGET_API_MAC_CARBON == 1 ! #include "CallMachOFrameWork.h" ! #endif ! #ifdef WIN95VERSION ! #include "sysshellcall.h" ! #endif #include "langsystem7.h" //6.1b7 AR: we need coercetolist --- 59,63 ---- #include "process.h" #include "processinternal.h" ! #include "sysshellcall.h" #include "langsystem7.h" //6.1b7 AR: we need coercetolist |