home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0948.lha / Snoopy / Ini / Examples / example.c < prev    next >
C/C++ Source or Header  |  1993-12-20  |  2KB  |  57 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <clib/exec_protos.h>
  5.  
  6. #include "/libraries/ini.h"
  7. #include "/clib/ini_protos.h"
  8. #include "/pragmas/ini_pragmas.h"
  9.  
  10. struct IniBase *IniBase;
  11.  
  12. int main( void )
  13. {
  14.     /* open the ini.library */
  15.     if( ( IniBase = (struct IniBase *)OpenLibrary( "ini.library", 0 ) ) != NULL )
  16.     {
  17.         INIPARSER parser; 
  18.         INILINEINFO *info;
  19.         INIERROR rc;
  20.  
  21.         /* parse in a new inifile */
  22.         if( ( rc = ini_New( "test.ini", &parser ) ) == INIERROR_NONE )
  23.         {
  24.             /* now you can examine the parser. this *very* rudimentary example
  25.                only shows all section/variable strings; you'll probably do more
  26.                serious things with this structure */
  27.  
  28.             for( info = (INILINEINFO *)parser.table.lh_Head;
  29.                  info->node.ln_Succ;
  30.                  info = (INILINEINFO *)info->node.ln_Succ )
  31.             {
  32.                 switch( info->flags )
  33.                 {
  34.                 case INIFLAG_VARIABLE:
  35.                     printf( "VARIABLE=\"%s\", CONTENTS=\"%s\"\n", 
  36.                         info->variable, info->contents );
  37.                     break;
  38.                 case INIFLAG_HEADER:
  39.                     printf( "HEADER=\"%s\"\n", info->contents );
  40.                     break;
  41.                 case INIFLAG_COMMENT: /* SHOULD BE IGNORED */
  42.                     printf( "COMMENT=\"%s\"\n", info->allocated );
  43.                     break;
  44.                 default:
  45.                     printf( "UNKNOWN ENTRY AT 0x%08lx, PLEASE REPORT\n", info );
  46.                 }
  47.             }
  48.             ini_Delete( &parser );
  49.         }
  50.         else printf( "INIERROR:%s\n", ini_ErrorString( rc ) );
  51.         
  52.         /* close library */
  53.         CloseLibrary( (struct Library *)IniBase );
  54.     }
  55.     return 0;
  56. }
  57.