home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-1.LHA / CLISP960530-sr.lha / amiga / jchlib / startup / wbmain.c < prev   
Encoding:
C/C++ Source or Header  |  1996-07-09  |  4.5 KB  |  139 lines

  1. /* Tiny GCC Library
  2.  * Jörg Höhle, 9-Jul-96
  3.  */
  4.  
  5. #include "defs.h"
  6. #include <exec/libraries.h>
  7. #include <workbench/startup.h>
  8. #include <workbench/icon.h>
  9. #include <workbench/workbench.h>
  10.  
  11. struct Library * IconBase = NULL;
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #define BASE_EXT_DECL    /* no const declaration with old GCC function inlines */
  16. #include <proto/icon.h>
  17.  
  18. /* FALSE for standard code (def_window.c), TRUE for CLISP (through clisp.c) */
  19. extern BOOL  _CLISP_glue;
  20.  
  21. /* These are pulled from the library unless you define them (see clisp.c) */
  22. #ifdef SUPPORT_1_3
  23. extern UBYTE _WDefName13[];
  24. #endif
  25. extern UBYTE _WDefName[];
  26.  
  27. void wbmain(struct WBStartup* wbmsg)
  28. {
  29.   UBYTE *ioname = NULL;  /* IO stream name that we are going to open */
  30.   int argc = 0;
  31.   char **argv;
  32.   short int numargs = wbmsg->sm_NumArgs;
  33.   #define MAXIONAME 100 /* including '\0' byte */
  34.   UBYTE ionamebuf[MAXIONAME];
  35.   struct argline {
  36.     char *line;       /* tokenized content */
  37.     int nt;           /* number of tokens in ARGS ToolType line */
  38.   } argline[numargs];
  39.   D(ebug("In wbmain(), numargs=%ld\n",numargs));
  40.   IconBase = OpenLibrary(ICONNAME,0L);
  41.   if (IconBase != NULL)
  42.     { register short int i;
  43.       struct WBArg *wbarg;
  44.       for (i = 0, wbarg = wbmsg->sm_ArgList;
  45.            i < numargs;
  46.            i++, wbarg++)
  47.         { struct DiskObject* dobj;
  48.           argline[i].line = NULL;
  49.       D(ebug("Got an object "));
  50.           if (wbarg->wa_Name != NULL)
  51.             {
  52.               dobj = GetDiskObject(wbarg->wa_Name);
  53.           D(ebug(wbarg->wa_Name));
  54.             }
  55.           else { dobj = NULL; D(ebug("without name!")); }
  56.           if (dobj != NULL)
  57.             { char* arg = FindToolType(dobj->do_ToolTypes,"WINDOW");
  58.               /* ex: WINDOW=CON:0/0/640/200/CLOS-Listener/CLOSE oder WINDOW=NIL: */
  59.               if (arg != NULL)
  60.                 { register int len = strlen(arg);
  61.                   if (len < MAXIONAME)
  62.                     { /* we overwrite, thus using the last possible name */
  63.               D(ebug("Found WINDOW tooltype\n"));
  64.                       ioname = &ionamebuf[0];
  65.                       nzbcopy(arg,ionamebuf,len+1);
  66.                     }
  67.                 }
  68.               arg = FindToolType(dobj->do_ToolTypes,"ARGS");
  69.               /* ex: ARGS=-Mcompiled.mem */
  70.               if (arg != NULL)
  71.                 { register int len = strlen(arg);
  72.           D(ebug("Found ARGS tooltype: %s\n",arg));
  73.                   argline[i].line = alloca(len+1);
  74.                   nzbcopy(arg,argline[i].line,len+1);
  75.                   argc += argline[i].nt = _tokenize(argline[i].line,len);
  76.                 }
  77.               FreeDiskObject(dobj);
  78.             }
  79.           if (i > 0 && argline[i].line == NULL)
  80.             { /* if there's no ARGS ToolType don't resign, add the filename */
  81.           if (_CLISP_glue) argc++; /* add -i filename */
  82.           argc++;
  83.             }
  84.         }
  85.       CloseLibrary(IconBase);
  86.       IconBase = NULL;
  87.     }
  88.   D(ebug("Argc is now %ld\n",argc));
  89.   D(ebug("Going to alloca(argv)\n"));
  90.   argv = alloca((argc+2) * sizeof(char *));  /* room for argv[0] and last NULL */
  91.   argv[0] = (char *)(wbmsg->sm_ArgList->wa_Name);  /* command name first */
  92.   /* (we fail to consider the case where sm_ArgList is NULL) */
  93.   { register short int i;
  94.     struct WBArg *wbarg;
  95.     register char **av = &argv[1];
  96.     for(i = 0, wbarg = wbmsg->sm_ArgList;
  97.         i < numargs;
  98.         i++, wbarg++)
  99.       {
  100.         if (argline[i].line != NULL)
  101.           { register int ac = argline[i].nt;
  102.         D(ebug("ARGS argline, ac is %ld\n",ac));
  103.             _dumpargs(argline[i].line,av,ac);
  104.             for ( ; ac > 0; ac--, av++)
  105.               { /* replace the token '*' with the file name */
  106.                 if ((*av)[0] == '*' && (*av)[1] == '\0')
  107.                   { *av = wbarg->wa_Name; }
  108.               }
  109.           }
  110.         else if (i > 0) /* not for the command name */
  111.           { /* no ARGS option specified, use "-i <name>" (see above) */
  112.         if (_CLISP_glue) *(av++) = "-i";
  113.             *(av++) = wbarg->wa_Name;
  114.         D(ebug("Empty argline\n"));
  115.           }
  116.       }
  117.     *av = NULL;
  118.     /* av - &argv[1] should be argc now */
  119.     D(ebug("+ av %ld\n",av - &argv[1]));
  120.   }
  121.   D(ebug(argv[0]));
  122.   argc++;       /* count command name argv[0] */
  123.  
  124.   if (ioname == NULL)
  125. #ifdef SUPPORT_1_3
  126.     { ioname = _OS_Version >= 37 ? _WDefName : _WDefName13; }
  127. #else
  128.     { ioname = _WDefName; }
  129. #endif
  130.  
  131.   Input_handle = Output_handle = Open(ioname,MODE_OLDFILE);
  132.   if (NULL != Input_handle)
  133.     {
  134.       _Close_Output = TRUE;     /* opened once, so close once */
  135.       D(ebug("Calling main()\n"));
  136.       main(argc,argv);
  137.     }
  138. }
  139.