home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk373.lzh / Multiplot / source / mplot_src / src.zoo / main.c < prev    next >
C/C++ Source or Header  |  1990-08-02  |  4KB  |  147 lines

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