1
0
mirror of https://github.com/elua/elua.git synced 2025-01-25 01:02:54 +08:00

Added file saving xmodem. to use it, run in eLua terminal: recv <path_to_file>

This commit is contained in:
Marcelo Politzer Couto 2011-06-07 18:59:13 -03:00
parent 63ce42492c
commit cc88916c9f

View File

@ -144,7 +144,19 @@ static void shell_recv( char* args )
p ++; p ++;
printf( "done, got %u bytes\n", ( unsigned )( p - shell_prog ) ); printf( "done, got %u bytes\n", ( unsigned )( p - shell_prog ) );
// Execute /* If we've got a parameter, consider it the path to write, if not, run it. */
if (strcmp( args, "") != 0)
{
FILE *foutput = fopen( args, "w" );
if( foutput == NULL )
{
printf( "unable to open file %s\n", args);
return;
}
fwrite( shell_prog, sizeof (char), p - shell_prog, foutput );
printf ("received and saved as %s\n", args);
fclose( foutput );
} else {
if( ( L = lua_open() ) == NULL ) if( ( L = lua_open() ) == NULL )
{ {
printf( "Unable to create Lua state\n" ); printf( "Unable to create Lua state\n" );
@ -159,6 +171,7 @@ static void shell_recv( char* args )
if( lua_pcall( L, 0, LUA_MULTRET, 0 ) != 0 ) if( lua_pcall( L, 0, LUA_MULTRET, 0 ) != 0 )
printf( "Error: %s\n", lua_tostring( L, -1 ) ); printf( "Error: %s\n", lua_tostring( L, -1 ) );
lua_close( L ); lua_close( L );
}
free( shell_prog ); free( shell_prog );
shell_prog = NULL; shell_prog = NULL;
#endif // #ifndef BUILD_XMODEM #endif // #ifndef BUILD_XMODEM