home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
util
/
csh-5.39.lha
/
Csh
/
src
/
execom.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-07-30
|
49KB
|
1,969 lines
/*
* EXECOM.C
*
* Matthew Dillon, 10 August 1986
* Version 2.07M by Steve Drew 10-Sep-87
* Version 4.01A by Carlo Borreo & Cesare Dieni 17-Feb-90
* Version 5.00L by Urban Mueller 17-Feb-91
* Version 5.20L by Andreas M. Kirchwitz (Fri, 13 Mar 1992)
*
*/
#include "shell.h"
#define DEFAULTFRAME 1024
#define Strlen(x) strlen((char*)x)
#define Strcpy(x,y) strcpy((char*)x,(char*)y)
#define Strcat(x,y) strcat((char*)x,(char*)y)
#define Index(x,y) ((UBYTE*)index((char*)x,y))
#define CHECKAV(num) { if( ac+num+10>max_ac ) checkav( frameptr, num ); }
typedef struct StackFrame {
struct StackFrame *next;
int bytesleft;
char *ptr;
char mem[1];
} FRAME;
/* execom.c */
int fcomm(UBYTE *str,FRAME **frame,char *from );
int hasspace( char *s );
int myfgets( char *buf, FILE *in );
static char *compile_avf(FRAME **frame,char **av,int start,int end,char delim,int quote);
static int preformat(char *s, UBYTE *d);
static void backtrans(UBYTE *str);
static UBYTE *exarg(UBYTE **ptr, UBYTE *elast);
static UBYTE *format_insert_string(FRAME **frameptr, UBYTE *str, char *from);
static int find_command(char *str);
static int checkav( FRAME **frame,int n );
static char *tempname( int which );
static UBYTE *skipword( UBYTE *strskip );
static void newframe( FRAME **frame, int bytes);
static void *falloc( FRAME **frame, int bytes );
static void *frealloc( FRAME **frame, char *oldstring, int morebytes );
static void funalloc( FRAME **frame, int bytes );
static char *push_cpy( FRAME **frame, void *s);
static void deleteframe( FRAME *frame);
void exec_every(void);
int do_nothing(void);
struct COMMAND {
int (*func)();
short minargs;
short stat;
int val;
char *name;
char *options;
char *usage;
};
#define ST_COND 0x01 /* this is an 'if' type command, no redirection */
#define ST_NORED 0x02 /* this command can't be redirected */
#define ST_NOEXP 0x04 /* no wild card expansion for this command */
#define ST_A0 0x08 /* delimit args with 0xA0 instead of ' ' */
#define ST_FUNC 0x10 /* can be used as a function */
#define ST_STORED 0x20 /* stores redirection instead of execuing it */
#define ST_AVLINE 0x40 /* needs avline */
#define COND ST_COND
#define NORED ST_NORED
#define STRED ST_STORED
#define NOEXP ST_NOEXP
#define A0 (ST_A0|ST_AVLINE)
#define AV ST_AVLINE
#define FUNC ST_FUNC
#define ALIAS LEVEL_ALIAS
#define SET LEVEL_SET
#define FIRSTCOMMAND 4
#define COM_EXEC 3
static struct COMMAND Command[] = {
do_run, 0, A0, 0, "\001", NULL, NULL, /* may call do_source, do_cd */
do_nothing, 0, 0, 0, "\002", NULL, NULL, /* dummy for aliases */
do_nothing, 0, 0, 0, "\003", NULL, NULL, /* dummy for aliases with args */
do_run, 0,NORED|A0, 1, "\004", NULL, NULL, /* external that needs to be Execute()d */
do_abortline, 0, 0, 0, "abortline", NULL, "",
do_action, 2, AV, 9, "action", "av", "action file [args]",
do_addbuffers,1, 0, 0, "addbuffers", NULL, "{drive [bufs]}",
do_tackon, 3, FUNC, 0, "addpart", NULL, "var pathname filename",
do_set_var, 0, 0, ALIAS, "alias", NULL, "[name [string] ]",
do_ascii, 0, 0, 0, "ascii", "oh", "-oh [string]",
do_assign, 0, 0, 0, "assign", "adpln",",logical,-adp {logical physical}",
do_basename, 2, FUNC, 0, "basename", NULL, "var path",
do_cat, 0, 0, 0, "cat", "n", "-n [file file...]",
do_cd, 0, 0, 0, "cd", "g", "[path],-g path...path",
do_chgrp, 2, 0, 0, "chgrp", NULL, "group file...file",
do_chmod, 2, 0, 0, "chmod", NULL, "flags file...file",
do_chown, 2, 0, 0, "chown", NULL, "owner file...file",
do_class, 0, A0, 0, "class", "n", "-n name {type=param} \"actions\" {action=command}",
do_close, 0, 0, 0, "close", NULL, "filenumber",
do_copy, 1, 0, 0, "copy", "rudpfmqoa","-adfmopqru file file,-ud file...file dir,-ud dir...dir dir",
do_copy, 1, 0, 0, "cp", "rudpfmqoa","-adfmopqru file file,-ud file...file dir,-ud dir...dir dir",
do_date, 0, 0, 0, "date", "srb","-bsr [date/time]",
do_inc, 1, 0, -1, "dec", NULL, "varname [step]",
do_rm, 0, 0, 0, "delete", "rfpqv","-fpqrv file...file",
do_dir, 0,NOEXP, 0, "dir", "sfdcnhltbuikqavopzegL","-abcdefghiklnopqstuvL [-z lformat] [path...path]",
do_diskchange,1, 0, 0, "diskchange", NULL, "drive...drive",
do_echo, 0, 0, 0, "echo", "ne", "-ne string",
do_if, 0, COND, 1, "else", NULL, "",
do_if, 0, COND, 2, "endif", NULL, "",
do_error, 1, 0, 0, "error", NULL, "num",
do_exec, 1, AV, 0, "exec", "i", "-i command",
do_fault, 1, 0, 0, "fault", NULL, "error",
do_filenote, 1, 0, 0, "filenote", "s", "file...file note,-s file...file",
do_fileslist, 0, 0, 0, "flist", NULL, "",
do_fltlower, 0, 0, 0, "fltlower", NULL, "<in >out",
do_fltupper, 0, 0, 0, "fltupper", NULL, "<in >out",
do_foreach, 3, 0, 0, "foreach", "v", "-v varname ( string ) command",
do_forever, 1, AV, 0, "forever", NULL, "command",
do_forline, 3, 0, 0, "forline", NULL, "var filename command",
do_fornum, 4, 0, 0, "fornum", "vs", "-vs var n1 n2 command",
do_getenv, 1, FUNC, 0, "getenv", NULL, "shellvar envvar",
do_goto, 1, 0, 0, "goto", NULL, "label",
do_head, 0, 0, 0, "head", NULL, "[filename] [num]",
do_help, 0, 0, 0, "help", "f", "help -f",
do_history, 0, 0, 0, "history", "nr", "-nr [partial_string]",
do_howmany, 0, 0, 0, "howmany", NULL, "",
do_htype, 0, 0, 0, "htype", "r", "-r [file...file]",
do_if, 1,COND|NORED,0, "if", "rftmdvone","-n arg cond arg,-n arg,-nf file,-nd dir,-nm,-nt file...file,-nr rpn_expr,-no opt args,-v varname",
do_inc, 1, 0, 1, "inc", NULL, "varname [step]",
do_info, 0, 0, 0, "info", "pt", "-pt [drive...drive]",
do_input, 1, 0, 0, "input", "sr", "-rs var...var",
do_join, 2, 0, 1, "join", "r", "-r file...file",
do_keymap, 1, 0, 0, "keymap", "n", "-n number {key=function}",
do_label, 1, COND, 0, "label", NULL, "name",
do_local, 0, 0, 0, "local", NULL, "[var...var]",
do_linecnt, 0, 0, 0, "linecnt", NULL, "<in >out",
do_ln, 1, 0, 0, "ln", "s", "-s original [link]",
do_dir, 0,NOEXP, 0, "ls", "sfdcnhltbuikqavopzegL","-abcdefghiklnopqstuvL [-z format] [path...path]",
do_ln, 1, 0, 0, "makelink", "s", "-s original [link]",
do_man, 0, 0, 0, "man", NULL, "command...command",
do_mkdir, 1, 0, 0, "md", "p", "-p name...name",
do_mem, 0, 0, 0, "mem", "cfqsrl","-cflqsr",
do_menu, 0, 0, 0, "menu", "nm", "-nm [title item...item]",
do_mkdir, 1, 0, 0, "mkdir", "p", "-p name...name",
do_mv, 2, 0, 0, "mv", "fv", "-fv from to,from...from todir",
do_open, 3, 0, 0, "open", NULL, "file mode number",
do_path, 0, 0, 0, "path", "rg", "-gr [dir...dir]",
do_pri, 2, 0, 0, "pri", NULL, "clinumber pri,0 pri",
do_protect, 2, 0, 0, "protect", NULL, "file...file flags",
do_ps, 0, 0, 0, "ps", "les","-els [commandname...commandname]",
do_pwd, 0, 0, 0, "pwd", NULL, "",
do_qsort, 0, 0, 0, "qsort", "rc", "-cr <in >out",
do_quit, 0,NORED, 0, "quit", NULL, "",
do_truerun, 1,NORED|AV, 1, "rback", NULL, "command",
do_mv, 2, 0, 0, "rename", "fv", "-fv from to,from...from todir",
do_readfile, 1, 0, 0, "readf