--- parser3/src/main/pa_exec.C 2003/01/27 17:17:06 1.48.2.1 +++ parser3/src/main/pa_exec.C 2003/04/04 14:42:38 1.49 @@ -1,13 +1,15 @@ /** @file Parser: program executing for different OS-es. - Copyright(c) 2000,2001, 2003 ArtLebedev Group(http://www.artlebedev.com) + Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) + portions by Victor Fedoseev" [January 23, 2003] + @todo setrlimit */ -static const char* IDENT_EXEC_C="$Date: 2003/01/27 17:17:06 $"; +static const char* IDENT_EXEC_C="$Date: 2003/04/04 14:42:38 $"; #include "pa_config_includes.h" @@ -27,7 +29,7 @@ static const char* IDENT_EXEC_C="$Date: /// this func from http://www.ccas.ru/~posp/popov/spawn.htm static DWORD CreateHiddenConsoleProcess(LPCTSTR szCmdLine, - char *szEnv, + char *szEnv, PROCESS_INFORMATION* ppi, LPHANDLE phInWrite, LPHANDLE phOutRead, @@ -111,18 +113,6 @@ error: return result; } -static void read_pipe(String& result, HANDLE hOutRead, const char *file_spec, - String::Untaint_lang lang){ - while(true) { - char *buf=(char *)result.pool().malloc(MAX_STRING); - unsigned long size; - if(!ReadFile(hOutRead, buf, MAX_STRING, &size, NULL) || !size) - break; - result.APPEND(buf, size, lang, file_spec, 0); - } -} - - static const char *buildCommand(Pool& pool, const String& origin_string, const char *file_spec_cstr, const Array *argv) { @@ -152,7 +142,7 @@ static const char *buildCommand(Pool& po buf << result; for(int i=0; isize(); i++) { buf << " "; - buf << argv->get(i); + buf << *argv->get_string(i); } result=buf.cstr(); @@ -161,7 +151,7 @@ static const char *buildCommand(Pool& po return result; } -#else +#else // WIN32 static pid_t execve_piped(const char *file_spec_cstr, char * const argv[], char * const env[], @@ -278,28 +268,90 @@ static int get_exit_status(int pid) { WEXITSTATUS(status) : -2; } -static void read_pipe(String& result, int file, const char *file_spec, String::Untaint_lang lang){ +#endif // WIN32 + +static void read_pipe(String& result, +#ifdef WIN32 + HANDLE hOutRead, +#else // WIN32 + int file, +#endif // WIN32 + const char *file_spec, + String::Untaint_lang lang, + int *header_pos=0, const char **eol_marker=0, size_t *eol_marker_size=0){ + + if(header_pos) *header_pos = -1; + if(eol_marker) *eol_marker = ""; + if(eol_marker_size) *eol_marker_size = 0; + + int dos_seq_match = 0; + int unix_seq_match = 0; + int blk_pos = 0; + bool do_search = (header_pos || eol_marker || eol_marker_size); + while(true) { char *buf=(char *)result.pool().malloc(MAX_STRING); - ssize_t size=read(file, buf, MAX_STRING); +#ifdef WIN32 + unsigned long size, i; + if(!ReadFile(hOutRead, buf, MAX_STRING, &size, NULL) || !size) + break; +#else // WIN32 + ssize_t i, size=read(file, buf, MAX_STRING); if(size<=0) break; +#endif // WIN32 + if(do_search){ + for(i=0; i(info); - string << key << "=" << value; + string << key << "=" << *static_cast(value); string.APPEND_AS_IS("", 1, 0, 0); // zero byte #else String string(key.pool()); - string << key << "=" << value; + string << key << "=" << *static_cast(value); char ***env_ref=static_cast(info); **env_ref=string.cstr(String::UL_UNSPECIFIED); (*env_ref)++; @@ -311,7 +363,8 @@ int pa_exec( const String& file_spec, const Hash *env, const Array *argv, - const String& in, String& out, String& err) { + const String& in, String& out, String& err, + int *header_pos, const char **eol_marker, size_t *eol_marker_size) { Pool& pool=file_spec.pool(); #ifdef NO_PA_EXECS @@ -356,7 +409,7 @@ int pa_exec( // without this char WriteFile(hInWrite, "\x1A", 1, &written_size, NULL); CloseHandle(hInWrite); - read_pipe(out, hOutRead, file_spec_cstr, String::UL_AS_IS); + read_pipe(out, hOutRead, file_spec_cstr, String::UL_AS_IS, header_pos, eol_marker, eol_marker_size); CloseHandle(hOutRead); read_pipe(err, hErrRead, file_spec_cstr, String::UL_TAINTED); CloseHandle(hErrRead); @@ -424,7 +477,7 @@ from http://www.apache.org/websrc/cvsweb if(*in_cstr) // there is some in data write(pipe_write, in_cstr, in.size()); close(pipe_write); - read_pipe(out, pipe_read, file_spec_cstr, String::UL_AS_IS); + read_pipe(out, pipe_read, file_spec_cstr, String::UL_AS_IS, header_pos, eol_marker, eol_marker_size); close(pipe_read); read_pipe(err, pipe_err, file_spec_cstr, String::UL_TAINTED); close(pipe_err);