home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / diskutil / disktest.lha / source / umain.c < prev   
Encoding:
C/C++ Source or Header  |  1992-05-21  |  4.4 KB  |  160 lines

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