This repository was archived by the owner on Mar 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinput.c
135 lines (126 loc) · 2.22 KB
/
input.c
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
#include "universal.h"
#include <stdlib.h>
#include <string.h>
extern Data_t Local;
extern char buffered;
extern short quit_chosen;
void switch_state()
{
char temp= Local.state;
Local.state= Local.previous;
Local.previous= temp;
}
_Bool press_a()
{
_Bool ret;
char in;
system("/bin/stty raw");
while(1) //loop infinito
{
in= getchar();
printf("\r \r");
if(in=='a')
break; //esce dal loop se digito 'a'
if(in=='q')
{
quit_chosen= 1;
switch_state();
break;
}
}
system("/bin/stty cooked");
ret= in=='a'? 1: 0;
return ret;
}
//dovrebbe essere l'ultima funzione chiamata prima di rivalutare il loop
_Bool choice(short* chosen, short choices)
{
_Bool ret;
char in;
system("/bin/stty raw");
while(1)
{
in= getchar();
printf("\r \r");
if(in=='q')
{
quit_chosen= 1;
switch_state();
break;
}
if(in=='a')
break;
if(in=='A' && *chosen>1)
{
*chosen-= 1;
break;
}
if(in=='B' && *chosen<choices)
{
*chosen+= 1;
break;
}
}
system("/bin/stty cooked");
ret= in=='a'? 1: 0;
return ret;
}
_Bool new_name()
{
_Bool existent= 0;
char* txt;
FILE* pf;
char* name= calloc(32,sizeof(char));
int n= 0;
char c;
while(1)
{
system("clear");
print_name(name);
system("/bin/stty raw");
while((c=getchar()))
{
if(((c <='z' && c>='a')||(c<='Z' && c>='A'))&& n<31)
name[n++]= c;
if(c=='-' && n)
n--;
break;
}
name[n]='\0';
system("/bin/stty cooked");
if(c=='.')
break;
continue;
}
printf("\r \r");
if(!n)
{
puts("");
print_center("Annullato"); //OUTPUT
return 0;
}
strcpy(Local.name,name);
free(name);
pf= fopen("saves/saves.txt","a+");
if(!pf)
alloc_error(__func__);
while(getc(pf)!=EOF)
{
txt= sstring(pf,'\n');
if(!strcmp(txt, Local.name))
{
existent= 1;
break;
}
free(txt);
}
if(existent || Local.name[0]==' ')
{
puts("");
print_center("Nome già utilizzato"); //OUTPUT
return 0;
}
fprintf(pf, "#%s\n", Local.name);
fclose(pf);
return 1;
}