|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
|
|
|
#include <milib.h> |
|
|
#include <miptrnam.h> |
|
|
#include <mih/callpgmv.h> |
|
|
|
|
|
#ifndef CURLPGM |
|
|
#define CURLPGM "CURL" |
|
|
#endif |
|
|
|
|
|
|
|
|
struct vary2 { |
|
|
short len; |
|
|
char string[5000]; |
|
|
}; |
|
|
|
|
|
|
|
|
struct arguments { |
|
|
char *pgm; |
|
|
struct vary2 *cmdargs; |
|
|
}; |
|
|
|
|
|
static int |
|
|
is_ifs(char c) |
|
|
{ |
|
|
return c == ' ' || c == '\t' || c == '\r' || c == '\n'; |
|
|
} |
|
|
|
|
|
static int |
|
|
parse_command_line(const char *cmdargs, size_t len, |
|
|
size_t *argc, char **argv, |
|
|
size_t *argsize, char *argbuf) |
|
|
{ |
|
|
const char *endline = cmdargs + len; |
|
|
char quote = '\0'; |
|
|
int inarg = 0; |
|
|
|
|
|
*argc = 0; |
|
|
*argsize = 0; |
|
|
|
|
|
while(cmdargs < endline) { |
|
|
char c = *cmdargs++; |
|
|
|
|
|
if(!inarg) { |
|
|
|
|
|
if(is_ifs(c)) |
|
|
continue; |
|
|
|
|
|
|
|
|
++*argc; |
|
|
if(argv) |
|
|
*argv++ = argbuf; |
|
|
inarg = 1; |
|
|
} |
|
|
|
|
|
|
|
|
if(quote && quote == c) { |
|
|
quote = '\0'; |
|
|
continue; |
|
|
} |
|
|
|
|
|
|
|
|
if(quote != '\'' && c == '\\') { |
|
|
if(cmdargs >= endline) { |
|
|
fputs("Trailing backslash in command\n", stderr); |
|
|
return -1; |
|
|
} |
|
|
c = *cmdargs++; |
|
|
} |
|
|
else if(!quote && is_ifs(c)) { |
|
|
inarg = 0; |
|
|
c = '\0'; |
|
|
} |
|
|
|
|
|
|
|
|
if(argbuf) |
|
|
*argbuf++ = c; |
|
|
++*argsize; |
|
|
} |
|
|
|
|
|
if(quote) { |
|
|
fprintf(stderr, "Unterminated quote: %c\n", quote); |
|
|
return -1; |
|
|
} |
|
|
|
|
|
|
|
|
if(inarg) { |
|
|
if(argbuf) |
|
|
*argbuf = '\0'; |
|
|
++*argsize; |
|
|
} |
|
|
|
|
|
|
|
|
if(argv) |
|
|
*argv = NULL; |
|
|
|
|
|
return 0; |
|
|
} |
|
|
|
|
|
|
|
|
int |
|
|
main(int argsc, struct arguments *args) |
|
|
{ |
|
|
size_t argc; |
|
|
char **argv; |
|
|
size_t argsize; |
|
|
int i; |
|
|
int exitcode; |
|
|
char library[11]; |
|
|
|
|
|
|
|
|
for(i = 0; i < 10; i++) { |
|
|
char c = args->pgm[i]; |
|
|
|
|
|
if(!c || c == '/') |
|
|
break; |
|
|
|
|
|
library[i] = c; |
|
|
} |
|
|
library[i] = '\0'; |
|
|
|
|
|
|
|
|
exitcode = parse_command_line(args->cmdargs->string, args->cmdargs->len, |
|
|
&argc, NULL, &argsize, NULL); |
|
|
|
|
|
if(!exitcode) { |
|
|
|
|
|
argv = (char **) malloc((argc + 1) * sizeof(*argv) + argsize); |
|
|
if(!argv) { |
|
|
fputs("Memory allocation error\n", stderr); |
|
|
exitcode = -2; |
|
|
} |
|
|
else { |
|
|
_SYSPTR pgmptr = rslvsp(WLI_PGM, (char *) CURLPGM, library, _AUTH_NONE); |
|
|
_LU_Work_Area_T *luwrka = (_LU_Work_Area_T *) _LUWRKA(); |
|
|
|
|
|
parse_command_line(args->cmdargs->string, args->cmdargs->len, |
|
|
&argc, argv, &argsize, (char *) (argv + argc + 1)); |
|
|
|
|
|
|
|
|
_CALLPGMV((void *) &pgmptr, argv, argc); |
|
|
exitcode = luwrka->LU_RC; |
|
|
|
|
|
free(argv); |
|
|
} |
|
|
} |
|
|
|
|
|
return exitcode; |
|
|
} |
|
|
|