-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstuff.cc
More file actions
121 lines (118 loc) · 1.98 KB
/
stuff.cc
File metadata and controls
121 lines (118 loc) · 1.98 KB
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
#include "acejudge.h"
run_res mkres(int res, int time, int mem) {
run_res r;
r. res_num = res;
r. time = time;
r. mem = mem;
return r;
}
/*color list:
* 30 : gray
* 31 : red
* 32 : green
* 33 : yellow
* 34 : blue
* 35 : purple
* 36 : olive
*/
void setcolor(int x) {
static int now_color = 0, prv_color;
if (x == -1) {
swap(now_color, prv_color);
}
else {
prv_color = now_color;
now_color = x;
}
printf("\33[%dm", now_color);
}
bool is_letter(int x) {
return (x > 64 && x < 92) || (x > 96 && x < 124);
}
void get_char_pre() {
struct termios new_s;
struct termios old_s;
tcgetattr(0, &old_s);
new_s = old_s;
new_s. c_lflag &= (~ICANON);
// new_s. c_cc[VTIME] = 0;
// new_s. c_cc[VMIN] = 1;
tcsetattr(0, TCSANOW, &new_s);
}
void get_char_undo() {
struct termios new_s;
struct termios old_s;
tcgetattr(0, &old_s);
new_s = old_s;
new_s. c_lflag |= ICANON;
// new_s. c_cc[VTIME] = 0;
// new_s. c_cc[VMIN] = 1;
tcsetattr(0, TCSANOW, &new_s);
}
int get_cmd() {
char o;
get_char_pre();
do
o = getchar();
while (!is_letter(o));
get_char_undo();
putchar(10);
return (o > 96) ? (o - 32) : o;
}
void get_key() {
get_char_pre();
getchar();
get_char_undo();
}
void get_str(char *str) {
char buf[max_path], od[max_path];
setcolor(35);
while (1) {
scanf("%s", buf);
if (strcmp(buf, "old") == 0)
break;
else if (strcmp(buf, "ls") == 0) {
scanf("%s", buf);
setcolor(32);
puts("File list");
setcolor(37);
sprintf(od, "ls %s", buf);
system(od);
setcolor(35);
}
else {
strcpy(str, buf);
break;
}
}
setcolor(-1);
}
void get_int(int &num) {
char buf[max_path];
setcolor(35);
scanf("%s", buf);
if (strcmp(buf, "\\o"))
sscanf(buf, "%d", &num);
setcolor(-1);
}
void file_wrong() {
//setcolor(31);
puts("Wrong file");
}
inline void str_clr(char*) {
// if (x)
// delete x;
}
inline void str_new(char* &x) {
str_clr(x);
x = new char[max_path];
}
void str_cut(char *p) {
while (*p)
if (*p == '\"') {
*p = 0;
break;
}
else
p ++;
}