Mail Archives: djgpp-workers/2001/06/27/13:46:40
This patch adds proxy support to v2loadimage. Comments?
Index: v2load.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/debug/common/v2load.c,v
retrieving revision 1.6
diff -c -p -r1.6 v2load.c
*** v2load.c 2001/06/21 17:13:50 1.6
--- v2load.c 2001/06/27 17:45:50
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
***************
*** 20,25 ****
--- 21,27 ----
#include <debug/v2load.h>
#include <libc/farptrgs.h>
#include <sys/stat.h>
+ #include <ctype.h>
#define SIMAGIC "go32stub"
#define __tb_size _go32_info_block.size_of_transfer_buffer
*************** static int read_section(int pf, unsigned
*** 53,58 ****
--- 55,166 ----
return 0;
}
+ static inline int
+ is_quote(const char ch)
+ {
+ return (ch == '"' || ch == '\'');
+ }
+
+ static
+ const char * get_arg(const char *ptr, const char **beg, const char **end)
+ {
+ while (*ptr && isspace(*ptr))
+ ++ptr;
+ if (!is_quote(*ptr))
+ {
+ *beg = ptr;
+ while (*ptr && !isspace(*ptr))
+ ++ptr;
+ *end = ptr;
+ }
+ else
+ {
+ char quote = *ptr;
+ *beg = ptr;
+ ++ptr;
+ while (*ptr && *ptr != quote)
+ ++ptr;
+ ++ptr;
+ *end = ptr;
+ }
+
+ return ptr;
+ }
+
+ static size_t
+ make_proxy_var(const char *program, const char *cmdline,
+ unsigned long tbuf, size_t tb_len, size_t *tb_space)
+ {
+ size_t argc;
+ const char *beg, *end;
+ char proxy_string[] = " !proxy";
+ char proxy[48];
+
+ /* Include the program name, a null terminator, and offset pointer
+ in the argument count. */
+ argc = 1;
+ *tb_space = strlen(program) + 1 + sizeof(short);
+
+ /* Got arguments? */
+ while (*cmdline && (*tb_space <= tb_len))
+ {
+ cmdline = get_arg(cmdline, &beg, &end);
+ /* Add in the space needed for the command, a null terminator
+ and offset pointer. */
+ *tb_space += (end - beg) + 1 + sizeof(short);
+ ++argc;
+ }
+ /* If the last arg would cause an overrun, don't include it. */
+ if (*tb_space > tb_len)
+ {
+ --argc;
+ *tb_space -= (end - beg) - 1 - sizeof(short);
+ }
+
+ if (*tb_space > 126)
+ {
+ sprintf(proxy, "%s=%04x %04lx %04lx", proxy_string, (unsigned int)argc,
+ tbuf / 16, tbuf & 0x0f);
+ putenv(proxy);
+ }
+
+ return argc;
+ }
+
+ static void
+ make_proxy_buffer(const char *prog, const char *cmdline, size_t argc,
+ unsigned long tbuf, size_t tb_len)
+ {
+ const char *ptr, *beg, *end;
+ unsigned long argv_ptr;
+ unsigned long tbuf_end;
+ int i;
+ size_t arg_len;
+
+ tbuf_end = tbuf + tb_len;
+ argv_ptr = tbuf + (argc + 1) * sizeof(short);
+ ptr = cmdline;
+
+ /* Insert the program name into argv[0]. */
+ arg_len = strlen(prog) + 1;
+ dosmemput(prog, arg_len, argv_ptr);
+ _farpokew(_dos_ds, tbuf + 0, (argv_ptr - tbuf) & 0xffff);
+ argv_ptr += arg_len;
+
+ /* Now insert the command line into argv[]. */
+ i = 1;
+ while (i < argc)
+ {
+ ptr = get_arg(ptr, &beg, &end);
+ arg_len = end - beg;
+ dosmemput(beg, arg_len, argv_ptr);
+ _farpokeb(_dos_ds, argv_ptr + arg_len, 0);
+ _farpokew(_dos_ds, tbuf + i * sizeof(short), (argv_ptr - tbuf) & 0xffff);
+ argv_ptr += arg_len + 1;
+ ++i;
+ }
+ }
+
int v2loadimage(const char *program, const char *cmdline, jmp_buf load_state)
{
unsigned short header[5];
*************** int v2loadimage(const char *program, con
*** 66,71 ****
--- 174,180 ----
__dpmi_meminfo memblock;
unsigned new_env_selector;
char true_name[FILENAME_MAX];
+ size_t proxy_argc, proxy_space;
_truename(program, true_name);
*************** int v2loadimage(const char *program, con
*** 137,142 ****
--- 246,257 ----
si.initial_size += 0xffff;
si.initial_size &= 0xffff0000U;
+ /* Create the proxy variable now so the child's environment
+ has the correct size. */
+ while (*cmdline && isspace(*cmdline))
+ ++cmdline;
+ proxy_argc = make_proxy_var(program, cmdline, __tb, __tb_size, &proxy_space);
+
si.env_size = 0;
for (i=0; environ[i]; i++)
si.env_size += strlen(environ[i])+1;
*************** int v2loadimage(const char *program, con
*** 258,263 ****
--- 373,383 ----
/* copy command arguments into debug process */
movedata(my_ds, (unsigned)cmdline, si.psp_selector, 128, 128);
+
+ /* Setup the buffer with proxy arguments. */
+ if (proxy_space > 126)
+ make_proxy_buffer(program, cmdline, proxy_argc, __tb, __tb_size);
+
/* copy si we built into debug process */
movedata(my_ds, (unsigned)&si, si.ds_selector, 0, sizeof(si));
load_state->__ds = client_ds;
- Raw text -