|
Lines 25-43
Link Here
|
| 25 |
|
25 |
|
| 26 |
Mika Halttunen <lsoft@mbnet.fi> |
26 |
Mika Halttunen <lsoft@mbnet.fi> |
| 27 |
|
27 |
|
|
|
28 |
09/22/2004 - Changed functions to return bool on success/failure of |
| 29 |
load/save config. Greg Watson <gwatson@linuxlogin.com> |
| 30 |
|
| 28 |
*************************************************************************/ |
31 |
*************************************************************************/ |
| 29 |
|
32 |
|
| 30 |
#include <stdio.h> |
33 |
#include <stdio.h> |
|
|
34 |
#include <string.h> |
| 31 |
#include "config.h" |
35 |
#include "config.h" |
| 32 |
#include "init.h" |
36 |
#include "init.h" |
| 33 |
|
37 |
|
| 34 |
|
38 |
|
| 35 |
// Load config from file |
39 |
// Load config from file |
| 36 |
void load_config(char *file, CONFIG *conf) { |
40 |
bool load_config(char *file, CONFIG *conf) { |
| 37 |
|
41 |
|
| 38 |
FILE *f = fopen(file, "rt"); |
42 |
FILE *f = fopen(file, "rt"); |
| 39 |
if(!f) |
43 |
if (!f) { |
| 40 |
error_msg("Unable to load config file: %s!", file); |
44 |
// If we are not tying to load ~/.tomatoesrc, then |
|
|
45 |
// abort program, since no config was found at all |
| 46 |
if (!strstr(file, "tomatoesrc")) |
| 47 |
error_msg("Unable to load config file: %s!", file); |
| 48 |
|
| 49 |
// return false since we couldn't load |
| 50 |
return false; |
| 51 |
} |
| 41 |
|
52 |
|
| 42 |
fscanf(f, "video_mode = %d x %d\n", &(conf->vid_w), &(conf->vid_h)); |
53 |
fscanf(f, "video_mode = %d x %d\n", &(conf->vid_w), &(conf->vid_h)); |
| 43 |
fscanf(f, "video_mode_color_depth = %d\n", &(conf->vid_color_depth)); |
54 |
fscanf(f, "video_mode_color_depth = %d\n", &(conf->vid_color_depth)); |
|
Lines 56-70
Link Here
|
| 56 |
fscanf(f, "perspective = %d\n", &(conf->perspective_mode)); |
67 |
fscanf(f, "perspective = %d\n", &(conf->perspective_mode)); |
| 57 |
fscanf(f, "moving_style = %d\n", &(conf->moving_style)); |
68 |
fscanf(f, "moving_style = %d\n", &(conf->moving_style)); |
| 58 |
fclose(f); |
69 |
fclose(f); |
|
|
70 |
return true; |
| 59 |
} |
71 |
} |
| 60 |
|
72 |
|
| 61 |
|
73 |
|
| 62 |
// Save config to file |
74 |
// Save config to file |
| 63 |
void save_config(char *file, CONFIG *conf) { |
75 |
bool save_config(char *file, CONFIG *conf) { |
| 64 |
|
76 |
|
| 65 |
FILE *f = fopen(file, "wt"); |
77 |
FILE *f = fopen(file, "wt"); |
| 66 |
if(!f) |
78 |
if(!f) { |
| 67 |
error_msg("Unable to save config file: %s!", file); |
79 |
error_msg("Unable to save config file: %s!", file); |
|
|
80 |
return false; |
| 81 |
} |
| 68 |
|
82 |
|
| 69 |
fprintf(f, "video_mode = %d x %d\n", (conf->vid_w), (conf->vid_h)); |
83 |
fprintf(f, "video_mode = %d x %d\n", (conf->vid_w), (conf->vid_h)); |
| 70 |
fprintf(f, "video_mode_color_depth = %d\n", (conf->vid_color_depth)); |
84 |
fprintf(f, "video_mode_color_depth = %d\n", (conf->vid_color_depth)); |
|
Lines 83-88
Link Here
|
| 83 |
fprintf(f, "perspective = %d\n", (conf->perspective_mode)); |
97 |
fprintf(f, "perspective = %d\n", (conf->perspective_mode)); |
| 84 |
fprintf(f, "moving_style = %d\n", (conf->moving_style)); |
98 |
fprintf(f, "moving_style = %d\n", (conf->moving_style)); |
| 85 |
fclose(f); |
99 |
fclose(f); |
|
|
100 |
return true; |
| 86 |
} |
101 |
} |
| 87 |
|
102 |
|
| 88 |
|
103 |
|