@@ -20,6 +20,7 @@ static int need_restart = 0;
2020static int need_load = 0 ;
2121static int need_save = 0 ;
2222static int parser_mode = 0 ;
23+ static int menu_mode = 0 ;
2324
2425static int luaB_menu (lua_State * L )
2526{
@@ -118,12 +119,12 @@ static void footer(void)
118119 char * p ;
119120 p = instead_cmd ("way" , NULL );
120121 if (p && * p ) {
121- puts (">> " ); fmt (trim (p ), opt_width );
122+ printf (">> " ); fmt (trim (p ), opt_width );
122123 free (p );
123124 }
124125 p = instead_cmd ("inv" , NULL );
125126 if (p && * p ) {
126- puts ("** " ); fmt (trim (p ), opt_width );
127+ printf ("** " ); fmt (trim (p ), opt_width );
127128 free (p );
128129 }
129130}
@@ -138,7 +139,8 @@ static void reopen_stderr(const char *fname)
138139
139140static char * get_input (void )
140141{
141- static char input [256 ], * p ;
142+ static char input [256 ];
143+ char * p ;
142144 input [0 ] = 0 ;
143145 p = fgets (input , sizeof (input ), stdin );
144146 if (p && * p ) {
@@ -178,7 +180,7 @@ int main(int argc, const char **argv)
178180 }
179181
180182 if (!game ) {
181- fprintf (stdout , "Usage: %s [-d] [-w<width>] <game>\n" , argv [0 ]);
183+ fprintf (stdout , "Usage: %s [-d<file> ] [-w<width>] [-i<script>] [-l<log >] <game>\n" , argv [0 ]);
182184 exit (1 );
183185 }
184186
@@ -196,6 +198,9 @@ int main(int argc, const char **argv)
196198 fprintf (stdout , "Can not init game: %s\n" , game );
197199 exit (1 );
198200 }
201+ #ifdef _WIN32
202+ instead_set_encoding ("CP1251" );
203+ #endif
199204 if (instead_load (NULL )) {
200205 fprintf (stdout , "Can not load game: %s\n" , instead_err ());
201206 exit (1 );
@@ -225,33 +230,39 @@ int main(int argc, const char **argv)
225230 if (!strcmp (p , "/quit" ))
226231 break ;
227232
228- if (!strncmp (p , "/load " , 6 ) || !strncmp (p , "/save " , 6 )) {
229- rc = 1 ; str = NULL ;
230- } else {
233+ rc = 1 ; str = NULL ;
234+
235+ if (* p == '/' ) {
236+ p ++ ;
237+ snprintf (cmd , sizeof (cmd ), "%s" , p );
238+ str = instead_cmd (cmd , & rc );
239+ } else if (!parser_mode ) {
231240 snprintf (cmd , sizeof (cmd ), "use %s" , p ); /* try use */
232241 str = instead_cmd (cmd , & rc );
233242 if (rc ) { /* try go */
234243 free (str );
235244 snprintf (cmd , sizeof (cmd ), "go %s" , p );
236245 str = instead_cmd (cmd , & rc );
237246 }
247+ if (!rc )
248+ menu_mode = 1 ;
249+ }
250+ if (rc && !str && !menu_mode ) { /* parser? */
251+ parser_mode = 1 ;
252+ snprintf (cmd , sizeof (cmd ), "@metaparser \"%s\"" , p );
253+ str = instead_cmd (cmd , & rc );
238254 }
239255 if (rc ) { /* try act */
240256 free (str );
241- snprintf (cmd , sizeof (cmd ), "%s" , p );
257+ snprintf (cmd , sizeof (cmd ), "act %s" , p );
242258 str = instead_cmd (cmd , & rc );
243259 }
244- if (rc && !str ) { /* parser? */
245- parser_mode = 1 ;
246- snprintf (cmd , sizeof (cmd ), "@metaparser \"%s\"" , p );
247- str = instead_cmd (cmd , NULL );
248- }
249260 if (str ) {
250261 fmt (trim (str ), opt_width );
251262 fflush (stdout );
263+ free (str );
252264 }
253- free (str );
254- if (!rc && !parser_mode ) /* no parser */
265+ if (!parser_mode )
255266 footer ();
256267 if (opt_log )
257268 fprintf (stderr , "%s\n" , p );
0 commit comments