home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume4 / xgen / part03 / parse_resources.c < prev    next >
C/C++ Source or Header  |  1989-06-29  |  2KB  |  88 lines

  1. #include <stdio.h> 
  2. #include "application.h"
  3.  
  4. struct resource *parse_resources( fp1, shell_label, label)
  5. FILE *fp1;
  6. char *shell_label;
  7. char *label;
  8. {
  9.     char resource_value[1024];
  10.     char *temp;
  11.  
  12.     struct resource *header,
  13.     *pres_resource,
  14.     *prev_resource;
  15.  
  16.     int  C ;
  17.     int count = 0;
  18.  
  19.     /* start a linked list of the widget resources */
  20.     header = (struct resource *)malloc(sizeof(
  21.         struct resource));
  22.     strcpy( header->name, "label");
  23.  
  24.     /*first resource is the label of the widget*/
  25.     header->value = ( char *)malloc(
  26.         (strlen(label) +1)*sizeof(char));
  27.  
  28.     strcpy( header->value, label);
  29.  
  30. /*    fprintf(stderr, "parsing object %s",  header->value); */
  31.     /* initialize the linked list */
  32.     pres_resource = header;
  33.     prev_resource = header;
  34.  
  35.     while(1)
  36.     {
  37.         get_symbol(fp1, &C) ;
  38.  
  39.         /* if the option declaration is closed  exit loop */
  40.         if (C == ';'|| C == '(')
  41.         {
  42.             ungetc(C, fp1);
  43.             break;
  44.         }
  45.  
  46.         ungetc(C, fp1);
  47.  
  48.         /* otherwise add a new data resource to the list */
  49.         pres_resource = (struct resource *)malloc(sizeof(
  50.             struct resource));
  51.  
  52.         prev_resource->next = pres_resource;
  53.  
  54.         /* read and resource name */
  55.         get_string(fp1, pres_resource->name, ':', STR_LEN) ;
  56.  
  57. /*        fprintf(stderr,"parsing option %s\n", pres_resource->name);*/
  58.  
  59.         temp = resource_value;
  60.  
  61.         /* read colon */
  62.         get_symbol(fp1, &C) ;
  63.         if( C != ':' )
  64.         {
  65.             fprintf(stderr,  "Syntax error in shell \"%s\" in object \"%s\" declaration\n",
  66.                 shell_label, label);
  67.             exit(-1);
  68.         }
  69.         get_string(fp1, temp, ';', 1024) ;
  70.  
  71.         pres_resource->value = ( char *)malloc(
  72.             (strlen( resource_value)+1) * sizeof(char));
  73.         strcpy(pres_resource->value, resource_value);
  74.  
  75. /*        fprintf(stderr,"option val %s\n", pres_resource->value);*/
  76.  
  77.         prev_resource = pres_resource;
  78.  
  79.     }
  80.     /*close linked list*/
  81. /*        fprintf(stderr,"option val %s\n", pres_resource->value);*/
  82.  
  83.     pres_resource->next = NULL;
  84.  
  85.  
  86.     return(header);
  87. }
  88.