示例#1
0
void roadmap_config_declare_color (const char *config,
                                   RoadMapConfigDescriptor *descriptor,
                                   const char *default_value) {

   RoadMapConfig *file = roadmap_config_search_file (config);

   roadmap_config_new_item
      (file, descriptor, default_value, ROADMAP_CONFIG_COLOR, NULL, NULL);
}
示例#2
0
void roadmap_config_declare (const char *config,
                             RoadMapConfigDescriptor *descriptor,
                             const char *default_value, int *is_new) {

   RoadMapConfig *file = roadmap_config_search_file (config);

   roadmap_config_new_item
      (file, descriptor, default_value, ROADMAP_CONFIG_STRING, NULL,
       is_new);
}
示例#3
0
RoadMapConfigItem *roadmap_config_declare_enumeration (const char *config,
                                         RoadMapConfigDescriptor *descriptor,
                                         RoadMapCallback callback,
                                         const char *enumeration_value, ...) {

   char *p;
   va_list ap;

   RoadMapConfig *file = roadmap_config_search_file (config);
   RoadMapConfigItem *item;
   RoadMapConfigEnum *next;
   RoadMapConfigEnum *enumerated;

   item = roadmap_config_new_item
             (file, descriptor, enumeration_value, ROADMAP_CONFIG_ENUM,
              callback, NULL);

   /* Replace the enumeration list. */

   for (enumerated = item->detail.enumeration_values;
        enumerated != NULL;
        enumerated = next) {
      next = enumerated->next;
      free (enumerated->value);
      free (enumerated);
   }
   item->detail.enumeration_values = NULL;

   roadmap_config_add_enumeration_value (item, enumeration_value);

   va_start(ap, enumeration_value);
   for (p = va_arg(ap, char *); p != NULL; p = va_arg(ap, char *)) {
       roadmap_config_add_enumeration_value (item, p);
   }

   va_end(ap);

   return item;
}
示例#4
0
static int roadmap_config_load
               (const char *path, RoadMapConfig *config, int intended_state) {

   char *p;
   FILE *file;
   char  line[1024];

   char *category;
   char *name;
   char *value;

   RoadMapConfigItem *item;
   RoadMapConfigDescriptor descriptor;

#ifdef J2ME
   char file_name[100];
   char * nameWithCategory;
   sprintf(file_name,"%s_j2me",config->name);
   file = roadmap_file_fopen (path, file_name, "sr");
#else
   file = roadmap_file_fopen (path, config->name, "sr");
#endif
   if (file == NULL) return 0;
 
   while (!feof(file)) {
		int new_item;
#ifdef J2ME

        /* get the name and value from the binary file. Not that this doesn't include the parsing
        to category and name by the '.' character */
		if(!roadmap_config_get_name_value_binary(&nameWithCategory, &value, file))
			break; // error, or reached end of file
		

		category = nameWithCategory;

		// start additional parsing to retrieve the name and category
		p = roadmap_config_skip_until (nameWithCategory, '.');
        if (*p != '.') continue;
        *(p++) = 0; // end the category string
		
		
        name = p;
	
        descriptor.name = strdup (name);
        descriptor.category = strdup (category);
        descriptor.reference = NULL;	
		free(nameWithCategory); // since we already parsed this into name & category , we don't need it anymore

#else
       
        /* Read the next line, skip empty lines and comments. */

        if (fgets (line, sizeof(line), file) == NULL) break;

        category =
            roadmap_config_extract_data (line, sizeof(line));

        if (category == NULL) continue;


        /* Decode the line (category.name: value). */

        p = roadmap_config_skip_until (category, '.');
        if (*p != '.') continue;
        *(p++) = 0;

        name = p;

        p = roadmap_config_skip_until (p, ':');
        if (*p != ':') continue;
        *(p++) = 0;

        p = roadmap_config_skip_spaces (p);
        value = p;

        p = roadmap_config_skip_until (p, 0);
        *p = 0;


        /* Detach the strings from the line buffer. */

        value = strdup (value);
        descriptor.name = strdup (name);
        descriptor.category = strdup (category);
        descriptor.reference = NULL;
#endif

        /* Retrieve or create this configuration item. */

        item = roadmap_config_new_item
                    (config, &descriptor, "", ROADMAP_CONFIG_STRING|ROADMAP_CONFIG_NEW,
                     NULL, &new_item);
        if (!new_item) {
          free ((void *)descriptor.name);
          free ((void *)descriptor.category);
        }

        if (item->value != NULL) {
            free(item->value);
        }
        item->value = value;
        item->state = intended_state;

        item->cached_valid = 0;
    }
    fclose (file);

    config->state = ROADMAP_CONFIG_CLEAN;

    RoadMapConfigLoaded = 1;
    return 1;
}
示例#5
0
static int roadmap_config_load
               (const char *path, RoadMapConfig *config, int intended_state) {

   char *p;
   FILE *file;
   char  line[1024];

   char *category;
   char *name;
   char *value;

   RoadMapConfigItem *item;
   RoadMapConfigDescriptor descriptor;

   file = roadmap_file_fopen (path, config->name, "sr");

   if (file == NULL) return 0;

   while (!feof(file)) {

        int new_item;
        /* Read the next line, skip empty lines and comments. */

        if (fgets (line, sizeof(line), file) == NULL) break;

        category =
            roadmap_config_extract_data (line, sizeof(line));

        if (category == NULL) continue;


        /* Decode the line (category.name: value). */

        p = roadmap_config_skip_until (category, '.');
        if (*p != '.') continue;
        *(p++) = 0;

        name = p;

        p = roadmap_config_skip_until (p, ':');
        if (*p != ':') continue;
        *(p++) = 0;

        p = roadmap_config_skip_spaces (p);
        value = p;

        p = roadmap_config_skip_until (p, 0);
        *p = 0;


        /* Detach the strings from the line buffer. */

        value = strdup (value);
        descriptor.name = strdup (name);
        descriptor.category = strdup (category);
        descriptor.reference = NULL;


        /* Retrieve or create this configuration item. */

        item = roadmap_config_new_item
                    (config, &descriptor, "", ROADMAP_CONFIG_STRING,
                     NULL, &new_item);
        if (!new_item) {
          free ((void *)descriptor.name);
          free ((void *)descriptor.category);
        }

        if (item->value != NULL) {
            free(item->value);
        }
        item->value = value;
        item->state = intended_state;

        item->cached_valid = 0;
    }
    fclose (file);

    config->state = ROADMAP_CONFIG_CLEAN;
    return 1;
}