home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / config / amiga / boot / config.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-03  |  2.3 KB  |  107 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: config.c,v 1.3 1997/02/03 02:53:27 ldp Exp $
  4.  
  5.     Desc: Amiga bootloader -- config file routines
  6.     Lang: C
  7. */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/lists.h>
  11. #include <exec/nodes.h>
  12. #include <exec/memory.h>
  13.  
  14. #include "string.h"
  15.  
  16. #include <proto/exec.h>
  17. #include <proto/dos.h>
  18.  
  19. #include "boot.h"
  20. #include "main.h"
  21. #include "config.h"
  22.  
  23. #define D(x) if (debug) x
  24. #define bug Printf
  25. LONG Printf(STRPTR format, ...);
  26.  
  27. char modulestring[] = "MODULE ";
  28.  
  29. struct FileList *ReadConfig(char *file)
  30. {
  31.     BPTR fh;
  32.     struct FileList *list;
  33.     struct Node *node;
  34.     char *name;
  35.     char *result;
  36.     int i;
  37.     char buffer[80];
  38.  
  39.     D(bug("Opening config file\n"));
  40.     if( (fh = Open(file, MODE_OLDFILE)) )
  41.     {
  42.     if( (list = AllocVec(sizeof(struct FileList), MEMF_CLEAR)) )
  43.     {
  44.         list->fl_List.lh_Head = (struct Node *)&list->fl_List.lh_Tail;
  45.         list->fl_List.lh_Tail = 0;
  46.         list->fl_List.lh_TailPred = (struct Node *)&list->fl_List.lh_Head;
  47.         list->fl_Num = 0;
  48.  
  49.             while( (result = FGets(fh, buffer, 79)) )
  50.         {
  51.         if( !(strnicmp(buffer, modulestring, strlen(modulestring))) )
  52.         {
  53.             /* found a valid entry */
  54.             if( (node = AllocVec(sizeof(struct Node), MEMF_CLEAR)) )
  55.             {
  56.             if( (name = AllocVec(strlen(buffer+strlen(modulestring)), MEMF_CLEAR)) )
  57.             {
  58.                 strcpy(name, buffer+strlen(modulestring));
  59.                 /* remove newline character, if present */
  60.                 for(i = 0; i < strlen(name); i++)
  61.                 {
  62.                 if('\n' == name[i]) name[i] = '\0';
  63.                 }
  64.                 node->ln_Name = name;
  65.                 D(bug(" Found %s\n", name));
  66.                 AddTail((struct List *)list, node);
  67.                 list->fl_Num++;
  68.             }
  69.             else
  70.             {
  71.                 FreeVec(node);
  72.             }
  73.             } /* if(node=AllocVec) */
  74.         } /* if(strnicmp) */
  75.         } /* while */
  76.  
  77.     } /* if(list=AllocVec) */
  78.     Close(fh);
  79.     } /* if(Open) */
  80.     else
  81.     {
  82.     return 0;
  83.     } /* if(Open) */
  84.  
  85.     return list;
  86. }
  87.  
  88. void FreeConfig(struct FileList *list)
  89. {
  90.     struct Node *node, *next;
  91.  
  92.     D(bug("FreeConfig()\n"));
  93.  
  94.     for(node = list->fl_List.lh_Head; node->ln_Succ; node = next)
  95.     {
  96.     /*
  97.         Get the next node here, because after the Remove() it is undefined.
  98.     */
  99.     next = node->ln_Succ;
  100.     Remove(node);
  101.     if(node->ln_Name) FreeVec(node->ln_Name);
  102.     FreeVec(node);
  103.     }
  104.  
  105.     if(list) FreeVec(list);
  106. }
  107.