コード例 #1
0
ファイル: roadmap_lang.c プロジェクト: Priednis/WazeWP7
static int roadmap_lang_load (const char *path) {



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

   char *name;
   char *value;

#ifndef J2ME
   sprintf(file_name, "lang.%s", roadmap_lang_get_system_lang());
#else   
   sprintf(file_name, "lang.%s_j2me", roadmap_lang_get_system_lang()); 
#endif   
   file = roadmap_file_fopen (path, file_name, "sr");
   if (file == NULL) return 0;
   while (!feof(file)) {

#ifndef J2ME
        /* Read the next line, skip empty lines and comments. */
        if (fgets (line, sizeof(line), file) == NULL) break;


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

        if (p == NULL) continue;
        /* Decode the line (name= value). */
        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;
        name  = strdup (name);
        value = strdup (value);
#else // J2ME
		if(!roadmap_config_get_name_value_binary(&name, &value, file))
			break; // reached end of file		
#endif
        roadmap_lang_new_item (name, value);
   	}
    fclose (file);
	return 1; 
	
}
コード例 #2
0
ファイル: roadmap_lang.c プロジェクト: Priednis/WazeWP7
static int roadmap_lang_conf_load (const char *path) {

    char *p;
   FILE *file;
   char  line[1024];
   char file_name[20];
   char *name;
   char *value;

   roadmap_log (ROADMAP_INFO, "Starting 'roadmap_lang_conf_load'");

   languages_count = 0;

   sprintf(file_name, "lang.conf");
   file = roadmap_file_fopen (path, file_name, "sr");
   if (file == NULL){
      roadmap_log (ROADMAP_ERROR, "lang.conf not found.");
      return 0;
   }

   while (!feof(file)) {

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

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

        p = roadmap_config_extract_data (line, sizeof(line));
        if (p == NULL) continue;

           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;

           lang_labels[languages_count] = strdup (value);
           lang_values[languages_count] = strdup (name);
           languages_count++;
    }

   roadmap_log (ROADMAP_INFO, "Calling 'NOPH_LanguagesLoaded'");
    fclose (file);
	NOPH_LanguagesLoaded( (int)lang_labels, (int)lang_values, languages_count);

    return 1;
}
コード例 #3
0
ファイル: roadmap_config.c プロジェクト: NoamSheffer/WazeWP7
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;
}
コード例 #4
0
ファイル: roadmap_config.c プロジェクト: GitPicz/waze
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;
}