2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 enum{NONE
,BYTE
,WORD
,DWORD
,STRING
,SW_ON
,SW_OFF
,FILES
,KEY
};
51 char cfg_file
[128]="default.cfg";
56 {"file",NULL
,NULL
,FILES
,0},
57 {"cheat",NULL
,&cheat
,SW_ON
,0},
58 {"vga","screenshot",&shot_vga
,SW_ON
,0},
59 {"sndvol","sound_volume",&snd_vol
,WORD
,0},
60 {"musvol","music_volume",&mus_vol
,WORD
,0},
61 // {"fullscr","fullscreen",&fullscreen,SW_ON,0},
62 // {"window",NULL,&fullscreen,SW_OFF,0},
63 {NULL
,"sky",&w_horiz
,SW_ON
,0},
64 {"mon",NULL
,&nomon
,SW_OFF
,0},
65 // {"gamma","gamma",&gammaa,DWORD,0},
66 {"warp",NULL
,&_warp
,BYTE
,0},
67 {"width","screen_width",&SCRW
,DWORD
,0},
68 {"height","screen_height",&SCRH
,DWORD
,0},
69 {NULL
,"music_random",&music_random
,SW_ON
,0},
70 {NULL
,"music_time",&music_time
,DWORD
,0},
71 {NULL
,"music_fade",&music_fade
,DWORD
,0},
72 {NULL
,"pl1_left", &pl1
.kl
,KEY
,0},
73 {NULL
,"pl1_right",&pl1
.kr
,KEY
,0},
74 {NULL
,"pl1_up", &pl1
.ku
,KEY
,0},
75 {NULL
,"pl1_down", &pl1
.kd
,KEY
,0},
76 {NULL
,"pl1_jump", &pl1
.kj
,KEY
,0},
77 {NULL
,"pl1_fire", &pl1
.kf
,KEY
,0},
78 {NULL
,"pl1_next", &pl1
.kwr
,KEY
,0},
79 {NULL
,"pl1_prev", &pl1
.kwl
,KEY
,0},
80 {NULL
,"pl1_use", &pl1
.kp
,KEY
,0},
81 {NULL
,"pl2_left", &pl2
.kl
,KEY
,0},
82 {NULL
,"pl2_right",&pl2
.kr
,KEY
,0},
83 {NULL
,"pl2_up", &pl2
.ku
,KEY
,0},
84 {NULL
,"pl2_down", &pl2
.kd
,KEY
,0},
85 {NULL
,"pl2_jump", &pl2
.kj
,KEY
,0},
86 {NULL
,"pl2_fire", &pl2
.kf
,KEY
,0},
87 {NULL
,"pl2_next", &pl2
.kwr
,KEY
,0},
88 {NULL
,"pl2_prev", &pl2
.kwl
,KEY
,0},
89 {NULL
,"pl2_use", &pl2
.kp
,KEY
,0},
90 {"config",NULL
,cfg_file
,STRING
,0},
91 {NULL
,NULL
,NULL
,NONE
,0}
94 void CFG_args(int argc
, char *argv
[]) {
99 logo("CFG_args: проверка командной строки\n");
103 for (i
=1;i
<argc
;i
++){
104 strcpy(pbuf
,argv
[i
]);
105 pbuf
+=strlen(argv
[i
]);
110 for(s
=strtok(buf
," \r\n\t");s
;s
=strtok(NULL
," \r\n\t")) {//for(s=strtok(getcmd(buf)," \r\n\t");s;s=strtok(NULL," \r\n\t")) {
112 if(*s
=='/' || *s
=='-') ++s
;
113 for(j
=0;cfg
[j
].t
;++j
) if(cfg
[j
].par
) if(strcasecmp(s
,cfg
[j
].par
)==0) {
116 n
=strtol(s
=strtok(NULL
," \r\n\t"),NULL
,0);
117 *((byte
*)cfg
[j
].p
)=(byte
)n
;
120 n
=strtol(s
=strtok(NULL
," \r\n\t"),NULL
,0);
121 *((word
*)cfg
[j
].p
)=(word
)n
;
124 n
=strtol(s
=strtok(NULL
," \r\n\t"),NULL
,0);
125 *((dword
*)cfg
[j
].p
)=n
;
128 strcpy((char *)cfg
[j
].p
,s
=strtok(NULL
," \r\n\t"));
131 *((byte
*)cfg
[j
].p
)=ON
;
132 if(cfg
[j
+1].t
==SW_OFF
&& cfg
[j
+1].p
==cfg
[j
].p
) cfg
[j
+1].o
=1;
133 if(j
>0) if(cfg
[j
-1].t
==SW_OFF
&& cfg
[j
-1].p
==cfg
[j
].p
) cfg
[j
-1].o
=1;
136 *((byte
*)cfg
[j
].p
)=OFF
;
137 if(cfg
[j
+1].t
==SW_ON
&& cfg
[j
+1].p
==cfg
[j
].p
) cfg
[j
+1].o
=1;
138 if(j
>0) if(cfg
[j
-1].t
==SW_ON
&& cfg
[j
-1].p
==cfg
[j
].p
) cfg
[j
-1].o
=1;
141 for(s
=strtok(NULL
," \r\n\t");s
;s
=strtok(NULL
," \r\n\t")) {
142 if(*s
=='/' || *s
=='-') goto next
;
144 logo(" %s НЕ подключен!\n",s
);
150 ERR_failinit("!!! Неизвестный тип в cfg !!!");
157 void CFG_load(void) {
165 char *e
= getenv("HOME");
167 strcpy(&pc
[strlen(pc
)], "/default.cfg");
169 strcpy(pc
, "default.cfg");
171 strcpy(pc
, "/usr/share/doom2d-rembo/default.cfg");
173 logo("default.cfg not found\n");
179 logo("CFG_load: загрузка конфигурации из %s\n",pc
);
180 if((h
=fopen(pc
,"rb"))==NULL
) {
181 perror("Cannot open file");return;
185 if(*s
==';' || s
[1]==';')
187 if(!(p1
=strtok(s
,"\r\n\t=;")))
188 continue; //if(!(p1=strtok(s,"\r\n\t =;"))) continue;
189 if(!(p2
=strtok(NULL
,"\r\n\t=;")))
190 continue;//if(!(p2=strtok(NULL,"\r\n\t =;"))) continue;
191 for(j
=0;cfg
[j
].t
;++j
) {
192 if(cfg
[j
].cfg
&& !cfg
[j
].o
) {
193 if(strcasecmp(p1
,cfg
[j
].cfg
)==0) {
197 *((byte
*)cfg
[j
].p
)=(byte
)n
;
201 *((word
*)cfg
[j
].p
)=(word
)n
;
205 *((dword
*)cfg
[j
].p
)=n
;
208 strcpy((char *)cfg
[j
].p
,p2
);
212 if(strcasecmp(p2
,"ON")==0) {
213 *((byte
*)cfg
[j
].p
)=ON
;
216 if(strcasecmp(p2
,"OFF")==0) {
217 *((byte
*)cfg
[j
].p
)=OFF
;
220 *((byte
*)cfg
[j
].p
)=strtol(p2
,NULL
,0);
226 int k
= I_string_to_key(p2
);
227 if (k
!= KEY_UNKNOWN
) {
228 *((int *)cfg
[j
].p
)=k
;
231 logo("Unknown key in cfg: %s=%s\n",p1
,p2
);
232 logo("List available key names:\n");
233 for(i
= 1; i
<= KEY__LAST
; i
++) {
234 logo(" %s\n", I_key_to_string(i
));
240 ERR_failinit("!!! Неизвестный тип в cfg !!!");
250 void CFG_save(void) {
252 char s[140],str[140];
256 remove("CONFIG.ZZZ");
257 if(rename(cfg_file,"CONFIG.ZZZ")) return;
258 if(!(h=fopen("CONFIG.ZZZ","rt")))
259 {rename("CONFIG.ZZZ",cfg_file);return;}
260 if(!(oh=fopen(cfg_file,"wt")))
261 {fclose(h);rename("CONFIG.ZZZ",cfg_file);return;}
263 if(!fgets(s,128,h)) break;
265 if(!(p=strtok(str,"\r\n\t =;"))) {fprintf(oh,"%s",s);continue;}
266 if(strcasecmp(p,"sound_volume")==0)
267 sprintf(s,"sound_volume=%d\n",snd_vol);
268 else if(strcasecmp(p,"music_volume")==0)
269 sprintf(s,"music_volume=%d\n",mus_vol);
270 else if(strcasecmp(p,"gamma")==0)
271 sprintf(s,"gamma=%d\n",gammaa);
272 else if(strcasecmp(p,"sound_interp")==0)
273 sprintf(s,"sound_interp=%s\n",s_interp?"on":"off");
276 fclose(oh);fclose(h);
277 remove("CONFIG.ZZZ");