Skip to content

Commit cd5c4ca

Browse files
committed
update custom select
1 parent ede8f0f commit cd5c4ca

File tree

4 files changed

+61
-6
lines changed

4 files changed

+61
-6
lines changed

lib/checkdata.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ bool checkdata (int &count)
2323

2424
bool check_custom_data (char *name)
2525
{
26-
char *p;
26+
char p[200];
2727
strcpy (p, "usr/custom/world/");
2828
strcat (p, name);
2929
strcat (p, "/main");
3030
struct stat buffer;
31-
if (stat (name, &buffer) != 0)
31+
if (stat (p, &buffer) != 0)
3232
{
3333
printf ("Cannot read data! Please check 'usr/custom/world' folder.\n");
3434
printf ("More info: https://github.com/ohzff/Zff-Reload/\n");

lib/move.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ inline int check(int num){
1919
if(num==32)return 32;
2020
if(num==127)return 127;
2121
if(num=='/')return num;
22+
if(num=='l')return num;
2223
if(num==224||num==-32||num == 91)return -1;
2324
return 0;
2425
}
@@ -246,7 +247,7 @@ void command ()
246247
{
247248
int read = keyboard ();
248249
if (read == 27) return;
249-
if (read == 127)
250+
if (read == 127 && strlen (BOTTOM_LEFT_INFO) > 1)
250251
{
251252
BOTTOM_LEFT_INFO[strlen (BOTTOM_LEFT_INFO) - 1] = '\0';
252253
}
@@ -274,7 +275,7 @@ void command ()
274275
return;
275276
}
276277
}
277-
strcpy (BOTTOM_LEFT_INFO, "ERROR");
278+
strcpy (BOTTOM_LEFT_INFO, " Error");
278279
msleep (OUTPUT_TIME * 1000);
279280
return;
280281
}

lib/select.cpp renamed to lib/select.hpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,43 @@ void sel_windowsize_protect ()
1010
}
1111
}
1212

13+
char ipt[100];
14+
15+
int sel_command ()
16+
{
17+
strcpy (ipt, "");
18+
while (true)
19+
{
20+
int read = keyboard ();
21+
if (read == 27) return 0;
22+
if (read == 127 && strlen (ipt) > 0)
23+
{
24+
ipt[strlen (ipt) - 1] = '\0';
25+
BOTTOM_LEFT_INFO[strlen (BOTTOM_LEFT_INFO) - 1] = '\0';
26+
}
27+
else if ((read >= 'a' && read <= 'z') || (read >= '0' && read <= '9') || read == ' ')
28+
{
29+
char tmp[2] = {char (read)};
30+
strcat (ipt, tmp);
31+
strcat (BOTTOM_LEFT_INFO, tmp);
32+
}
33+
else if (read == 10)
34+
{
35+
if (check_custom_data (ipt))
36+
{
37+
return 1;
38+
}
39+
else
40+
{
41+
strcpy (BOTTOM_LEFT_INFO, " Error");
42+
msleep (OUTPUT_TIME * 1000);
43+
return 0;
44+
}
45+
}
46+
}
47+
return 0;
48+
}
49+
1350
int doselect ()
1451
{
1552
int read;
@@ -20,10 +57,18 @@ int doselect ()
2057
strcpy (BOTTOM_RIGHT_INFO, inttochar (pid + 1));
2158
strcat (BOTTOM_RIGHT_INFO, "/");
2259
strcat (BOTTOM_RIGHT_INFO, inttochar (PIDMAX));
23-
while ((read < 1 || read > 4) && read != 9 && read != 32 && read != '/' && read != 10)
60+
while ((read < 1 || read > 4) && read != 9 && read != 32 && read != 'l' && read != 10)
2461
{
2562
read = check (keyboard ());
2663
}
64+
if (read == 'l')
65+
{
66+
strcpy (BOTTOM_LEFT_INFO, " Load: ");
67+
if (sel_command () == 1)
68+
{
69+
return -2;
70+
}
71+
}
2772
if (read == 3)
2873
{
2974
if (pid > 0)
@@ -82,6 +127,7 @@ int func_select ()
82127
SEL_OUTPUT_STOP = 1;
83128

84129
if (k == -1) return -1;
130+
else if (k == -2) return -2;
85131
else return pid + 1;
86132
}
87133

main.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace std;
1515
#include "lib/checkdata.hpp"
1616
#include "lib/output.hpp"
1717
#include "lib/move.hpp"
18-
#include "lib/select.cpp"
18+
#include "lib/select.hpp"
1919
#include "lib/version.hpp"
2020

2121
int readytorun (int &i)
@@ -79,6 +79,14 @@ int main (int argc, char * argv[])
7979

8080
int k = func_select ();
8181
if (k == -1) return 0;
82+
if (k == -2)
83+
{
84+
if (check_custom_data (ipt)) return 1;
85+
read_world (-1, string (ipt));
86+
int a = 0;
87+
readytorun (a);
88+
return 0;
89+
}
8290
START = k;
8391

8492
for (int i = START; i <= PIDMAX; i ++)

0 commit comments

Comments
 (0)