static void roadmap_config_update (RoadMapConfig *config, int force) { FILE *file; const char *value; const char *p = NULL; RoadMapConfigItem *item; if (force || (config->state == ROADMAP_CONFIG_DIRTY)) { #ifndef J2ME for ( p = roadmap_path_first( config->set ); p != NULL; p = roadmap_path_next( config->set, p ) ) { if ( roadmap_file_exists( p, "" ) ) break; } #endif if ( p == NULL ) { p = roadmap_path_config(); } #ifdef J2ME char file_name[100]; sprintf(file_name,"%s_j2me",config->name); file = roadmap_file_fopen (p, file_name, "w"); #else file = roadmap_file_fopen ( p, config->name, "w" ); #endif if ( file ) { for (item = config->first_item; item != NULL; item = item->next) { if ((! force) && (item->state == ROADMAP_CONFIG_SHARED)) continue; if (item->value != NULL) { value = item->value; } else { value = item->default_value; } #ifdef J2ME char name_to_write[100]; // this will be of the category.type name sprintf(name_to_write,"%s.%s", item->category, item->name); roadmap_config_write_name_value_to_binary(name_to_write,value,file); #else fprintf (file, "%s.%s: %s\n", item->category, item->name, value); #endif } fclose (file); config->state = ROADMAP_CONFIG_CLEAN; } } }
static ssd_contextmenu_ptr roadmap_factory_load_menu_file( const char* file_name, const RoadMapAction* actions, const char* path) { char* p; char buffer[256]; ssd_contextmenu_ptr menu; #ifndef J2ME FILE* file = roadmap_file_fopen (path, file_name, "sr"); #else FILE* file = roadmap_file_fopen (NULL, file_name, "sr"); #endif if( !file) { roadmap_log(ROADMAP_ERROR, "Can't open menu file: %s", file_name); assert(0); return NULL; } menu = malloc( sizeof(ssd_contextmenu)); memset( menu, 0, sizeof(ssd_contextmenu)); menu->item = calloc( sizeof(ssd_cm_item), CONTEXT_MENU_MAX_ITEMS_COUNT); buffer[sizeof(buffer)-1] = 0; while (! feof(file)) { fgets( buffer, sizeof(buffer)-1, file); if (feof(file) || ferror(file)) break; // remove the end-of-line character. p = strchr (buffer, '\r'); if (p != NULL) *p = 0; p = strchr (buffer, '\n'); if (p != NULL) *p = 0; // Remove any leading space. for (p = buffer; isspace(*p); ++p) ; if ((*p == 0) || (*p == '#')) continue; // Empty line. if( !roadmap_factory_load_menu_item( menu, p, actions)) { assert(0); ssd_contextmenu_delete( menu, FALSE); menu = NULL; break; } } fclose(file); return menu; }
static int open_data_file (void) { char *file_name; if (track_file) return 0; file_name = roadmap_path_join(roadmap_config_get(&RoadMapConfigMapPath), "track_data.bin"); track_file = roadmap_file_fopen(NULL, file_name, "a"); roadmap_path_free(file_name); if (track_file == NULL) { roadmap_messagebox("Error", "Can't open track_data"); return -1; } if (ftell(track_file) == 0) { unsigned char version[4] = {0, 10, 0, 1}; if (fwrite(version, sizeof(version), 1, track_file) != 1) { roadmap_messagebox("Error", "Can't write to track_data"); fclose(track_file); track_file = NULL; return -1; } } return 0; }
void roadmap_log_init(){ long fileSize; const char *log_path; const char *log_path_temp; const char * path; const char * name; char lineFromLog[300]; #if defined (__SYMBIAN32__) #if defined (WINSCW) path = "C:\\"; name = "waze_log.txt"; #else path = roadmap_db_map_path(); name = "waze_log.txt"; #endif #elif defined(ANDROID) roadmap_path_sdcard(); name = "waze_log.txt"; #elif !defined (J2ME) path = roadmap_path_user(); name = "postmortem"; #endif fileSize = roadmap_file_length(path,name); if (fileSize > 0 ){ // file exists if(fileSize>MAX_SIZE_LOG_FILE){ FILE * LogFile = roadmap_file_fopen(path,name,"sa+"); FILE * tempLogFile = roadmap_file_fopen(path,"temp_log_file.txt","sa+"); fseek(LogFile, 0, SEEK_END-TO_KEEP_LOG_SIZE); fgets (lineFromLog,300, LogFile ); while (1){ fgets (lineFromLog,300, LogFile ); if(feof(LogFile)) break; fputs (lineFromLog,tempLogFile ); } fclose(LogFile); fclose(tempLogFile); log_path = roadmap_path_join (path, name); log_path_temp = roadmap_path_join (path, "temp_log_file.txt"); roadmap_file_remove (path, name); rename(log_path_temp,log_path); roadmap_path_free (log_path); roadmap_path_free (log_path_temp); } } }
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; }
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; }
static void roadmap_config_update (RoadMapConfig *config, int force) { FILE *file; const char *value; const char *p; RoadMapConfigItem *item; if (force || (config->state == ROADMAP_CONFIG_DIRTY)) { for ( p = roadmap_path_first( config->set ); p != NULL; p = roadmap_path_next( config->set, p ) ) { if ( roadmap_file_exists( p, "" ) ) break; } if ( p == NULL ) { p = roadmap_path_config(); } file = roadmap_file_fopen ( p, config->name, "w" ); if ( file ) { for (item = config->first_item; item != NULL; item = item->next) { if ((! force) && (item->state == ROADMAP_CONFIG_SHARED)) continue; if (item->value != NULL) { value = item->value; } else { value = item->default_value; } fprintf (file, "%s.%s: %s\n", item->category, item->name, value); } fclose (file); config->state = ROADMAP_CONFIG_CLEAN; } } }
void roadmap_log (int level, const char *source, int line, const char *format, ...) { va_list ap; char saved = ' '; struct roadmap_message_descriptor *category; char *debug; if (level < roadmap_verbosity()) return; #if(defined DEBUG && defined SKIP_DEBUG_LOGS) return; #endif // SKIP_DEBUG_LOGS debug = roadmap_debug(); if ((debug[0] != 0) && (strcmp (debug, source) != 0)) return; for (category = RoadMapMessageHead; category->level != 0; ++category) { if (category->level == level) break; } va_start(ap, format); if (category->save_to_file) { static int open_file_attemped = 0; if ((sgLogFile == NULL) && (!open_file_attemped)) { open_file_attemped = 1; sgLogFile = roadmap_file_fopen (roadmap_log_path(), roadmap_log_filename(), roadmap_log_access_mode()); if (sgLogFile) fprintf (sgLogFile, "*** Starting log file %d ***", (int)time(NULL)); } if (sgLogFile != NULL) { roadmap_log_one (category, sgLogFile, ' ', source, line, format, ap); fflush (sgLogFile); //fclose (file); va_end(ap); va_start(ap, format); saved = 's'; } } #ifdef __SYMBIAN32__ //roadmap_log_one (category, __stderr(), saved, source, line, format, ap); #else #if(defined WIN32PC && defined _DEBUG) show_logs_in_debugger( category, format, ap); #endif // WIN32PC Debug roadmap_log_one (category, stderr, saved, source, line, format, ap); #endif va_end(ap); if( category->do_exit) #ifdef FREEZE_ON_FATAL_ERROR { int beep_times = 20; int sleep_time = 1000; do { Sleep( sleep_time); if( beep_times) { fprintf( sgLogFile, ">>> FATAL ERROR - WAITING FOR PROCESS TO BE ATTACHED BY A DEBUGGER...\r\n"); MessageBeep(MB_OK); beep_times--; if(!beep_times) sleep_time = 5000; } } while(1); } #else exit(1); #endif // FREEZE_ON_FATAL_ERROR }
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; }
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; }