home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Extra 1997 #5 / AmigaPlus_Extra-CD_5-97.iso / online-tools / mail / pgp_mip / pgpsendmail / source / rcs / main.c,v < prev    next >
Encoding:
Text File  |  1993-10-06  |  8.5 KB  |  391 lines

  1. head    1.4;
  2. access;
  3. symbols;
  4. locks
  5.         simons:1.4; strict;
  6. comment @ * @;
  7.  
  8.  
  9. 1.4
  10. date    93.10.06.12.19.18;      author simons;  state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    93.09.14.17.20.14;      author simons;  state Stab;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    93.09.14.17.10.14;      author simons;  state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    93.09.14.17.04.08;      author simons;  state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @__main() is a replacement for the standard startup-code, usually
  32. linked to C programs. This one provides the unparsed commandline
  33. to the main program and does not support the Workbench message.
  34. @
  35.  
  36.  
  37. 1.4
  38. log
  39. @Changed format of RCS-Header.
  40. @
  41. text
  42. @/*
  43.  *     $Filename: main.c $
  44.  *     $Revision: 1.3 $
  45.  *     $Date: 1993/09/14 17:20:14 $
  46.  *
  47.  *     __main() is a replacement for the standard startup-code, usually
  48.  *     linked to C programs. This one provides the unparsed commandline
  49.  *     to the main program and does not support the Workbench message.
  50.  *
  51.  *
  52.  *     © Copyright 1993 Peter Simons, Germany
  53.  *       All Rights Reserved
  54.  *
  55.  *     $Id: main.c,v 1.3 1993/09/14 17:20:14 simons Stab simons $
  56.  *
  57.  * ------------------------------ log history ----------------------------
  58.  * $Log: main.c,v $
  59.  * Revision 1.3  1993/09/14  17:20:14  simons
  60.  * Removed any Workbench-startup and commandline parsing stuff.
  61.  * The `real' main() now gets the unparsed commandline.
  62.  *
  63.  * Revision 1.2  1993/09/14  17:10:14  simons
  64.  * Added RCSId string and removed the TINY-stuff.
  65.  *
  66.  * Revision 1.1  1993/09/14  17:04:08  simons
  67.  * Initial revision
  68.  */
  69.  
  70. #include <stdio.h>
  71. #include <fcntl.h>
  72. #include <ios1.h>
  73. #include <string.h>
  74. #include <stdlib.h>
  75. #include <time.h>
  76. #include <workbench/startup.h>
  77. #include <libraries/dos.h>
  78. #include <libraries/dosextens.h>
  79. #include <proto/dos.h>
  80. #include <proto/exec.h>
  81. #include <exec/execbase.h>
  82.  
  83. extern int __fmode;
  84.  
  85. int main(char *);
  86.  
  87.         static const char __RCSId[] = "$Id: main.c,v 1.3 1993/09/14 17:20:14 simons Stab simons $";
  88.  
  89. void __stdargs __main(char *line)
  90. {
  91.         int ret, x;
  92.         struct UFB  ufbs[3];
  93.  
  94.  
  95.         /* Open standard files. */
  96.  
  97.         ufbs[0].ufbnxt = &ufbs[1];
  98.         ufbs[1].ufbnxt = &ufbs[2];
  99.         ufbs[2].ufbnxt = NULL;
  100.         __ufbs = &ufbs[0];
  101.         ufbs[0].ufbfn = NULL;
  102.         ufbs[1].ufbfn = NULL;
  103.         ufbs[2].ufbfn = NULL;
  104.         ufbs[0].ufbflg = UFB_RA | O_RAW | UFB_NC;
  105.         ufbs[1].ufbflg = UFB_WA | O_RAW | UFB_NC;
  106.         ufbs[2].ufbflg = UFB_WA | O_RAW | UFB_NC | UFB_CLO;
  107.  
  108.         ufbs[0].ufbfh = Input();
  109.         ufbs[1].ufbfh = Output();
  110.         if ((ufbs[2].ufbfh = Open("*", MODE_OLDFILE)) == NULL)
  111.                 ufbs[2].ufbfh = Open("NIL:", MODE_OLDFILE);
  112.  
  113.         __nufbs += 3;
  114.  
  115.         x = (__fmode) ? 0 : _IOXLAT;
  116.         stdin->_file = 0;
  117.         stdin->_flag = _IOREAD | x;
  118.         stdout->_file = 1;
  119.         stdout->_flag = _IOWRT | _IOLBF | x;
  120.         stderr->_file = 2;
  121.         stderr->_flag = _IOWRT | _IOLBF | x;
  122.  
  123.  
  124.         /* Call user's main program! */
  125.  
  126.         ret = main(line);                /* call main function */
  127.         exit(ret);
  128. }
  129. @
  130.  
  131.  
  132. 1.3
  133. log
  134. @Removed any Workbench-startup and commandline parsing stuff.
  135. The `real' main() now gets the unparsed commandline.
  136. @
  137. text
  138. @d1 27
  139. a27 23
  140. /**
  141.  **     $Filename: main.c $
  142.  **     $Revision: 1.2 $
  143.  **     $Date: 1993/09/14 17:10:14 $
  144.  **
  145.  **     __main() is a replacement for the standard startup-code, usually
  146.  **     linked to C programs. This one provides the unparsed commandline
  147.  **     to the main program and does not support the Workbench message.
  148.  **
  149.  **
  150.  **     © Copyright 1993 Peter Simons, Germany
  151.  **       All Rights Reserved
  152.  **
  153.  **     $Id: main.c,v 1.2 1993/09/14 17:10:14 simons Exp simons $
  154.  **
  155.  ** ------------------------------ log history ----------------------------
  156.  ** $Log: main.c,v $
  157.  ** Revision 1.2  1993/09/14  17:10:14  simons
  158.  ** Added RCSId string and removed the TINY-stuff.
  159.  **
  160.  ** Revision 1.1  1993/09/14  17:04:08  simons
  161.  ** Initial revision
  162.  **/
  163. d46 1
  164. a46 1
  165.         static const char __RCSId[] = "$Id: main.c,v 1.2 1993/09/14 17:10:14 simons Exp simons $";
  166. @
  167.  
  168.  
  169. 1.2
  170. log
  171. @Added RCSId string and removed the TINY-stuff.
  172. @
  173. text
  174. @d3 2
  175. a4 2
  176.  **     $Revision: 1.1 $
  177.  **     $Date: 1993/09/14 17:04:08 $
  178. d14 1
  179. a14 1
  180.  **     $Id$
  181. d18 3
  182. d38 1
  183. a38 1
  184. extern struct ExecBase *SysBase;
  185. d40 1
  186. a40 6
  187. #define MAXARG 32
  188. #define QUOTE       '"'
  189. #define MAXWINDOW   40
  190. #define ESCAPE '*'
  191. #define ESC '\027'
  192. #define NL '\n'
  193. d42 1
  194. a42 1
  195. #define isspace(c)      ((c == ' ')||(c == '\t') || (c == '\n'))
  196. d44 4
  197. a47 5
  198.  
  199. extern int __fmode;
  200.  
  201. extern char __stdiowin[];
  202. extern char __stdiov37[];
  203. a48 2
  204. extern struct WBStartup *_WBenchMsg;
  205. int main(int, void *);
  206. d50 1
  207. a50 2
  208. static int argc;                            /* arg count */
  209. static char **targv, *argv[MAXARG+1];       /* arg pointers */
  210. d52 10
  211. a62 111
  212.         static const char __RCSId[] = "$Id$";
  213.  
  214. void __stdargs __main(line)
  215.     char *line;
  216. {
  217.     char **pargv;
  218.     char *argbuf;
  219.     int ret;
  220.  
  221.  
  222.     int x;
  223.     struct Process *process;
  224.     struct FileHandle *handle;
  225.     struct UFB  ufbs[3];
  226.     static char window[MAXWINDOW+18];
  227.  
  228.  
  229. /***
  230. *     Build argument pointer list
  231. ***/
  232.    while (argc < MAXARG)
  233.    {
  234.         while (isspace(*line))  line++;
  235.         if (*line == '\0')      break;
  236.         pargv = &argv[argc++];
  237.         if (*line == QUOTE)
  238.         {
  239.             argbuf = *pargv = ++line;  /* ptr inside quoted string */
  240.             while (*line != QUOTE && *line != 0)
  241.             {
  242.                if (*line == ESCAPE)
  243.                {
  244.                   line++;
  245.                   switch (*line)
  246.                   {
  247.                      case '\0':
  248.                         *argbuf = 0;
  249.                         goto linedone;
  250.                      case 'E':
  251.                         *argbuf++ = ESC;
  252.                         break;
  253.                      case 'N':
  254.                         *argbuf++ = NL;
  255.                         break;
  256.                      default:
  257.                         *argbuf++ = *line;
  258.                   }
  259.                   line++;
  260.                }
  261.                else
  262.                {
  263.                  *argbuf++ = *line++;
  264.                }
  265.             }
  266.             line++;
  267.             *argbuf++ = '\0'; /* terminate arg */
  268.         }
  269.         else            /* non-quoted arg */
  270.         {
  271.             *pargv = line;
  272.             while ((*line != '\0') && (!isspace(*line))) line++;
  273.             if (*line == '\0')  break;
  274.             else                *line++ = '\0';  /* terminate arg */
  275.         }
  276.    }  /* while */
  277.  
  278. linedone:
  279.  
  280.     targv = (argc == 0) ? (char **) _WBenchMsg : (char **) &argv[0];
  281.  
  282.  
  283. /***
  284. *     Open standard files
  285. ***/
  286.  
  287.     ufbs[0].ufbnxt = &ufbs[1];
  288.     ufbs[1].ufbnxt = &ufbs[2];
  289.     ufbs[2].ufbnxt = NULL;
  290.     __ufbs = &ufbs[0];
  291.     ufbs[0].ufbfn = NULL;
  292.     ufbs[1].ufbfn = NULL;
  293.     ufbs[2].ufbfn = NULL;
  294.     ufbs[0].ufbflg = UFB_RA | O_RAW | UFB_NC;
  295.     ufbs[1].ufbflg = UFB_WA | O_RAW | UFB_NC;
  296.     ufbs[2].ufbflg = UFB_WA | O_RAW | UFB_NC | UFB_CLO;
  297.  
  298.     if (argc == 0)
  299.     {             /* running under workbench      */
  300.         if (_WBenchMsg->sm_ToolWindow)
  301.             ufbs[0].ufbfh = Open(_WBenchMsg->sm_ToolWindow, MODE_NEWFILE);
  302.         else
  303.         {
  304.            strcpy(window, __stdiowin);
  305.            strncat(window, _WBenchMsg->sm_ArgList->wa_Name, MAXWINDOW);
  306.  
  307.            if (SysBase->LibNode.lib_Version >= 36)
  308.               strncat(window, __stdiov37, MAXWINDOW+18-strlen(window)-1);
  309.  
  310.            ufbs[0].ufbfh = Open(window, MODE_NEWFILE);
  311.         }
  312.  
  313.         ufbs[0].ufbflg |= UFB_CLO;
  314.         handle = (struct FileHandle *) (ufbs[0].ufbfh << 2);
  315.         process = (struct Process *) FindTask(0);
  316.         process->pr_ConsoleTask = (APTR) handle->fh_Type;
  317.         if ((ufbs[1].ufbfh = Open("*", MODE_OLDFILE)) == NULL)
  318.              ufbs[1].ufbfh = Open("NIL:", MODE_OLDFILE);
  319.         ufbs[2].ufbfh = ufbs[1].ufbfh;
  320.     }
  321.     else
  322.     {                     /* running under CLI            */
  323. d66 1
  324. a66 14
  325.              ufbs[2].ufbfh = Open("NIL:", MODE_OLDFILE);
  326.     }
  327.  
  328.  
  329.     __nufbs += 3;
  330.  
  331.  
  332.     x = (__fmode) ? 0 : _IOXLAT;
  333.     stdin->_file = 0;
  334.     stdin->_flag = _IOREAD | x;
  335.     stdout->_file = 1;
  336.     stdout->_flag = _IOWRT | _IOLBF | x;
  337.     stderr->_file = 2;
  338.     stderr->_flag = _IOWRT | _IOLBF | x;
  339. d68 1
  340. d70 7
  341. a77 3
  342. /***
  343. *     Call user's main program
  344. ***/
  345. d79 1
  346. a79 1
  347.     ret = main(argc, targv);                /* call main function */
  348. d81 2
  349. a82 1
  350.     exit(ret);
  351. @
  352.  
  353.  
  354. 1.1
  355. log
  356. @Initial revision
  357. @
  358. text
  359. @d3 2
  360. a4 2
  361.  **     $Revision$
  362.  **     $Date$
  363. d14 1
  364. a14 1
  365.  **     $Id§
  366. d17 3
  367. a19 1
  368.  ** $Log$
  369. a46 1
  370. #ifndef TINY
  371. a47 1
  372. #endif
  373. d59 1
  374. a60 1
  375.  
  376. a68 1
  377. #ifndef TINY
  378. a73 1
  379. #endif
  380. a133 1
  381. #ifndef TINY
  382. a187 1
  383. #endif
  384. a195 1
  385. #ifndef TINY
  386. a196 3
  387. #else
  388.     __exit(ret);
  389. #endif
  390. @
  391.