|
From: Andre R. <and...@us...> - 2006-03-10 10:00:07
|
Update of /cvsroot/frontierkernel/Frontier/Common/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23553/Common/source Modified Files: sysshellcall.c Log Message: Improved error checking and reporting in winshellcall and its subroutines. Index: sysshellcall.c =================================================================== RCS file: /cvsroot/frontierkernel/Frontier/Common/source/sysshellcall.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** sysshellcall.c 9 Mar 2006 22:19:54 -0000 1.4 --- sysshellcall.c 10 Mar 2006 09:59:55 -0000 1.5 *************** *** 33,36 **** --- 33,39 ---- #include "threads.h" #include "error.h" + #include "langinternal.h" /*for error strings*/ + #include "resources.h" /*for error strings*/ + #include "shell.h" #include "sysshellcall.h" *************** *** 38,42 **** #if defined(MACVERSION) && (TARGET_API_MAC_CARBON == 1) - #include "shell.h" #include "lang.h" #include "CallMachOFramework.h" --- 41,44 ---- *************** *** 208,211 **** --- 210,218 ---- #ifdef WIN95VERSION + #define CHDOUBLEQUOTE '"' + #define CHSEMICOLON ';' + #define CHBACKSLASH '\\' + #define CHNULL '\0' + static boolean getenvironmentvariable (char *name, boolean flwinerror, Handle *hresult) { *************** *** 218,222 **** long res; ! res = GetEnvironmentVariable (name, nil, 0); if (res == 0) { --- 225,229 ---- long res; ! res = GetEnvironmentVariable (name, nil, 0); /*get required space*/ if (res == 0) { *************** *** 231,237 **** lockhandle (h); ! res = GetEnvironmentVariable (name, *h, res); unlockhandle (h); if (!sethandlesize (h, res)) { /*drop trailing nil char*/ --- 238,246 ---- lockhandle (h); ! res = GetEnvironmentVariable (name, *h, res); /*get actual value*/ unlockhandle (h); + + assert (gethandlesize (h) == res + 1); if (!sethandlesize (h, res)) { /*drop trailing nil char*/ *************** *** 248,251 **** --- 257,264 ---- static boolean cmdshellexists (Handle hshell) { + /* + 2006-03-09 aradke: check whether a file exists at the given path + */ + DWORD attr; *************** *** 293,303 **** - #define CHDOUBLEQUOTE '"' - #define CHSEMICOLON ';' - #define CHBACKSLASH '\\' - - static boolean getnextpath (Handle hpath, long *ixstart, Handle *hitem) { Handle h; handlestream s; --- 306,315 ---- static boolean getnextpath (Handle hpath, long *ixstart, Handle *hitem) { + /* + 2006-03-10 aradke: extract the next item from a string delimited by semicolons + */ + Handle h; handlestream s; *************** *** 327,333 **** }/*while*/ /*extract item*/ ! if (!loadfromhandletohandle (s.data, ixstart, s.pos - *ixstart, false, &h)) return (false); --- 339,347 ---- }/*while*/ + assert (athandlestreameof (&s) || (nexthandlestreamcharacter (&s) == CHSEMICOLON)); + /*extract item*/ ! if (!loadfromhandletohandle (s.data, ixstart, min(s.pos, s.eof) - *ixstart, false, &h)) return (false); *************** *** 346,349 **** --- 360,368 ---- }/*while*/ + assert (athandlestreameof (&s)); + + if (s.eof == 0) + return (false); /*break out of potential infinite loop at end of path string*/ + if (lasthandlestreamcharacter (&s) != CHBACKSLASH) if (!writehandlestreamchar (&s, CHBACKSLASH)) { *************** *** 352,355 **** --- 371,376 ---- } + assert (lasthandlestreamcharacter (&s) == CHBACKSLASH); + *hitem = closehandlestream (&s); *************** *** 357,360 **** --- 378,401 ---- } /*getnextpath*/ + + static void cmdnotfounderror (Handle hshell) { + + /* + 2006-03-10 aradke: report missing command shell + */ + + bigstring bsshell, bs; + + texthandletostring (hshell, bsshell); + + poptrailingchars (bsshell, CHNULL); + + getstringlist (langerrorlist, cmdshellnotfounderror, bs); + + parsedialogstring (bs, (ptrstring) bsshell, nil, nil, nil, bs); + + shellerrormessage (bs); + } /*cmdnotfounderror*/ + static boolean searchcmdpath (Handle *hshell) { *************** *** 364,370 **** see if the command shell is located in any of the directories. caller is responsible for disposing hshell. - - TO DO: - - check length of hshell < MAX_PATH */ --- 405,408 ---- *************** *** 384,389 **** if (!pushhandle (*hshell, h)) goto exit; ! ! if (!enlargehandle (h, 1, "\0")) goto exit; --- 422,427 ---- if (!pushhandle (*hshell, h)) goto exit; ! ! if (!pushcharhandle (CHNULL, h)) goto exit; *************** *** 397,403 **** }/*while*/ ! /*not found*/ ! ! oserror (ERROR_FILE_NOT_FOUND); exit: --- 435,439 ---- }/*while*/ ! cmdnotfounderror (*hshell); exit: *************** *** 413,419 **** 2006-03-09 aradke: launch the command shell as a child process. we consume hshell, but caller is responsible for closing hout if we return true. - - TO DO: - - check length of hcmdline < MAX_PATH */ --- 449,452 ---- *************** *** 458,466 **** if (!concathandles (hshell, hcommand, &hcmdline)) goto exit; ! ! if (!enlargehandle (hshell, 1, "\0")) goto exit; ! if (!enlargehandle (hcmdline, 1, "\0")) goto exit; --- 491,499 ---- if (!concathandles (hshell, hcommand, &hcmdline)) goto exit; ! ! if (!pushcharhandle (CHNULL, hshell)) goto exit; ! if (!pushcharhandle (CHNULL, hcmdline)) goto exit; *************** *** 468,472 **** if (!cmdshellexists (hshell)) { ! if (!searchcmdpath (&hshell)) /*do a search path lookup*/ goto exit; } --- 501,505 ---- if (!cmdshellexists (hshell)) { ! if (!searchcmdpath (&hshell)) /*do a search path lookup, sets error*/ goto exit; } *************** *** 592,599 **** return (false); ! if (!runcmdshell (hshell, hcommand, &hread)) return (false); ! if (!readcmdresult (hread, hreturn)) return (false); --- 625,632 ---- return (false); ! if (!runcmdshell (hshell, hcommand, &hread)) /*consumes hshell*/ return (false); ! if (!readcmdresult (hread, hreturn)) /*consumes hread*/ return (false); |