This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.h
executable file
·343 lines (327 loc) · 9.62 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
//config.h: Configuration settings
/*
Program title: CMDTYPIST
Author: Chiatiah Calson
License: GPL 3 or later versions
Date and Time: 5 July 2017 @ 10:40PM
Program Size: 2.8
*/
//0=message config, 1=mode config, 2=block confi , 3=sound config, 4: user text config
extern char read_myown_config(void)//num_value is used to record settings for random and standard play
{
char num_value;
FILE *fconf;//file pointer to configuration file
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,4L,SEEK_SET);
fread(&num_value,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
return num_value;
}
extern void write_myown_config(char n)//r is used to record settings for random and standard play
{
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,4L,SEEK_SET);
fwrite(&n,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
}
extern char read_conf_mode(void)//num_value is used to record settings for random and standard play
{
char num_value;
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,1L,SEEK_SET);
fread(&num_value,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
return num_value;
}
extern void write_conf_mode(char n)//r is used to record settings for random and standard play
{
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,1L,SEEK_SET);
fwrite(&n,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
}
extern char read_conf_block_read(void)//num_value is used to record settings for random and standard play
{
char num_value;
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,2L,SEEK_SET);
fread(&num_value,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
return num_value;
}
extern void write_conf_block_read(unsigned int n)//r is used to record settings for random and standard play
{
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,2L,SEEK_SET);
fwrite(&n,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
}
extern char sound_config_read(void)//num_value is used to record settings for random and standard play
{
char num_value;
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,3L,SEEK_SET);
fread(&num_value,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
return num_value;
}
extern void sound_config_write(unsigned int n)//r is used to record settings for random and standard play
{
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,3L,SEEK_SET);
fwrite(&n,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
}
//writing message configuration to config file
extern void write_message_conf(char n)//r is used to record settings for random and standard play
{
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
rewind(fconf);
fwrite(&n,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
}
extern short unsigned int first_time(void)
{
FILE *fconf;
char num_test=8;//value different from 0 or 1
if((fconf=fopen("cmdtypist.conf", "rb+"))==NULL)//opening the file storing information on first time display.
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(1);
}
rewind(fconf);//move to beginnning of the file
fread(&num_test,sizeof(char),1,fconf);
return num_test;
fclose(fconf);
}
extern void confirm_user_exist(void)
{
char num_test=1;
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Unable to read configuration file");
exit(EXIT_FAILURE);
}
rewind(fconf);
fwrite(&num_test,sizeof(char),1,fconf);
if(fclose(fconf)!=0)
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(2);
}
}
/*This function opens a binary file on which zero was initally written, it then checks if the zero is still there,
if yes then it is the first time the program is being opened and then replaces the zero with 1*/
extern void read_message_conf(void)//Function for first time message display
{
if(first_time()==0)//checking to see if its 0 that is found in the file.
{
system("clear");
FILE *fconf;
printf("%s\n", " ============================WELCOME!!!============================ \n");
printf("\n\t\t\t\tCMDTYPIST\n\n It is an extremely fast typing tutor designed to work on ubuntu and other linux distros "
"\ncmd_typist v 1.0 by Chiatiah Calson Noah on the 5th July 2017 @ 10:40PM "
"\n\nThis program is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version."
"\n\nThis program is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
"GNU General Public License for more details.\n");
printf("\n%s\n","Do you want to view full license[y/n]:" );
if(get_only_char()=='y')
{
if((fconf=fopen("LICENSE.md","r"))==NULL)
fprintf(stderr, "%s\n", "GNU GPL license not found in program directory, visit <http://www.gnu.org/licenses/>");
else
{
char ch;
while((ch=getc(fconf))!=EOF)
putchar(ch);
}
if(fclose(fconf)!=0)
{
fprintf(stderr, "%s\n", "Fatal Error, license file is corrupted\n");
exit(2);
}
}
printf("%s\n", "ENTER to continue");
while(ch=getchar()!='\n');//remains here until enter key.
printf("\n%s", "First time tip:\n Enter \"select \"lesson-number\"\" when prompted for a command; lesson-number=valid lesson number"
"\n\n Have a look at the help menu? You can revisit it later using \"cmdtypist --help\" command [y/n]:");
if(get_only_char()=='y')
{
if((fconf=fopen("help.md","r"))==NULL)
fprintf(stderr, "%s\n", "Error: Unable to find help menu");
else
{
printf("\n\n");
char ch;
while((ch=getc(fconf))!=EOF)
putchar(ch);
}
if(fclose(fconf)!=0)
{
fprintf(stderr, "%s\n", "Fatal Error, license file is corrupted\n");
exit(2);
}
}
printf("\n%s\n", "ENTER to continue");
while(ch=getchar()!='\n');//remains here until enter key.
}
}
extern void waiting(char *wait_style)//style in waiting for input.
{
printf("%s",wait_style);
fflush(stdout);
sleepf(1);
printf("%s","." );
fflush(stdout);
sleepf(1);
printf("%s","." );
fflush(stdout);
sleepf(1);
printf("%s","." );
letter_clear(3);
fflush(stdout);
sleepf(1);
printf("%s","." );
fflush(stdout);
sleepf(1);
printf("%s","." );
fflush(stdout);
sleepf(1);
printf("%s","." );
}
//helps to adapt to version by solving problem of erasing a character
//writes one or
extern char adapt_to_ver(void)//num_value is used to record settings for random and standard play
{
char num_value,n;
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,5L,SEEK_SET);
fread(&num_value,sizeof(char),1,fconf);
fseek(fconf,-1,SEEK_CUR);
//num_value=2;//first time value writing, to be commented
if(num_value==1)
{
num_value=2;
fwrite(&num_value,sizeof(char),1,fconf);
}
else if(num_value==2)
{
num_value=1;
fwrite(&num_value,sizeof(char),1,fconf);
}
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
return num_value;
}
extern char adapt_to_ver_read(void)//num_value is used to record settings for random and standard play
{
char num_value;
FILE *fconf;
if((fconf=fopen("cmdtypist.conf","rb+"))==NULL)
{
fprintf(stderr, "%s\n", "Fatal Error, Some files are missing");
exit(EXIT_FAILURE);
}
fseek(fconf,5L,SEEK_SET);
fread(&num_value,sizeof(char),1,fconf);
if(fclose(fconf))
{
fprintf(stderr, "%s\n", "Fatal Error, Unable to close some files\n");
exit(EXIT_FAILURE);
}
return num_value;
}