Nastrel pthread_mq
[mirrors/Programs.git] / misc / gbook_offline / gb_console.php
... / ...
CommitLineData
1<?php\r
2\r
3//READLINE Function\r
4function readline($prompt="") {\r
5 echo $prompt;\r
6 \r
7 /*\r
8 $ifp = fopen("php://stdin", "r"); //PHP <= 4\r
9 $line = fgets($ifp, 999); //PHP <= 4\r
10 fclose($ifp); //PHP <= 4\r
11 */\r
12 \r
13 $line = fgets(STDIN, 999); //PHP >= 5\r
14 return trim($line);\r
15}\r
16//READLINE End\r
17\r
18//Hobit-01.txt\r
19\r
20//Settings:\r
21$prompt = "\n> ";\r
22$random_out = "Random judged: ";\r
23$nextf_out = "\nNext file: ";\r
24exec("chcp 1250"); //Only Windows - set CP1250 - national alphabets - needed for Cestina ;)\r
25\r
26//CODE\r
27//Init:\r
28$game = ""; //Hra natazena v pameti\r
29$file = ""; //Posledni otevreny soubor\r
30$nextf = ""; //Soubor nacteny z odkazu\r
31$pos = 2; //Pozice ve hre\r
32$histpos = "1";\r
33$hist[$histpos] = "START";\r
34\r
35\r
36echo(\r
37"OGB Engine 0.6\n".\r
38"Harvie 2oo7\n".\r
39"http://gbook.wz.cz/\n".\r
40"-----------------------\n".\r
41"Type h[ENTER] for help.\n"\r
42);\r
43\r
44while(1) {\r
45\r
46 $in_line = readline($prompt); \r
47 $in_cmds = explode(" ", $in_line);\r
48 $in_cmds[0] = strtolower($in_cmds[0]);\r
49 \r
50 //h - print help\r
51 if ($in_cmds[0] == "h") {\r
52 echo(\r
53 "HELP:\n".\r
54 "h - Show help\n".\r
55 "f - Show files\n".\r
56 "l file - Load file\n".\r
57 "l URL - Load file from HTTP or FTP\n".\r
58 "y - set CP 1250 ONLY WINDOWS!!! (for some national characters)\n".\r
59 "# - Go to line #\n".\r
60 "2 - Go to start\n".\r
61 "p - Print history\n".\r
62 "n - Load next file from link\n".\r
63 "r - Reload file\n".\r
64 "c - Close file\n".\r
65 "q - Quit\n"\r
66 ); \r
67 }\r
68\r
69 //l - load game\r
70 if ($in_cmds[0] == "l") {\r
71 if ( file_exists( trim($in_cmds[1]) ) || strpos(" ".$in_cmds[1], ":") )\r
72 {\r
73 if ( strpos(" ".$in_cmds[1], ":") ) {\r
74 echo("DOWNLOADING...\n");\r
75 }\r
76 $game = file( trim($in_cmds[1]) );\r
77 $file = trim($in_cmds[1]);\r
78 $histpos++;\r
79 $hist[$histpos] = "\nLOAD: ".trim($in_cmds[1])."\n";\r
80 echo("LOADED: $in_cmds[1]\n");\r
81 print_r(explode("|", $game[0]));\r
82 echo("\n");\r
83 }\r
84 else\r
85 {\r
86 echo("CAN'T LOAD: $in_cmds[1]\n");\r
87 }\r
88 }\r
89 \r
90 //r - reload\r
91 if ($in_cmds[0] == "r") {\r
92 $histpos++;\r
93 $hist[$histpos] = "RELOAD";\r
94 $game = file($file);\r
95 }\r
96 \r
97 //p - history\r
98 if ($in_cmds[0] == "p") {\r
99 echo( implode(";", $hist) );\r
100 }\r
101 \r
102 //c - close\r
103 if ($in_cmds[0] == "c") {\r
104 $histpos++;\r
105 $hist[$histpos] = "CLOSE\n";\r
106 $game = ("");\r
107 }\r
108 \r
109 //# - show line\r
110 if ( is_numeric( trim($in_cmds[0]) ) ) {\r
111 $pos = round(trim($in_cmds[0]));\r
112 $posi = ($pos - 1);\r
113 if(isset($game[$posi])) {\r
114\r
115 //history\r
116 $histpos++;\r
117 $hist[$histpos] = $pos;\r
118\r
119 //nextf\r
120 if ( strpos( (" ".$game[$posi]), "%%" ) ) {\r
121 $nextf = explode("%%", $game[$posi]);\r
122 $nextf = explode("|", $nextf[1]);\r
123 $nextf = $nextf[0];\r
124 }\r
125 \r
126 //rnd\r
127 $rnd = "";\r
128 if ( strpos( (" ".$game[$posi]), "{" ) ) {\r
129 $rnd = explode("{", $game[$posi]);\r
130 $rnd = explode("}", $rnd[1]);\r
131 $rnd = explode("\\\\", $rnd[0]);\r
132 $rnd = $rnd[rand( 0, (sizeof($rnd) - 1) )];\r
133 $rnd = ($random_out.$rnd);\r
134 }\r
135 \r
136 //out\r
137 echo("$pos: ". $game[$posi]);\r
138 \r
139 //rnd\r
140 echo ($rnd);\r
141 \r
142 //nextf\r
143 if( is_file($nextf) ) {\r
144 echo($nextf_out.$nextf."\nType n[ENTER]2[ENTER] to go on.");\r
145 }\r
146 }\r
147 }\r
148 \r
149 //f - files\r
150 if ( $in_cmds[0] == "f" ) {\r
151 echo("FILES:\n\n");\r
152 $dfp=opendir('.');\r
153 while (false!==($file = readdir($dfp))) {\r
154 if ($file != "." && $file != "..") {\r
155 echo "$file\n";\r
156 }\r
157 }\r
158 closedir($dfp);\r
159 }\r
160 \r
161 //y - CP 1250 (needed for Czech language)\r
162 if ( $in_cmds[0] == "y" ) {\r
163 system("chcp 1250"); //Only Windows\r
164 }\r
165 \r
166 //i - info\r
167 if ($in_cmds[0] == "i") {\r
168 print_r(explode("|", $game[0]));\r
169 echo("\n");\r
170 }\r
171 \r
172 //n - nextfile\r
173 if ($in_cmds[0] == "n" && is_file($nextf) ) {\r
174 $game = file($nextf);\r
175 $file = $nextf;\r
176 $histpos++;\r
177 $hist[$histpos] = "\n\r
178 NEXTF: $nextf\n";\r
179 $nextf = "";\r
180 }\r
181 \r
182 //q - quit\r
183 if ($in_cmds[0] == "q") {\r
184 die("Exited by user at $file - $pos.\n");\r
185 }\r
186\r
187}\r
188\r
189?>\r
This page took 0.204611 seconds and 4 git commands to generate.