home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / texmf / source / driver / print / amiga / PrintUmain.c < prev   
Encoding:
C/C++ Source or Header  |  1991-11-08  |  6.3 KB  |  242 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.  
  12. #include <exec/execbase.h>        /* added*/
  13. #include <clib/dos_protos.h>    /* renamed from proto/dos.h*/
  14. #include <clib/exec_protos.h>    /* renamed from proto/exec.h*/
  15. #include <clib/icon_protos.h>        /* added*/
  16. #ifndef LIBRARIES_DOSEXTENS_H        /* added*/
  17. #include <libraries/dosextens.h>    /* added*/
  18. #endif                    /* added*/
  19. extern struct DosLibrary *DOSBase;    /* added*/
  20. extern struct Library    *IconBase;    /* added*/
  21. #include <pragmas/dos_pragmas.h>    /* added*/
  22. #include <pragmas/exec_pragmas.h>    /* added*/
  23. #include <pragmas/icon_pragmas.h>    /* added*/
  24. void main(int argc, char **argv);    /* added*/
  25.  
  26. extern struct ExecBase        *SysBase;
  27. extern struct DosLibrary    *DOSBase;
  28.  
  29.  
  30. #define MAXARG 32
  31. #define QUOTE  '"'
  32. #define ESCAPE '*'
  33. #define ESC '\027'
  34. #define NL '\n'
  35.  
  36. #define isspace(c)      ((c == ' ')||(c == '\t') || (c == '\n'))
  37.  
  38. #ifndef TINY
  39. extern int _fmode,_iomode;
  40. extern int (*_ONBREAK)();
  41. extern int CXBRK();
  42. #endif
  43.  
  44. extern struct UFB _ufbs[];
  45. extern void main(int, char**);
  46. static int argc;                       /* arg count */
  47. static char **targv, *argv[MAXARG];   /* arg pointers */
  48. static void badarg(char *program);
  49.  
  50. #define MAXWINDOW 80    /* 40 */
  51. extern struct WBStartup *WBenchMsg;
  52. /**
  53. *
  54. * name         _main - process command line, open files, and call "main"
  55. *
  56. * synopsis     _main(line);
  57. *              char *line;     ptr to command line that caused execution
  58. *
  59. * description   This function performs the standard pre-processing for
  60. *               the main module of a C program.  It accepts a command
  61. *               line of the form
  62. *
  63. *                       pgmname arg1 arg2 ...
  64. *
  65. *               and builds a list of pointers to each argument.  The first
  66. *               pointer is to the program name.  For some environments, the
  67. *               standard I/O files are also opened, using file names that
  68. *               were set up by the OS interface module XCMAIN.
  69. *
  70. **/
  71. void _main(line)
  72. register char *line;
  73. {
  74.    register char **pargv;
  75.    register int x;
  76.    struct Process *process;
  77.    struct FileHandle *handle;
  78.    static char window[MAXWINDOW+18+16];        /* +16 fuer "/CLOSE/AUTO/WAIT"*/
  79.    char *argbuf;
  80.  
  81. /*
  82. *
  83. * Build argument pointer list
  84. *
  85. */
  86.    
  87.    while (argc < MAXARG)
  88.    {
  89.         while (isspace(*line))  line++;
  90.         if (*line == '\0')      break;
  91.         pargv = &argv[argc++];
  92.         if (*line == QUOTE)
  93.         {
  94.             argbuf = *pargv = ++line;  /* ptr inside quoted string */
  95.             while (*line != QUOTE && *line != 0)
  96.             {
  97.                if (*line == ESCAPE)
  98.                {
  99.                   line++;
  100.                   switch (*line)
  101.                   {
  102.                      case '0':
  103.                         *argbuf = 0;
  104.                         goto linedone;
  105.                      case 'E':
  106.                         *argbuf++ = ESC;
  107.                         break;
  108.                      case 'N':
  109.                         *argbuf++ = NL;
  110.                         break;
  111.                      default:
  112.                         *argbuf++ = *line;
  113.                   }
  114.                   line++;
  115.                }
  116.                else
  117.                {
  118.                  *argbuf++ = *line++;
  119.                }
  120.             }
  121.             line++;
  122.             *argbuf++ = '\0'; /* terminate arg */
  123.         }
  124.         else            /* non-quoted arg */
  125.         {       
  126.             *pargv = line;
  127.             while ((*line != '\0') && (!isspace(*line))) line++;
  128.             if (*line == '\0')  break;
  129.             else                *line++ = '\0';  /* terminate arg */
  130.         }
  131.    }  /* while */
  132.  
  133. linedone:
  134.  
  135.    targv = (argc == 0) ? (char **)WBenchMsg : (char **)&argv[0];
  136.  
  137.  
  138. /*
  139. *
  140. * Open standard files
  141. *
  142. */
  143. #ifndef TINY
  144.  
  145.    if (argc == 0)          /* running under workbench      */
  146.    {
  147. #ifdef NORMAL
  148.         strcpy(window, "con:10/10/320/80/");
  149.         strncat(window, WBenchMsg->sm_ArgList->wa_Name,MAXWINDOW);
  150. #else
  151.     int os37 = SysBase->LibNode.lib_Version >= 37;
  152.     char *name = NULL;
  153.     int donil;
  154.  
  155.     window[0] = '\0';
  156.     IconBase = OpenLibrary("icon.library", 0L);
  157.     if (IconBase != NULL) {
  158.       struct DiskObject *dobject;
  159.       /* gibt es immer sm_ArgList->... ?*/
  160.       if (dobject = GetDiskObject(WBenchMsg->sm_ArgList->wa_Name)) {
  161.         name = FindToolType(dobject->do_ToolTypes, "WINDOW");
  162.         /* z.B. WINDOW=CON:0/0/500/100/DVIprint, oder WINDOW=NIL:*/
  163.         if (name) strncpy(window, name, MAXWINDOW);
  164.         FreeDiskObject(dobject);
  165.       }
  166.       CloseLibrary(IconBase);
  167.       IconBase = NULL;
  168.     }
  169.  
  170.     if (!name) {
  171.           strcpy(window, "CON:8/10/540/90/");
  172.           strcat(window, WBenchMsg->sm_ArgList->wa_Name);
  173.       if (os37) strcat(window, "/CLOSE/AUTO/WAIT");
  174.     }
  175.  
  176.     if (stricmp(window, "NIL:") != 0) {
  177.       donil = 0;
  178.     }
  179.     else {
  180.       donil = 1;
  181.     }
  182. #endif
  183.         _ufbs[0].ufbfh = Open(window,MODE_NEWFILE);
  184.         _ufbs[1].ufbfh = _ufbs[0].ufbfh;
  185.         _ufbs[1].ufbflg = UFB_NC;
  186.         _ufbs[2].ufbfh = _ufbs[0].ufbfh;
  187.         _ufbs[2].ufbflg = UFB_NC;
  188. #ifdef NORMAL
  189.         handle = (struct FileHandle *)(_ufbs[0].ufbfh << 2);
  190.         process = (struct Process *)FindTask(0);
  191.         process->pr_ConsoleTask = (APTR)handle->fh_Type;
  192. #else
  193.     /* prueft Lattice nicht, ob Open erfolgreich war?!*/
  194.     if (!donil) {    /* NIL: has no ConsoleTask */
  195.           handle = (struct FileHandle *)(_ufbs[0].ufbfh << 2);
  196.           process = (struct Process *)FindTask(0);
  197.           process->pr_ConsoleTask = (APTR)handle->fh_Type;
  198.     }
  199. #endif
  200.         x = 0;
  201.    }
  202.    else                    /* running under CLI            */
  203.    {
  204.         _ufbs[0].ufbfh = Input();
  205.         _ufbs[1].ufbfh = Output();
  206.         if ((_ufbs[2].ufbfh = Open("*", MODE_OLDFILE)) == NULL)
  207.              _ufbs[2].ufbfh = Open("NIL:", MODE_OLDFILE);
  208.         x = UFB_NC;                     /* do not close CLI defaults    */
  209.    }
  210.  
  211.    _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  212.    _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  213.    _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  214.  
  215.    x = (_fmode) ? 0 : _IOXLAT;
  216.    stdin->_file = 0;
  217.    stdin->_flag = _IOREAD | x;   
  218.    stdout->_file = 1;
  219.    stdout->_flag = _IOWRT | x;
  220.    stderr->_file = 2;
  221.    stderr->_flag = _IORW | x;
  222.  
  223. /*      establish control-c handler */
  224.  
  225. _ONBREAK = CXBRK;
  226.  
  227. #endif
  228.  
  229. /*
  230. *
  231. * Call user's main program
  232. *
  233. */
  234.  
  235.    main(argc,targv);              /* call main function */
  236. #ifndef TINY
  237.    exit(0);
  238. #else
  239. _  exit(0);
  240. #endif
  241. }
  242.