home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / 3_1SWTOO.DMS / in.adf / wack.lha / demos / xwackdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-10  |  3.0 KB  |  158 lines

  1. ;/*
  2. lc -b0 -v xwackdemo
  3. blink xwackdemo.o to xwackdemo sc sd nd lib lib:lc.lib
  4. quit
  5. ;*/
  6.  
  7. /* xwackdemo.c
  8.  *
  9.  * (c) Copyright 1992-1993 Commodore-Amiga, Inc.  All rights reserved.
  10.  *
  11.  * This software is provided as-is and is subject to change; no warranties
  12.  * are made.  All use is at your own risk.  No liability or responsibility
  13.  * is assumed.
  14.  *
  15.  * Example Wack external extension program.  This one has a single
  16.  * function called "libvers".  Its role is to print out the name, version
  17.  * and revision of a library at the specified address.  If no address
  18.  * is specified, the current address is used.
  19.  *
  20.  * Bind it into Wack using:
  21.  *
  22.  *    bindxwack libvers xwackdemo libvers
  23.  *
  24.  */
  25.  
  26. #include <clib/exec_protos.h>
  27. #include <clib/dos_protos.h>
  28.  
  29. #include <pragmas/exec_pragmas.h>
  30. #include <pragmas/dos_pragmas.h>
  31.  
  32. #include "V39:aug/src/wack/wack_protos.h"
  33. #include "V39:aug/src/wack/wack_pragmas.h"
  34.  
  35. struct Library *SysBase;
  36. struct Library *DOSBase;
  37. struct MsgPort *WackBase;
  38.  
  39. #define TEMPLATE "wackport/A,libvers/S,arg/F"
  40. #define OPT_WACKPORT    0
  41. #define    OPT_LIBVERS    1
  42. #define OPT_ARG        2
  43. #define OPT_COUNT    3
  44.  
  45. ULONG stringToHex( STRPTR argstring, ULONG *result );
  46.  
  47. long
  48. main( void )
  49. {
  50.     long x;
  51.     long opts[OPT_COUNT];
  52.     struct ReadArgs *rdargs;
  53.     long result = 20;
  54.  
  55.     SysBase = (*((struct Library **) 4));
  56.  
  57.     if ( DOSBase = OpenLibrary("dos.library", 37 ) )
  58.     {
  59.     for ( x=0; x<OPT_COUNT; opts[x++]=0 )
  60.     {
  61.     }
  62.  
  63.     if ( rdargs = ReadArgs( TEMPLATE, opts, NULL ) )
  64.     {
  65.         result = 5;
  66.         if ( WackBase = FindPort( (STRPTR)opts[OPT_WACKPORT] ))
  67.         {
  68.         if ( opts[OPT_LIBVERS] )
  69.         {
  70.             struct Library *library;
  71.             if ( opts[OPT_ARG ] )
  72.             {
  73.             if ( stringToHex( (STRPTR)opts[OPT_ARG], (ULONG *)&library ) )
  74.             {
  75.                 result = 0;
  76.             }
  77.             }
  78.             else
  79.             {
  80.             library = Wack_ReadCurrAddr();
  81.             result = 0;
  82.             }
  83.             if ( result == 0 )
  84.             {
  85. #define NAMESIZE 100
  86.             char namebuff[ NAMESIZE ];
  87.             Wack_ReadString( Wack_ReadPointer( &library->lib_Node.ln_Name ),
  88.                 namebuff, NAMESIZE );
  89.             Wack_Printf( "%s %ld.%ld at %lx\n",
  90.                 namebuff,
  91.                 Wack_ReadWord( &library->lib_Version ),
  92.                 Wack_ReadWord( &library->lib_Revision ),
  93.                 library );
  94.             result = 0;
  95.             }
  96.         }
  97.         }
  98.         FreeArgs( rdargs );
  99.     }
  100.     CloseLibrary( DOSBase );
  101.     }
  102.     return( result );
  103. }
  104.  
  105. void
  106. Wack_Printf( STRPTR fmt, ... )
  107. {
  108.     Wack_VPrintf( fmt, ((ULONG *)&fmt)+1 );
  109. }
  110.  
  111. ULONG
  112. stringToHex( STRPTR argstring, ULONG *result )
  113. {
  114.     ULONG number = 0;
  115.     ULONG done = 0;
  116.     char ch;
  117.     ULONG digit;
  118.  
  119.     while ( !done )
  120.     {
  121.     ch = *argstring++;
  122.  
  123.     if ( ( ch >= '0' ) && ( ch <= '9' ) )
  124.     {
  125.         digit = ch - '0';
  126.     }
  127.     else if ( ( ch >= 'A' ) && ( ch <= 'F' ) )
  128.     {
  129.         digit = ch - 'A' + 10;
  130.     }
  131.     else if ( ( ch >= 'a' ) && ( ch <= 'f' ) )
  132.     {
  133.         digit = ch - 'a' + 10;
  134.     }
  135.     else
  136.     {
  137.         done = 1;
  138.         if ( ( ch != '\0' ) && ( ch != '\t' ) && ( ch != '\n' ) && ( ch != ' ' ) )
  139.         {
  140.         done = 2;
  141.         }
  142.     }
  143.     if ( !done )
  144.     {
  145.         number = 16*number + digit;
  146.     }
  147.     }
  148.     if ( done == 1 )
  149.     {
  150.     *result = number;
  151.     return( 1 );
  152.     }
  153.     else
  154.     {
  155.     return( 0 );
  156.     }
  157. }
  158.