home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d107 / csh.lha / Csh / main.c < prev    next >
C/C++ Source or Header  |  1987-10-31  |  3KB  |  151 lines

  1.  
  2. /*
  3.  * MAIN.C
  4.  *
  5.  * Matthew Dillon, 24 Feb 1986
  6.  * (c)1986 Matthew Dillon     9 October 1986
  7.  *
  8.  * Version 2.07M by Steve Drew 10-Sep-87
  9.  *
  10.  */
  11.  
  12. #include "shell.h"
  13.  
  14. int aux; /* for use with aux: driver */
  15.  
  16. char Inline[260];
  17.  
  18. main(argc, argv)
  19. register char *argv[];
  20. {
  21. #if RAW_CONSOLE
  22.    char *rawgets();
  23. #endif
  24.    char *prompt;
  25.    register int i;
  26.    extern int Enable_Abort;
  27.    init_vars();
  28.    init();
  29.    seterr();
  30.    do_pwd(NULL); /* set $_cwd */
  31.  
  32.    Enable_Abort = 0;
  33.  
  34.    for (i = 1; i < argc; ++i) {
  35.       if (argv[i][0] == '-' && argv[i][1] == 'c') {
  36.         Inline[0] = ' ';
  37.         Inline[1] = '\000';
  38.         while (++i < argc) {
  39.         strcat(Inline,argv[i]);
  40.         strcat(Inline," ");
  41.         }
  42.         exec_command(Inline);
  43.         main_exit(Lastresult);
  44.         }
  45.       if (argv[i][0] == '-' && argv[i][1] == 'a') {
  46.       aux = 1;
  47.       continue;
  48.       }
  49.       strcpy (Inline, "source ");
  50.       strcat (Inline, argv[i]);
  51.       av[1] = argv[i];
  52.       do_source (Inline);
  53.    }
  54.  
  55.    for (;;) {
  56.       if ((prompt = get_var (LEVEL_SET, V_PROMPT)) == NULL)
  57.      prompt = "$ ";
  58.       if (disable)
  59.          prompt = "_ ";
  60.       if (breakcheck()) {
  61.      while (WaitForChar(Input(), 100L) || stdin->_bp < stdin->_bend)
  62.         gets(Inline);
  63.       }
  64.       clearerr(stdin);    /* prevent acidental quit */
  65. #if RAW_CONSOLE
  66.       if (Quit || !rawgets(Inline, prompt))
  67. #else
  68.       printf("%s",prompt);
  69.       fflush(stdout);
  70.       if (Quit || !gets(Inline))
  71. #endif
  72.      main_exit(0);
  73.       breakreset();
  74.       if (*Inline)
  75.      exec_command(Inline);
  76.    }
  77. }
  78.  
  79. init_vars()
  80. {
  81.    if (IsInteractive(Input()))
  82.       set_var (LEVEL_SET, V_PROMPT, "$ ");
  83.    else
  84.       set_var (LEVEL_SET, V_PROMPT, "");
  85.    set_var (LEVEL_SET, V_HIST,     "20");
  86.    set_var (LEVEL_SET, V_LASTERR, "0");
  87.    set_var (LEVEL_SET, V_PATH, "ram:,ram:c/,c:,df1:c/,df0:c/");
  88.    set_var (LEVEL_SET, "_insert", "1");
  89. }
  90.  
  91. init()
  92. {
  93.    static char pipe1[32], pipe2[32];
  94.  
  95.    stdin->_flags  |= 0x80;         /* make sure we're set as a tty */
  96.    stdout->_flags |= 0x80;       /* incase of redirection in .login */
  97.  
  98. #if RAW_CONSOLE
  99.    printf("\23312{");           /* enable window resize reports */
  100. #endif
  101.    Close(_devtab[2].fd);
  102.    _devtab[2].mode |= O_STDIO;
  103.    _devtab[2].fd = _devtab[1].fd;  /* set stderr to Output() otherwise */
  104.                    /* don't work with aux driver       */
  105.  
  106.    Myprocess = (struct Process *)FindTask(0L);
  107.    Uniq     = (long)Myprocess;
  108.    Pipe1 = pipe1;
  109.    Pipe2 = pipe2;
  110.    sprintf (pipe1, "ram:pipe1_%ld", Uniq);
  111.    sprintf (pipe2, "ram:pipe2_%ld", Uniq);
  112. }
  113.  
  114.  
  115. main_exit(n)
  116. {
  117.    exit (n);
  118. }
  119.  
  120. breakcheck()
  121. {
  122.    return (int)(SetSignal(0L,0L) & SIGBREAKF_CTRL_C);
  123. }
  124.  
  125. breakreset()
  126. {
  127.    SetSignal(0L, SIGBREAKF_CTRL_C);
  128. }
  129.  
  130. dobreak()
  131. {
  132.    if (breakcheck()) {
  133.        printf("^C\n");
  134.        return(1);
  135.    }
  136.    return(0);
  137. }
  138.  
  139. /* this routine causes manx to use this Chk_Abort() rather than it's own */
  140. /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
  141. /* is zero).  Since we want to check for our own ^C's             */
  142.  
  143. Chk_Abort()
  144. {
  145. return(0);
  146. }
  147.  
  148. _wb_parse()
  149. {
  150. }
  151.