home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
util
/
csh-5.39.lha
/
Csh
/
src
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-01
|
18KB
|
744 lines
/*
* MAIN.C
*
* Matthew Dillon, 24 Feb 1986
* (c)1986 Matthew Dillon 9 October 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 U. Dominik Mueller 17-Feb-91
* Version 5.20L by Andreas M. Kirchwitz (Fri, 13 Mar 1992)
*
*/
#include "shell.h"
#define CSH_VER "5"
#define CSH_REV "39"
static struct Window *getwindow(void);
static void exectimer(int stop);
static void set_kickversion(void);
char shellcompiled[]="Compiled: "__DATE__" "__TIME__" with "COMPILER"\n";
#if 1
char shellname[] ="Csh "CSH_VER"."CSH_REV" (public release)";
#else
char shellname[] ="Csh "CSH_VER"."CSH_REV" (BETA)";
#endif
char shellversion[] =CSH_VER""CSH_REV;
char shellvers[] =CSH_VER"."CSH_REV;
char shellv [] ="\0$VER: csh "CSH_VER"."CSH_REV" "__AMIGADATE__"";
char shellctr [] ="CshCounter";
char shellres [] ="CshResident";
char shellthere[] ="CshLoggedIn";
char *oldtitle = NULL;
char trueprompt[100];
char Inline[260];
extern struct ExecBase *SysBase; /* standard fare....*/
extern struct DosLibrary *DOSBase; /* more standard fare.... */
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *GadToolsBase;
struct Library *AslBase; /* AMK: Asl-FileRequester replaces ARP */
struct Library *BattClockBase;
struct Window *old_WindowPtr = NULL;
int oldtaskpri = -999;
BPTR OldCin;
void *PatternBase;
BOOL nologout = FALSE;
BOOL nowintitle = FALSE;
struct MsgPort *acs_oldport = NULL; /* old MsgPort */
#ifdef DO_ACS_KLUDGE
/*
* - New option "-K" (Kludge) for KingCON/ToolManager, sends DOS-Paket
* ACTION_CHANGE_SIGNAL. Don't use this option if you have no problems.
*/
int acs_kludge = 0; /* ACTION_CHANGE_SIGNAL kludge */
#endif
#ifdef MULTIUSER_SUPPORT
struct muBase *muBase; /* LILJA: Added for multiuser-support */
#endif
static char *defset[]={
v_histnum, "0",
v_titlebar, shellname,
v_hist, "50",
v_lasterr, "0",
v_stat, "0",
v_path, "RAM:,RAM:c,df0:c,df1:c,sys:system,csh:,s:",
v_rxpath, "REXX:",
v_scroll, "2",
v_minrows, "34",
v_hilite, "c7",
v_lcd, "",
v_qcd, "csh:csh-qcd",
v_insert, "1",
v_abbrev, "5",
"_terminal","",
"_man", "csh:csh.doc",
"_version", shellversion,
/* v_nomatch, "1",*/
v_prghash, "csh:csh-prgs",
NULL, NULL
};
static char *defalias[]={
"cls", "echo -n ^l",
"dswap","cd $_lcd",
"exit", "endcli;quit",
"cdir", "%q cd $q; cls; dir",
"q", "quit",
"rx", "RX",
"manlist", "search -nl $_man \" \"",
NULL, NULL
};
struct MsgPort *Console=(struct MsgPort *)-1;
long ExecTimer, ExecRC;
#ifdef __SASC
long __stack = 17500L;
#endif
main(int argc, char *argv[])
{
static ROOT locals;
BPTR fh;
int i, login=0;
char buf[10];
BOOL nologin=FALSE,nocshrc=FALSE,noclrmenu=FALSE;
#ifdef AZTEC_C
extern int Enable_Abort;
Enable_Abort = 0;
#endif
MyMem=salloc(4);
if( argc==0 ) { /* Prevent starting from workbench */
Delay(60);
exit(0);
}
Myprocess = (struct Process *)FindTask(NULL);
OldCin = Myprocess->pr_CIS;
Mycli = Cli();
/* Mycli = (struct CommandLineInterface *)((long)Myprocess->pr_CLI << 2);*/
init_mbase();
push_locals( &locals );
initmap();
if (!SysBase || SysBase->LibNode.lib_Version<37) {
printf("Sorry, you'll need at least V37 to run CSH.\n");
exit(20);
}
if (!DOSBase) {
printf("No dos library\n");
exit(20);
}
/* we do not work without it ... */
DOSBase->dl_Root->rn_Flags |= RNF_WILDSTAR;
if (!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",37L))) {
printf("No graphics library\n");
exit(20);
}
if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37L))) {
printf("No intuition library\n");
CloseLibrary((struct Library *)GfxBase);
exit(20);
}
if (!(AslBase=OpenLibrary("asl.library",37L))) {
printf("No asl library\n");
CloseLibrary((struct Library *)IntuitionBase);
CloseLibrary((struct Library *)GfxBase);
exit(20);
}
if (!(GadToolsBase=OpenLibrary("gadtools.library",37L))) {
printf("No gadtools library\n");
CloseLibrary((struct Library *)AslBase);
CloseLibrary((struct Library *)IntuitionBase);
CloseLibrary((struct Library *)GfxBase);
exit(20);
}
#ifdef MULTIUSER_SUPPORT
/* LILJA: Added for multiuser-support */
muBase = (struct muBase *) OpenLibrary("multiuser.library",39);
#endif
PatternBase = NULL; /* OpenLibrary("pattern.library",5L); */
BattClockBase = OpenResource(BATTCLOCKNAME);
set_var(LEVEL_SET,"_kick2x",(SysBase->LibNode.lib_Version>=37)?"1":"0");
set_var(LEVEL_SET,"_kick3x",(SysBase->LibNode.lib_Version>=39)?"1":"0");
set_kickversion();
if( !IsInteractive(Input())) {
o_bground=1;
Mycli->cli_Background=DOSTRUE;
} else
Mycli->cli_Background=DOSFALSE;
set_var( LEVEL_SET, v_bground, (o_bground) ? "1" : "0" );
/* We don't really need "CONSOLE:", maybe good for stderr ... */
if( fh=Open( "CONSOLE:" , MODE_NEWFILE) ) {
Console= ((struct FileHandle *)(4*fh))->fh_Type;
Close(fh);
}
Forbid();
i=0;
/* AMK: OS20-GetVar replaces ARP-Getenv, SetVar replaces Setenv */
if ( GetVar(shellres ,buf,10,GVF_GLOBAL_ONLY|GVF_BINARY_VAR) >= 0L)
o_resident=1;
if ( GetVar(shellthere,buf,10,GVF_GLOBAL_ONLY|GVF_BINARY_VAR) < 0L)
login=TRUE, SetVar(shellthere,"1",-1L,GVF_GLOBAL_ONLY|GVF_BINARY_VAR);
if ( GetVar(shellctr ,buf,10,GVF_GLOBAL_ONLY|GVF_BINARY_VAR) >= 0L)
i=atoi(buf);
sprintf(buf, "%d", i+1);
/* AMK: OS20-SetVar replaces ARP-Setenv */
SetVar(shellctr, buf, -1L, GVF_GLOBAL_ONLY|GVF_BINARY_VAR);
Permit();
#ifdef AZTEC_C
stdin->_flags |= _IONBF; /* make sure we're set as an unbuffered tty */
stdout->_flags |= _IONBF; /* in case of redirection in .login */
Close( (BPTR)_devtab[2].fd);
_devtab[2].mode |= O_STDIO;
_devtab[2].fd = _devtab[1].fd; /* set stderr to Output() otherwise */
/* don't work with aux driver */
#else
/* if( setvbuf( stdout,NULL,_IOLBF,BUFSIZ )) exit(20); */
/* setnbf( stdout ); */
/* Close( _ufbs[2] );*/
/*_ufbs[2]=_ufbs[1]; */
/* setnbf( stderr ); */
#endif
sprintf(buf,"%ld",Myprocess->pr_TaskNum);
set_var(LEVEL_SET, "_clinumber", buf);
seterr(0);
if (Myprocess->pr_CurrentDir == NULL)
execute("cd :");
set_cwd();
o_nowindow= 1;
set_var(LEVEL_SET,v_prompt, (IsInteractive(Input())) ? "%c%p> ":"");
for( i=0; defset[i]; i+=2 )
set_var( LEVEL_SET, defset[i], defset[i+1] );
for( i=0; defalias[i]; i+=2 )
set_var( LEVEL_ALIAS, defalias[i], defalias[i+1] );
o_nowindow= 0;
for (i = 1; i < argc; ++i) {
if (*argv[i]=='-' && (index(argv[i],'a') || index(argv[i],'t')))
o_nowindow=1;
if (*argv[i]=='-' && index(argv[i],'n'))
nologin = TRUE;
if (*argv[i]=='-' && index(argv[i],'N'))
nocshrc = TRUE;
if (*argv[i]=='-' && index(argv[i],'L'))
nologout = TRUE;
if (*argv[i]=='-' && index(argv[i],'M'))
noclrmenu = TRUE;
if (*argv[i]=='-' && index(argv[i],'W'))
nowintitle = TRUE;
if (*argv[i]=='-' && index(argv[i],'R'))
o_noraw = 1;
if (*argv[i]=='-' && index(argv[i],'w'))
o_nowindow = 1;
if (*argv[i]=='-' && (index(argv[i],'C') || index(argv[i],'c'))) {
noclrmenu = TRUE;
nowintitle = TRUE;
}
}
if (Mycli->cli_Background) {
o_noraw = 1;
o_nowindow = 1;
o_vt100 = 1;
}
if( !o_nowindow && (Mywindow=getwindow()) && IsInteractive(Input())) {
old_WindowPtr = Myprocess->pr_WindowPtr;
Myprocess->pr_WindowPtr = 0L/*Mywindow*/;
newwidth();
if (!nowintitle)
oldtitle=(char *)(Mywindow->Title);
if (!noclrmenu) {
/* clear menus, even if we are not the owner */
set_menu();
}
}
if (login && !nologin) {
/*printf("we're the first csh today, mon ami!\n");*/
if( exists("S:.login"))
execute("source S:.login");
}
if (!nocshrc) {
if( exists("S:.cshrc"))
execute("source S:.cshrc");
}
{
char nam1[40],nam2[40],nam3[40];
BOOL e1,e2,e3;
strcpy(nam1,"ENVARC:"); strcat(nam1,shellctr); e1=exists(nam1);
strcpy(nam2,"ENVARC:"); strcat(nam2,shellres); e2=exists(nam2);
strcpy(nam3,"ENVARC:"); strcat(nam3,shellthere); e3=exists(nam3);
if (e1 || e2 || e3) {
printf("\nWARNING: please remove the following files from ENVARC:\n\n");
if (e1)
pr