?? batch.c
字號:
/*rbf*/
#if 1
BYTE prmptcpbuf[MAX_ENVLEN];
REG BYTE *prmptcp = prmptcpbuf;
#endif
if(!echoflg) /* Return if No Echo */
return;
#if defined(CPM)
cp = heap();
strcpy(cp, "[CPM] $u$p$g");
#else
if(env_scan(msg_prmeq, cp = (BYTE *)heap()))
strcpy(cp, DEFAULT_PROMPT);
#endif
if(prompt_flg) /* If the previous Prompt display */
strcpy(cp, "$n$g"); /* terminated due to a Critical */
/* then just display the default */
prompt_flg = TRUE; /* drive. */
#if STACK
cp = stack(strlen(cp) + 1);
#else
cp = &cpbuf[0];
#endif
strcpy(cp, heap());
while((c = *cp++) != 0) { /* get next character */
if (c != '$') /* if not '$', print as is */
putc (c);
else {
c = *cp++;
switch(tolower(c)) { /* else get next character */
case '\0': /* Treat "$\0" as an invalid */
cp--; /* prompt command sequence */
break;
case 't': /* print current time */
disp_systime();
break;
case 'd': /* print current date */
disp_sysdate();
break;
case 'p': /* print current path */
if (ms_x_curdir(drive+1, buf) < 0)
printf(MSG_DRV_INVALID);
else
printf("%c:%s%s", drive+'A', pathchar, buf);
break;
case 'v': /* print version number */
cmd_ver("");
break;
case 'n': /* print default drive */
putc((BYTE) drive+'A');
break;
case 'g': /* print ">" */
putc ('>');
break;
case 'l': /* print "<" */
putc ('<');
break;
case 'b': /* print "|" */
putc ('|');
break;
case 'q': /* print "=" */
putc ('=');
break;
case '_': /* print CR,LF */
crlf();
break;
case 'h': /* print backspace, space, backspace */
printf("\b \b");
break;
case 'e': /* print ESC character */
putc ('\33');
break;
/*RG-01 */
#if !defined(NOXBATCH)
#if !defined (NOSECURITY)
#if defined(CDOSTMP) || defined(CDOS)
case 'm': /* print mail status */
if (login_enabled()) {
if(chk_mail()) { /* we have mail */
if(env_scan("MAIL=", heap()))
printf(MSG_UHAVEMAIL);
else
printf("%s",heap());
}
}
break;
case 'u': /* Display the User Name */
if (login_enabled()) {
if((aschextobin(user_info.userid)!=get_user_on_station())||(strlen(user_info.userid)==0)) {
if(get_user_info(get_user_on_station())!=0)
printf("#%04X",get_user_on_station());
else
printf("%s",user_info.loginname);
}
else
printf("%s",user_info.loginname);
}
break;
#endif
#endif
#endif /*NOXBATCH*/
/*RG-01-end*/
#if defined(CPM)
case 'u': /* Display the User Number */
printf("%d", user);
break;
#endif
#if defined(DOSPLUS)
case 'u':
if (!env_scan("LOGINNAME=",heap()))
printf("%s",heap());
break;
#endif
case '$':
putc ('$'); /* print single '$' */
break;
case 'x':
if ((allow_pexec)&&(!batchflg)) prompt_exec();
break;
default: /* Otherwise the character */
break;
}
}
}
prompt_flg = FALSE; /* Prompt display completed OK */
}
#if !defined(CDOSTMP)
/* The following functions are called by the int2e_handler function in
* COM.C. If a program is run from a batch file and calls INT 2E to
* execute a new batch file the original batch file must NOT be terminated.
* Therefore batch and batchflg must be saved, set to zero, and then
* restored when INT 2E returns. - EJH
*/
GLOBAL VOID int2e_start()
{
batchflg_save = batchflg;
batchflg = 0;
batch_save = batch;
echoflg_save = echoflg;
echoflg = ECHO_ON;
}
GLOBAL VOID int2e_finish()
{
batchflg = batchflg_save;
batch = batch_save;
echoflg = echoflg_save;
}
#endif
#if defined(CDOS)
MLOCAL VOID map_user_page(UWORD window_page, UWORD physical_page)
{
UWORD pblk[3];
pblk[0] = window_page;
pblk[1] = physical_page;
pblk[2] = 0;
bdos(181, pblk);
}
MLOCAL BYTE FAR * map_pd_mem(UWORD ppd, UWORD wp, UWORD seg, UWORD offset)
{
/* Map memory for another process into our memory space so we examine it */
UWORD base_seg;
UWORD page;
PD FAR * pdptr;
UWORD sysdat;
UWORD mptbl;
UWORD FAR * ptr;
UWORD mp_off;
UWORD i;
MPAD FAR * mp;
sysdat = FP_SEG(pd);
ptr = MK_FP(sysdat, 0xc8);
/* DEBUG */
if (*ptr == 0) /* for DEBUG under XM assume non-banked system */
return(MK_FP(seg, offset));
/* DEBUG */
ptr = MK_FP(sysdat, *ptr + 8);
mptbl = *ptr;
/* get segment of 4k page to map */
base_seg = (seg + (offset+15)/16) & 0xff00;
/* now find physical page to map */
pdptr = (PD FAR *) MK_FP(sysdat, ppd);
for (mp_off = pdptr->P_MPAR; mp_off !=0;) {
mp = MK_FP(sysdat, mp_off);
mp_off = mp->link;
if ((base_seg >= mp->start) &&
(base_seg < (mp->start + mp->length))) {
page = mp->xios;
for (i = 0; i < ((base_seg - mp->start)/1024); i++){
ptr = MK_FP(mptbl, page*2);
page = *ptr;
}
page = 4*page + (((base_seg - mp->start)/0x0100) & 3);
map_user_page(wp, page);
return(MK_FP(wp*0x0100,(seg*16+offset) & 0x0fff));
}
}
/* not found in mpad's - must be non-banked address */
return(MK_FP(seg, offset));
}
MLOCAL VOID ip_poke(UWORD ppd, UWORD wp, UWORD seg, UWORD offset, UBYTE val)
{
UBYTE FAR *ptr;
ptr = map_pd_mem(ppd, wp, seg, offset);
*ptr = val;
}
MLOCAL UBYTE ip_peek(UWORD ppd, UWORD wp, UWORD seg, UWORD offset)
{
UBYTE FAR *ptr;
ptr = map_pd_mem(ppd, wp, seg, offset);
return(*ptr);
}
MLOCAL UWORD ip_peek_word(UWORD ppd, UWORD wp, UWORD seg, UWORD offset)
{
return (ip_peek(ppd, wp, seg, offset) +
256*ip_peek(ppd, wp, seg, offset+1));
}
GLOBAL VOID inherit_TMP_state(VOID)
/* inherit batch files */
/* NB. This is bodged - we don't inherit FOR state, or redirection */
{
PD FAR *parent;
UWORD batch_seg;
UWORD tmp_mpad;
UWORD mp_off;
MPAD FAR * mp;
VOID FAR *window;
UWORD win_page;
UWORD i;
parent = (PD FAR *) MK_FP(FP_SEG(pd), pd->P_PARENT);
/* verify our parent is a Tmp, forget if it isn't */
if ((parent->P_NAME[0] != 'T') ||
(parent->P_NAME[1] != 'm') ||
(parent->P_NAME[2] != 'p'))
return;
/* allocate a 4k aligned window to bank data into */
i = 2*4096/16;
mem_alloc(&window, &i, i, i);
if (i==0)
return;
win_page = (FP_SEG(window) + 0x0100) / 0x100;
batch_seg = ip_peek_word(pd->P_PARENT, win_page,
parent->P_PSP, TmpPspBatchSeg);
/* do we have any batch files to inherit */
if (batch_seg) {
echoflg = (BOOLEAN)ip_peek_word(pd->P_PARENT, win_page,
ip_peek_word(pd->P_PARENT, win_page,
parent->P_PSP, TmpPspDataSeg),
ip_peek_word(pd->P_PARENT, win_page,
parent->P_PSP, TmpPspEchoFlgPtr));
/* recover Tmp's hidden mpads */
tmp_mpad = ip_peek_word(pd->P_PARENT, win_page,
parent->P_PSP, TmpPspMpad);
for (mp_off = parent->P_MPAR; mp_off != 0;) {
mp = MK_FP(FP_SEG(parent), parent->P_MPAR);
mp_off = mp->link;
}
mp->link = tmp_mpad;
inherit_batch_file(pd->P_PARENT, win_page, batch_seg);
mp->link = 0; /* unlink again */
}
map_user_page(0, 0); /* force user page to be unmapped */
bdos(141,0); /* dispatch to re-map TPA memory */
mem_free(&window); /* free the window */
}
MLOCAL VOID inherit_batch_file(UWORD ppd, UWORD win_page, UWORD batch_seg)
{
UBYTE FAR * dst;
BCONTROL FAR *save0;
FCONTROL *save1;
BYTE *save2;
WORD save3;
UWORD i;
UWORD data_seg;
PD FAR *parent;
/* if we are in a nested batch file, inherit older batch file first */
i = ip_peek_word(ppd, win_page, batch_seg, 2);
if (i != 0)
inherit_batch_file( ppd, win_page, i);
batch_new(); /* new incarnation of batch */
save0 = batch->bcontrol; save1 = batch->fcontrol;
save2 = batch->heap_start; save3 = batch->heap_size;
dst = (BYTE FAR *) batch; /* copy batch structure */
for (i=0; i<sizeof(BCONTROL); i++) /* from parental PD */
dst[i] = ip_peek(ppd, win_page, batch_seg, i);
/* now terminate parental batch processing by poking EOF */
ip_poke(ppd, win_page,
batch_seg, (UWORD) &batch->eof - (UWORD) &batch->bcontrol,
(UBYTE) TRUE);
/*
* Copy the invoking command and the individual elements
* of the command line into a buffer ready for processing
*/
parent = (PD FAR *) MK_FP(FP_SEG(pd), pd->P_PARENT);
data_seg = ip_peek_word(pd->P_PARENT, win_page,
parent->P_PSP, TmpPspDataSeg);
i = (UWORD) batch->batcmd;
batch->batcmd = (BYTE *)heap(); /* Initialize Parameter Buffer */
while (ip_peek_word(ppd, win_page, data_seg, i) != 0)
*(BYTE *)heap_get(1) = ip_peek(ppd, win_page, data_seg, i++);
*(WORD *)heap_get(2) = 0; /* Double NULL is a terminator */
/* for command line params */
batch->bcontrol = save0; batch->fcontrol = save1;
batch->heap_start = save2; batch->heap_size = save3;
batchflg++; /* increment batch flag */
crlfflg = YES; /* print CR/LF after this */
}
#endif
EXTERN N_CMD novell_ext_list[];
EXTERN BYTE FAR * CDECL farptr(BYTE *);
EXTERN BYTE FAR * CDECL cgroupptr(BYTE *);
EXTERN BOOLEAN CDECL call_novell(BYTE *, BYTE *, WORD);
EXTERN BOOLEAN CDECL nov_station(WORD *);
EXTERN WORD CDECL nov_connection();
MLOCAL BOOLEAN novell_extension(src,dst)
BYTE *src;
BYTE *dst;
/*
* Check if src string is a novell string to be expanded. eg login_name.
* if so, put expansion in dst.
*/
{
N_CMD FAR *n_cmd_p;
BYTE FAR *cpf;
WORD i;
for (i=0;src[i] && src[i]!='=';i++);
src[i] = 0;
n_cmd_p = (N_CMD FAR *)farptr((BYTE *)&novell_ext_list[0]);
while(n_cmd_p->string) {
cpf = cgroupptr(n_cmd_p->string);
for(i=0; (cpf[i]==src[i]) && src[i]; i++);
if(cpf[i]==src[i]) {
(*n_cmd_p->func)(dst);
return(0);
}
n_cmd_p++;
}
return(1);
}
GLOBAL VOID CDECL get_login_name(dst)
BYTE *dst;
{
struct s_nov_e346_in {
WORD len;
BYTE code;
} nov_e346_in;
struct s_nov_e346_out {
WORD len;
BYTE level;
LONG id;
} nov_e346_out;
struct s_nov_e336_in {
WORD len;
BYTE code;
LONG id;
} nov_e336_in;
struct s_nov_e336_out {
WORD len;
LONG id;
WORD type;
BYTE name[48];
} nov_e336_out;
nov_e346_in.len = 1;
nov_e346_in.code = 0x46;
nov_e346_out.len = 5;
nov_e346_out.id = -1L;
call_novell((BYTE *)&nov_e346_in, (BYTE *)&nov_e346_out, 0xE3);
if (nov_e346_out.id == -1L) {
*dst = 0;
return;
}
nov_e336_in.len = 5;
nov_e336_in.code = 0x36;
nov_e336_in.id = nov_e346_out.id;
nov_e336_out.len = 54;
call_novell((BYTE *)&nov_e336_in, (BYTE *)&nov_e336_out, 0xE3);
strcpy(dst,nov_e336_out.name);
}
GLOBAL VOID CDECL get_pstation(dst)
BYTE *dst;
{
WOR
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -