186 in = fopen(filename, "r"); |
186 in = fopen(filename, "r"); |
187 if (in == NULL) return ini; |
187 if (in == NULL) return ini; |
188 |
188 |
189 // for each line in the file |
189 // for each line in the file |
190 while (fgets(buffer, sizeof(buffer), in)) { |
190 while (fgets(buffer, sizeof(buffer), in)) { |
191 |
191 |
192 // trim whitespace from the left side |
192 // trim whitespace from the left side |
193 for(s=buffer; *s == ' ' || *s == '\t'; s++); |
193 for(s=buffer; *s == ' ' || *s == '\t'; s++); |
194 |
194 |
195 // trim whitespace from right side. |
195 // trim whitespace from right side. |
196 e = s + strlen(s); |
196 e = s + strlen(s); |
228 comment_size = 0; |
228 comment_size = 0; |
229 } |
229 } |
230 } else if (group) { |
230 } else if (group) { |
231 // find end of keyname |
231 // find end of keyname |
232 for(t=s; *t != 0 && *t != '=' && *t != '\t' && *t != ' '; t++) {} |
232 for(t=s; *t != 0 && *t != '=' && *t != '\t' && *t != ' '; t++) {} |
233 |
233 |
234 // it's an item in an existing group |
234 // it's an item in an existing group |
235 item = ini_item_alloc(group, s, t-s); |
235 item = ini_item_alloc(group, s, t-s); |
236 if (comment_size) { |
236 if (comment_size) { |
237 item->comment = pool_strdup(&ini->pool, comment, comment_size); |
237 item->comment = pool_strdup(&ini->pool, comment, comment_size); |
238 comment_size = 0; |
238 comment_size = 0; |
283 uint len = strlen(name); |
283 uint len = strlen(name); |
284 |
284 |
285 for(item = group->item; item; item = item->next) |
285 for(item = group->item; item; item = item->next) |
286 if (!strcmp(item->name, name)) |
286 if (!strcmp(item->name, name)) |
287 return item; |
287 return item; |
288 |
288 |
289 if (!create) return NULL; |
289 if (!create) return NULL; |
290 |
290 |
291 // otherwise make a new one |
291 // otherwise make a new one |
292 item = ini_item_alloc(group, name, len); |
292 item = ini_item_alloc(group, name, len); |
293 return item; |
293 return item; |
625 if (group_def == NULL) |
625 if (group_def == NULL) |
626 group_def = ini_getgroup(ini, grpname, -1); |
626 group_def = ini_getgroup(ini, grpname, -1); |
627 s = desc->name; |
627 s = desc->name; |
628 group = group_def; |
628 group = group_def; |
629 } |
629 } |
630 |
630 |
631 item = ini_getitem(group, s, true); |
631 item = ini_getitem(group, s, true); |
632 |
632 |
633 // get ptr to array |
633 // get ptr to array |
634 ptr = desc->ptr; |
634 ptr = desc->ptr; |
635 if ( (uint32)ptr < 0x10000) |
635 if ( (uint32)ptr < 0x10000) |
636 ptr = (byte*)base + (uint32)ptr; |
636 ptr = (byte*)base + (uint32)ptr; |
637 |
637 |
638 if (item->value != NULL) { |
638 if (item->value != NULL) { |
639 // check if the value is the same as the old value |
639 // check if the value is the same as the old value |
640 p = string_to_val(desc, item->value); |
640 p = string_to_val(desc, item->value); |
641 |
641 |
642 switch(desc->flags & 0xF) { |
642 switch(desc->flags & 0xF) { |
643 case SDT_INTX: |
643 case SDT_INTX: |
644 case SDT_ONEOFMANY: |
644 case SDT_ONEOFMANY: |
715 make_intlist(buf, ptr, desc->flags >> 16, desc->flags >> 4 & 7); |
715 make_intlist(buf, ptr, desc->flags >> 16, desc->flags >> 4 & 7); |
716 break; |
716 break; |
717 } |
717 } |
718 // the value is different, that means we have to write it to the ini |
718 // the value is different, that means we have to write it to the ini |
719 item->value = pool_strdup(&ini->pool, buf, strlen(buf)); |
719 item->value = pool_strdup(&ini->pool, buf, strlen(buf)); |
720 } |
720 } |
721 } |
721 } |
722 |
722 |
723 //*************************** |
723 //*************************** |
724 // TTD specific INI stuff |
724 // TTD specific INI stuff |
725 //*************************** |
725 //*************************** |
824 {"new_depot_finding", SDT_BOOL, (void*)false, (void*)offsetof(Patches, new_depot_finding), NULL}, |
824 {"new_depot_finding", SDT_BOOL, (void*)false, (void*)offsetof(Patches, new_depot_finding), NULL}, |
825 |
825 |
826 {"nonuniform_stations", SDT_BOOL, (void*)false, (void*)offsetof(Patches, nonuniform_stations), NULL}, |
826 {"nonuniform_stations", SDT_BOOL, (void*)false, (void*)offsetof(Patches, nonuniform_stations), NULL}, |
827 {"always_small_airport",SDT_BOOL, (void*)false, (void*)offsetof(Patches, always_small_airport), NULL}, |
827 {"always_small_airport",SDT_BOOL, (void*)false, (void*)offsetof(Patches, always_small_airport), NULL}, |
828 {"realistic_acceleration",SDT_BOOL, (void*)false, (void*)offsetof(Patches, realistic_acceleration), NULL}, |
828 {"realistic_acceleration",SDT_BOOL, (void*)false, (void*)offsetof(Patches, realistic_acceleration), NULL}, |
829 |
829 |
830 {"toolbar_pos", SDT_UINT8, (void*)0, (void*)offsetof(Patches, toolbar_pos), NULL}, |
830 {"toolbar_pos", SDT_UINT8, (void*)0, (void*)offsetof(Patches, toolbar_pos), NULL}, |
831 |
831 |
832 {"max_trains", SDT_UINT8, (void*)80, (void*)offsetof(Patches, max_trains), NULL}, |
832 {"max_trains", SDT_UINT8, (void*)80, (void*)offsetof(Patches, max_trains), NULL}, |
833 {"max_roadveh", SDT_UINT8, (void*)80, (void*)offsetof(Patches, max_roadveh), NULL}, |
833 {"max_roadveh", SDT_UINT8, (void*)80, (void*)offsetof(Patches, max_roadveh), NULL}, |
834 {"max_aircraft", SDT_UINT8, (void*)40, (void*)offsetof(Patches, max_aircraft), NULL}, |
834 {"max_aircraft", SDT_UINT8, (void*)40, (void*)offsetof(Patches, max_aircraft), NULL}, |
846 |
846 |
847 {"new_pathfinding", SDT_BOOL, (void*)false, (void*)offsetof(Patches, new_pathfinding), NULL}, |
847 {"new_pathfinding", SDT_BOOL, (void*)false, (void*)offsetof(Patches, new_pathfinding), NULL}, |
848 {"pf_maxlength", SDT_UINT16, (void*)512, (void*)offsetof(Patches, pf_maxlength), NULL}, |
848 {"pf_maxlength", SDT_UINT16, (void*)512, (void*)offsetof(Patches, pf_maxlength), NULL}, |
849 {"pf_maxdepth", SDT_UINT8, (void*)16, (void*)offsetof(Patches, pf_maxdepth), NULL}, |
849 {"pf_maxdepth", SDT_UINT8, (void*)16, (void*)offsetof(Patches, pf_maxdepth), NULL}, |
850 |
850 |
851 |
851 |
852 {"ai_disable_veh_train",SDT_BOOL, (void*)false, (void*)offsetof(Patches, ai_disable_veh_train), NULL}, |
852 {"ai_disable_veh_train",SDT_BOOL, (void*)false, (void*)offsetof(Patches, ai_disable_veh_train), NULL}, |
853 {"ai_disable_veh_roadveh",SDT_BOOL, (void*)false, (void*)offsetof(Patches, ai_disable_veh_roadveh), NULL}, |
853 {"ai_disable_veh_roadveh",SDT_BOOL, (void*)false, (void*)offsetof(Patches, ai_disable_veh_roadveh), NULL}, |
854 {"ai_disable_veh_aircraft",SDT_BOOL,(void*)false, (void*)offsetof(Patches, ai_disable_veh_aircraft),NULL}, |
854 {"ai_disable_veh_aircraft",SDT_BOOL,(void*)false, (void*)offsetof(Patches, ai_disable_veh_aircraft),NULL}, |
855 {"ai_disable_veh_ship", SDT_BOOL, (void*)false, (void*)offsetof(Patches, ai_disable_veh_ship), NULL}, |
855 {"ai_disable_veh_ship", SDT_BOOL, (void*)false, (void*)offsetof(Patches, ai_disable_veh_ship), NULL}, |
856 {"starting_date", SDT_UINT32, (void*)1950, (void*)offsetof(Patches, starting_date), NULL}, |
856 {"starting_date", SDT_UINT32, (void*)1950, (void*)offsetof(Patches, starting_date), NULL}, |
873 {"smooth_economy", SDT_BOOL, (void*)false, (void*)offsetof(Patches, smooth_economy), NULL}, |
873 {"smooth_economy", SDT_BOOL, (void*)false, (void*)offsetof(Patches, smooth_economy), NULL}, |
874 {"dist_local_authority",SDT_UINT8, (void*)20, (void*)offsetof(Patches, dist_local_authority), NULL}, |
874 {"dist_local_authority",SDT_UINT8, (void*)20, (void*)offsetof(Patches, dist_local_authority), NULL}, |
875 |
875 |
876 {"wait_oneway_signal", SDT_UINT8, (void*)15, (void*)offsetof(Patches, wait_oneway_signal), NULL}, |
876 {"wait_oneway_signal", SDT_UINT8, (void*)15, (void*)offsetof(Patches, wait_oneway_signal), NULL}, |
877 {"wait_twoway_signal", SDT_UINT8, (void*)41, (void*)offsetof(Patches, wait_twoway_signal), NULL}, |
877 {"wait_twoway_signal", SDT_UINT8, (void*)41, (void*)offsetof(Patches, wait_twoway_signal), NULL}, |
878 |
878 |
879 {"ainew_active", SDT_BOOL, (void*)false, (void*)offsetof(Patches, ainew_active), NULL}, |
879 {"ainew_active", SDT_BOOL, (void*)false, (void*)offsetof(Patches, ainew_active), NULL}, |
880 |
880 |
881 {"drag_signals_density",SDT_UINT8, (void*)4, (void*)offsetof(Patches, drag_signals_density), NULL}, |
881 {"drag_signals_density",SDT_UINT8, (void*)4, (void*)offsetof(Patches, drag_signals_density), NULL}, |
882 |
882 |
883 {NULL, 0, NULL, NULL, NULL} |
883 {NULL, 0, NULL, NULL, NULL} |