home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / driver / show / amiga / showumain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-08  |  4.4 KB  |  169 lines

  1. /*      _main.c         Copyright (C) 1985  Lattice, Inc.       */
  2. /*    modified for ShowDVI: no window when from WorkBench    */
  3.  
  4. #include <stdio.h>
  5. #include <fcntl.h>
  6. #include <ios1.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <workbench/startup.h>
  10. #include <libraries/dos.h>
  11. #include <libraries/dosextens.h>
  12. #include <clib/dos_protos.h>    /* renamed from proto/dos.h*/
  13. #include <clib/exec_protos.h>    /* renamed from proto/exec.h*/
  14. #ifndef LIBRARIES_DOSEXTENS_H        /* added*/
  15. #include <libraries/dosextens.h>    /* added*/
  16. #endif                    /* added*/
  17. extern struct DosLibrary *DOSBase;    /* added*/
  18. #include <pragmas/dos_pragmas.h>    /* added*/
  19. #include <pragmas/exec_pragmas.h>    /* added*/
  20. void main(int argc, char **argv);    /* added*/
  21.  
  22. extern struct ExecBase        *SysBase;
  23. extern struct DosLibrary    *DOSBase;
  24.  
  25.  
  26. #define MAXARG 32              /* maximum command line arguments */
  27. #define QUOTE  '"'
  28.  
  29. #define isspace(c)      ((c == ' ')||(c == '\t') || (c == '\n'))
  30.  
  31. #ifndef TINY
  32. extern int _fmode,_iomode;
  33. extern int (*_ONBREAK)();
  34. extern int CXBRK();
  35. #endif
  36.  
  37. extern struct UFB _ufbs[];
  38. int argc;                       /* arg count */
  39. char **targv, *argv[MAXARG];     /* arg pointers */
  40.  
  41. #define MAXWINDOW 40
  42. extern struct WBStartup *WBenchMsg;
  43.  
  44. /**
  45. *
  46. * name         _main - process command line, open files, and call "main"
  47. *
  48. * synopsis     _main(line);
  49. *              char *line;     ptr to command line that caused execution
  50. *
  51. * description   This function performs the standard pre-processing for
  52. *               the main module of a C program.  It accepts a command
  53. *               line of the form
  54. *
  55. *                       pgmname arg1 arg2 ...
  56. *
  57. *               and builds a list of pointers to each argument.  The first
  58. *               pointer is to the program name.  For some environments, the
  59. *               standard I/O files are also opened, using file names that
  60. *               were set up by the OS interface module XCMAIN.
  61. *
  62. **/
  63. void _main(line)
  64. register char *line;
  65. {
  66. register char **pargv;
  67. register int x;
  68. struct Process *process;
  69. struct FileHandle *handle;
  70. static char window[MAXWINDOW+18];
  71.  
  72. /*
  73. *
  74. * Build argument pointer list
  75. *
  76. */
  77. while (argc < MAXARG)
  78.         {
  79.         while (isspace(*line))  line++;
  80.         if (*line == '\0')      break;
  81.         pargv = &argv[argc++];
  82.         if (*line == QUOTE)
  83.                 {
  84.                 *pargv = ++line;  /* ptr inside quoted string */
  85.                 while ((*line != '\0') && (*line != QUOTE)) line++;
  86.                 if (*line == '\0')  _exit(1);
  87.                 else                *line++ = '\0';  /* terminate arg */
  88.                 }
  89.         else            /* non-quoted arg */
  90.                 {       
  91.                 *pargv = line;
  92.                 while ((*line != '\0') && (!isspace(*line))) line++;
  93.                 if (*line == '\0')  break;
  94.                 else                *line++ = '\0';  /* terminate arg */
  95.                 }
  96.         }  /* while */
  97. targv = (argc == 0) ? (char **)WBenchMsg : (char **)&argv[0];
  98.  
  99.  
  100. /*
  101. *
  102. * Open standard files
  103. *
  104. */
  105. #ifndef TINY
  106.  
  107. if (argc == 0)          /* running under workbench      */
  108.         {
  109. #ifdef NORMAL
  110.         strcpy(window, "con:10/10/320/80/");
  111.         strncat(window, WBenchMsg->sm_ArgList->wa_Name,MAXWINDOW);
  112. #else
  113.     /* no window, no tooltype, even with 2.0 */
  114.     strcpy(window,"NIL:");
  115. #endif
  116.         _ufbs[0].ufbfh = Open(window,MODE_NEWFILE);
  117.         _ufbs[1].ufbfh = _ufbs[0].ufbfh;
  118.         _ufbs[1].ufbflg = UFB_NC;
  119.         _ufbs[2].ufbfh = _ufbs[0].ufbfh;
  120.         _ufbs[2].ufbflg = UFB_NC;
  121. #ifdef NORMAL
  122.         handle = (struct FileHandle *)(_ufbs[0].ufbfh << 2);
  123.         process = (struct Process *)FindTask(0);
  124.         process->pr_ConsoleTask = (APTR)handle->fh_Type;
  125. #else
  126.     /* no ConsoleTask, because NIL: has none */
  127. #endif
  128.         x = 0;
  129.         }
  130. else                    /* running under CLI            */
  131.         {
  132.         _ufbs[0].ufbfh = Input();
  133.         _ufbs[1].ufbfh = Output();
  134.         _ufbs[2].ufbfh = Open("*", MODE_OLDFILE);
  135.         x = UFB_NC;                     /* do not close CLI defaults    */
  136.         }
  137.  
  138. _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  139. _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  140. _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  141.  
  142. x = (_fmode) ? 0 : _IOXLAT;
  143. stdin->_file = 0;
  144. stdin->_flag = _IOREAD | x;
  145. stdout->_file = 1;
  146. stdout->_flag = _IOWRT | x;
  147. stderr->_file = 2;
  148. stderr->_flag = _IORW | x;
  149.  
  150. /*      establish control-c handler */
  151.  
  152. _ONBREAK = CXBRK;
  153.  
  154. #endif
  155.  
  156. /*
  157. *
  158. * Call user's main program
  159. *
  160. */
  161.  
  162. main(argc,targv);              /* call main function */
  163. #ifndef TINY
  164. exit(0);
  165. #else
  166. _exit(0);
  167. #endif
  168. }
  169.