home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 632.lha / LoadLib_v1.0 / LoadLib.c < prev    next >
C/C++ Source or Header  |  1992-04-27  |  3KB  |  149 lines

  1. /*
  2.  *    LoadLib.c - Copyright © 1990 by S.R.
  3.  *
  4.  *    Created:    04 Aug 1991    18:27:25
  5.  *    Modified:    28 Jan 1992    18:44:29
  6.  * Compiles: 26
  7.  *
  8.  *    Make>> lc -b1 -cf -r1 -M -v -w -ci -O -HINCLUDE:x.sym <file>
  9.  *    Make>> BLink Lib:CStartupRes.o <file>.o TO <file> LIB Lib:String.lib SMALLDATA SMALLCODE VERBOSE
  10.  */
  11.  
  12. #include "string_lib.h"
  13.  
  14. extern struct ExecBase *SysBase;
  15. extern struct DosLibrary *DOSBase;
  16.  
  17. struct IconBase *IconBase = NULL;
  18.  
  19. struct WBStartup *_wb_parse(struct Process * ThisProcess)
  20. {
  21.     struct WBStartup *WBenchMsg = NULL;
  22.  
  23.     WaitPort(&ThisProcess->pr_MsgPort);
  24.     WBenchMsg = (struct WBStartup *) GetMsg(&ThisProcess->pr_MsgPort);
  25.     CurrentDir(WBenchMsg->sm_ArgList->wa_Lock);
  26.  
  27.     return WBenchMsg;
  28. }
  29.  
  30. void Msg( char * Str)
  31. {
  32.     BPTR fh;
  33.  
  34.     if ( fh = Open("CON:0/10/640/100/LoadLib Message:", MODE_NEWFILE)) 
  35.         {
  36.             Write( fh, Str, strlen(Str));
  37.             Delay(50L);
  38.             Close( fh);
  39.         }
  40.  
  41.     return;
  42. }
  43.  
  44. void LoadLibrary( char *LibraryName)
  45. {
  46.     struct Library *LibraryPtr;
  47.  
  48.     LibraryPtr = OpenLibrary( LibraryName, 0L);
  49.     if ( LibraryPtr)
  50.         CloseLibrary( LibraryPtr);
  51. }
  52.  
  53. /* return ptr on next arg. Attention: this function modified the arg line */
  54. char *NextCLIArg( char *lineptr)
  55. {
  56.     char *NextArg;
  57.  
  58.     while( isspace( *lineptr) )
  59.         lineptr++;                                        /* skip space, tab, etc... */
  60.  
  61.     if ( !(*lineptr) )
  62.         return NULL;                                    /* end of argument */
  63.  
  64.     if ( *lineptr == '"' )
  65.         {
  66.             NextArg = ++lineptr;                                /* arg start after quote */
  67.             while ( *lineptr != '"')
  68.                 lineptr++;                                /* go to terminating quote */
  69.         }
  70.     else
  71.         {
  72.             NextArg = lineptr++;                                /* arg start here */
  73.             while( !isspace( *lineptr) )
  74.                 lineptr++;
  75.         }
  76.  
  77.     *lineptr = '\0';                            /* terminate the string */
  78.     return NextArg;
  79. }        
  80.  
  81. long _main(  long alen, register char *aptr)
  82. {
  83.     struct Process *ThisProcess;
  84.     struct WBStartup *WBenchMsg = NULL;
  85.     char ArgLine[257];
  86.     char *CLIArg;
  87.  
  88.     struct DiskObject *dop;
  89.  
  90.     char **ToolTypesArray = NULL;
  91.     long i;
  92.  
  93.     ThisProcess = (struct Process *) SysBase->ThisTask;
  94.     if (!ThisProcess->pr_CLI)
  95.         {
  96.             /* run from WB */
  97.             WBenchMsg = _wb_parse(ThisProcess);
  98.         }
  99.  
  100.     if ( WBenchMsg)
  101.         {
  102.             if ( !( IconBase = (struct IconBase *) OpenLibrary("icon.library", 1L)))
  103.                 {
  104.                     Msg( "You need icon.library V1+ \n");
  105.                     return 20;
  106.                 }
  107.             /* Tool Types parsing */
  108.             for (i = 1; i < WBenchMsg->sm_NumArgs; i++)
  109.                 {
  110.                     CurrentDir(WBenchMsg->sm_ArgList[i].wa_Lock);    /* enter in the dir containing the Icon */
  111.                     if (dop = GetDiskObject(WBenchMsg->sm_ArgList[i].wa_Name))
  112.                         {
  113.                             for( ToolTypesArray = dop->do_ToolTypes, i = 0; ToolTypesArray[i]; i++)
  114.                                 {
  115.                                     LoadLibrary( ToolTypesArray[i]);
  116.                                 }
  117.                             FreeDiskObject(dop);
  118.  
  119.                         }
  120.                     else
  121.                         {
  122.                             /* no icon: I can't do anything ! */
  123.                             Msg( "I can't find the icon");
  124.                             return 20;
  125.                         }
  126.                 }
  127.         }
  128.     else
  129.         {        /* CLI parsing */
  130.             if ( alen < strlen("LoadLib"))
  131.                 {
  132.                     Write( Output(),"LoadLib V1.0 © 1991 by S.R.\nUsage: LoadLib <dev:dir/Library_name>\n", 86);
  133.                     return 5;
  134.                 }
  135.             strncpy ( ArgLine, aptr, alen);
  136.             ArgLine[alen] = '\0';
  137.             ArgLine[alen + 1 ] = '\0';
  138.             CLIArg = ArgLine;
  139.  
  140.             while ( CLIArg = NextCLIArg( CLIArg) )
  141.                 {
  142.                     LoadLibrary( CLIArg);
  143.                     CLIArg = &CLIArg[ strlen( CLIArg) + 1];
  144.                 }
  145.         }
  146.  
  147.     return 0;
  148. }
  149.