home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 122.lha / Arp_v1.1 / Libraries / Lattice_SRC / _arpmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-20  |  3.1 KB  |  124 lines

  1. /*  _arpmain.c -- Startup code for arp.library under Lattice.
  2.  *
  3.  * Modified from _main.c supplied by Lattice Inc.
  4.  * Copyright (c) 1988 by Scott Ballantyne
  5.  * Freely useable (at your own risk, of course).
  6.  *
  7.  * Lattice now has an arp 'wrapper', like manx does, so most if not
  8.  * all of the native compiler libraries and features can be used,
  9.  * including onexit()
  10.  * SDB 
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <fcntl.h>
  15. #include <ios1.h>
  16. #include <string.h>
  17.  
  18. #include <exec/alerts.h>
  19. #include <workbench/startup.h>
  20. #include <libraries/dos.h>
  21. #include <libraries/dosextens.h>
  22. #include "libraries/arpbase.h"
  23. #include <proto/dos.h>
  24. #include <proto/exec.h>
  25. #include "arpfunctions.h"
  26.  
  27. extern int _fmode,_iomode;
  28. extern int (*_ONBREAK)();
  29. extern int CXBRK();
  30.  
  31. extern char *CLI_Template;
  32. extern char *CLI_Help;
  33.  
  34. extern struct DosLibrary *DOSBase;
  35.  
  36. extern struct UFB _ufbs[];
  37. int argc;                       /* arg count */
  38. char *targv;
  39.  
  40. #define MAXWINDOW 40
  41. extern struct WBStartup *WBenchMsg;
  42.  
  43. /* If a WB process, line is a pointer to NULL, otherwise, is a pointer
  44.  * to a reconstructed command line.
  45.  */
  46.  
  47. void _main(line)
  48. register char *line;
  49. {
  50.     register char **pargv;
  51.     register char *c;
  52.     register int x;
  53.  
  54.     if ( *line != '\0' )
  55.     {
  56.         /* Argument parsing alla GADS(): calc sizeof(argv) we need */
  57.         for (x = 3, c = CLI_Template; *c; c++)
  58.             if (*c == ',')
  59.                 x++;
  60.         /* Following line will give a warning, just ignore it,
  61.          * lattice is *so* stupid sometimes.
  62.          */
  63.         if ( (pargv = (char **)ArpAlloc( x * sizeof(*pargv))) == NULL)
  64.             exit(20);
  65.         pargv[0] = line;    /* Program name */
  66.         while ( *line > ' ')    /* Advance to first command */
  67.             line++;
  68.         *line++ = '\0';
  69.  
  70.         argc = GADS(line, strlen(line), CLI_Help, (pargv+1), CLI_Template);
  71.         if (argc < 0 )
  72.         {
  73.             Printf("Bad Args for %s: %s\n", pargv[0], pargv[1]);
  74.             exit(20);
  75.         }
  76.         argc++;
  77.  
  78.             _ufbs[0].ufbfh = Input();
  79.             _ufbs[1].ufbfh = Output();
  80.             _ufbs[2].ufbfh = Open("*", MODE_OLDFILE);
  81.             x = UFB_NC;                     /* do not close CLI defaults    */
  82.     }
  83.     else /* From WorkBench */
  84.     {
  85.         struct Process *process;
  86.         struct FileHandle *handle;
  87.         static char window[MAXWINDOW+18];
  88.  
  89.         argc = 0;
  90.         pargv = (char **)WBenchMsg;
  91.             strcpy(window, "con:10/10/320/80/");
  92.             strncat(window, WBenchMsg->sm_ArgList->wa_Name,MAXWINDOW);
  93.             _ufbs[0].ufbfh = Open(window,MODE_NEWFILE);
  94.             _ufbs[1].ufbfh = _ufbs[0].ufbfh;
  95.             _ufbs[1].ufbflg = UFB_NC;
  96.             _ufbs[2].ufbfh = _ufbs[0].ufbfh;
  97.             _ufbs[2].ufbflg = UFB_NC;
  98.             handle = (struct FileHandle *)(_ufbs[0].ufbfh << 2);
  99.             process = (struct Process *)FindTask(0);
  100.             process->pr_ConsoleTask = (APTR)handle->fh_Type;
  101.             x = 0;
  102.     }
  103.  
  104.     _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  105.     _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  106.     _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  107.  
  108.     x = (_fmode) ? 0 : _IOXLAT;
  109.     stdin->_file = 0;
  110.     stdin->_flag = _IOREAD | x;
  111.     stdout->_file = 1;
  112.     stdout->_flag = _IOWRT | x;
  113.     stderr->_file = 2;
  114.     stderr->_flag = _IORW | x;
  115.  
  116.     /*      establish control-c handler */
  117.  
  118.     _ONBREAK = CXBRK;
  119.  
  120.     main(argc,targv = (char *)pargv);              /* call main function */    
  121.     exit(0);
  122. }
  123.  
  124.