home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 182.lha / CShell_v3.0a / main.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  5KB  |  187 lines

  1. /*
  2.  * MAIN.C
  3.  *
  4.  * Matthew Dillon, 24 Feb 1986
  5.  * (c)1986 Matthew Dillon     9 October 1986
  6.  *
  7.  * Version 2.07M by Steve Drew 10-Sep-87
  8.  *
  9.  * Version 3.00A by Carlo Borreo & Cesare Dieni 30-Oct-88
  10.  *
  11.  */
  12.  
  13. char *shellctr="CshCounter";
  14.  
  15. extern char *v_titlebar, *v_prompt, *v_hist, *v_lasterr, *v_path;
  16.  
  17. int aux; /* for use with aux: driver */
  18. char *oldtitle;
  19. char trueprompt[100];
  20. char Inline[260];
  21. struct IntuitionBase *IntuitionBase;
  22. struct Window *w;
  23. struct ArpBase *ArpBase;
  24.  
  25. main(argc, argv)
  26. register char *argv[];
  27. {
  28. #if RAW_CONSOLE
  29.     char *rawgets();
  30. #endif
  31.  
  32. register unsigned int i;
  33. extern int Enable_Abort;
  34. char buf[10];
  35.  
  36. ArpBase=(struct ArpBase *)OpenLibrary("arp.library",34L);
  37. if (ArpBase==NULL) { printf("No arp library\n"); exit(0); }
  38.  
  39. Forbid();
  40. i=Errno=0;
  41. if (Getenv(shellctr,buf,10L)) {
  42.     i=(int)(long)Atol(buf);
  43.     if (Errno) i=0;
  44.     }
  45. sprintf(buf,"%d",i+1);
  46. Setenv(shellctr,buf);
  47. Permit();
  48.  
  49. IntuitionBase=(struct IntuitionBase *)ArpBase->IntuiBase;
  50. w=IntuitionBase->ActiveWindow;
  51. oldtitle=(char *)(w->Title);
  52.  
  53. set_var(LEVEL_SET, v_titlebar, "CShell V3.00A");
  54. set_var(LEVEL_SET, v_prompt,
  55.     (IsInteractive(Input())) ? "\23337m%p> \2330m" : "");
  56. set_var(LEVEL_SET, v_hist, "20");
  57. set_var(LEVEL_SET, v_lasterr, "0");
  58. set_var(LEVEL_SET, v_path, "RAM:,RAM:c/,df0:c/,df1:c/,df0:,df1:,sys:system/");
  59. set_var(LEVEL_SET, "_insert", "1");
  60. set_var(LEVEL_SET, "f1", "cdir df0:\15");
  61. set_var(LEVEL_SET, "F1", "cdir df1:\15");
  62. set_var(LEVEL_SET, "f3", "cdir RAM:\15");
  63. set_var(LEVEL_SET, "F3", "cdir vd0:\15");
  64. set_var(LEVEL_SET, "f4", "cd df0:\15");
  65. set_var(LEVEL_SET, "F4", "cd df1:\15");
  66. set_var(LEVEL_SET, "f5", "cls; ls\15");
  67. set_var(LEVEL_SET, "F5", "cdir ");
  68. set_var(LEVEL_SET, "f6", "lc\15");
  69. set_var(LEVEL_SET, "f7", "info\15");
  70. set_var(LEVEL_SET, "F7", "assign \15");
  71. set_var(LEVEL_SET, "f8", "window -lf\15");
  72. set_var(LEVEL_SET, "F8", "window -sb\15");
  73. set_var(LEVEL_SET, "f10", "cls\15");
  74. set_var(LEVEL_SET, "F10", "exit\15");
  75. set_var(LEVEL_ALIAS, "cls", "echo -n ^l");
  76. set_var(LEVEL_ALIAS, "lc", "ls -s");
  77. set_var(LEVEL_ALIAS, "kr", "rm -r RAM:* >NIL:");
  78. set_var(LEVEL_ALIAS, "cdir", "%q cd $q; cls; dir");
  79. set_var(LEVEL_ALIAS, "exit", "endcli;quit");
  80. set_var(LEVEL_ALIAS, "lp", "cat >PRT:");
  81. init();
  82. seterr();
  83. do_pwd(NULL); /* set $_cwd */
  84. Enable_Abort = 0;
  85. for (i = 1; i < argc; ++i) {
  86.     if (!strcmp(argv[i],"-c")) {
  87.         Inline[0] = ' ';
  88.         Inline[1] = '\0';
  89.         while (++i < argc)
  90.             { strcat(Inline,argv[i]); strcat(Inline," "); }
  91.         exec_command(Inline);
  92.         main_exit(Lastresult);
  93.         }
  94.     if (!strcmp(argv[i],"-a")) { aux = 1; continue; }
  95.     sprintf (Inline, "source %s",argv[i]);
  96.     av[1] = argv[i];
  97.     do_source (Inline);
  98.     }
  99. for (;;) {
  100.    if (breakcheck())
  101.     while (WaitForChar(Input(), 100L) || stdin->_bp < stdin->_bend)
  102.         gets(Inline);
  103.    clearerr(stdin);  /* prevent acidental quit */
  104. #if RAW_CONSOLE
  105.    if (Quit || !rawgets(Inline, disable ? "_ " : trueprompt)) main_exit(0);
  106. #else
  107.    printf("%s", disable ? "_ " : trueprompt);
  108.    fflush(stdout);
  109.    if (Quit || !gets(Inline)) main_exit(0);
  110. #endif
  111.    breakreset();
  112.    if (*Inline) exec_command(Inline);
  113.    }
  114. }
  115.  
  116. main_exit(n)
  117. {
  118. register unsigned short i;
  119. char buf[10];
  120.  
  121. Getenv(shellctr,buf,10L);
  122. i=(int)Atol(buf);
  123. sprintf(buf,"%d",i-1);
  124. Setenv(shellctr,buf);
  125. SetWindowTitles(w,oldtitle,-1L);
  126. for (i=1; i<MAXMYFILES; i++) myclose(i);
  127. ArpExit(0L,0L);            /* Intuition need not to be closed */
  128. }
  129.  
  130. init()
  131. {
  132. static char pipe1[32], pipe2[32];
  133.  
  134. stdin->_flags    |= 0x80;    /* make sure we're set as a tty */
  135. stdout->_flags    |= 0x80;    /* in case of redirection in .login */
  136. #if RAW_CONSOLE
  137.     printf("\23312{");    /* enable window resize reports */
  138. #endif
  139. Close(_devtab[2].fd);
  140. _devtab[2].mode |= O_STDIO;
  141. _devtab[2].fd = _devtab[1].fd;    /* set stderr to Output() otherwise */
  142.         /* don't work with aux driver */
  143. Myprocess = (struct Process *)FindTask(0L);
  144. Mycli=(struct CommandLineInterface *)((long)Myprocess->pr_CLI << 2);
  145. Pipe1 = pipe1;
  146. Pipe2 = pipe2;
  147. sprintf(pipe1, "ram:pipe1_%ld", Myprocess);
  148. sprintf(pipe2, "ram:pipe2_%ld", Myprocess);
  149. }
  150.  
  151. breakcheck()
  152. {
  153. return (int)(SetSignal(0L,0L) & SIGBREAKF_CTRL_C);
  154. }
  155.  
  156. breakreset()
  157. {
  158. SetSignal(0L, SIGBREAKF_CTRL_C);
  159. }
  160.  
  161. dobreak()
  162. {
  163. if (breakcheck()) { printf("^C\n"); return(1); }
  164. return(0);
  165. }
  166.  
  167. /* this routine causes manx to use this Chk_Abort() rather than it's own */
  168. /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
  169. /* is zero).  Since we want to check for our own ^C's             */
  170.  
  171. Chk_Abort()
  172. {
  173. return(0);
  174. }
  175.  
  176. _wb_parse()
  177. {
  178. }
  179.  
  180. do_howmany()
  181. {
  182. char buf[10];
  183.  
  184. Getenv(shellctr, buf, 10L);
  185. printf("Shell(s) running: %s\n",buf);
  186. }
  187.