citic / botNeumann

A metaphorized and gamified visualization of the von Neumann architecture for programming learning
1 stars 0 forks source link

Inject botNeumann code in player's solution #130

Closed jeissonh closed 7 years ago

jeissonh commented 7 years ago

When player's solution is compiled, include an autogenerated hidden bn_player_solution.c file with autogenerated C code in the build process. The autogenerated code is the following changing the paths to the player's solution directory for the unit:

#include <stdio.h>

FILE* bn_reopen_stdin()  { return freopen("/user/player/solution/input.txt",  "r", stdin ); }
FILE* bn_reopen_stdout() { return freopen("/user/player/solution/output.txt", "w", stdout ); }
FILE* bn_reopen_stderr() { return freopen("/user/player/solution/error.txt",  "w", stderr ); }

long bn_tell_stdin()  { return ftell(stdin);  }
long bn_tell_stdout() { return ftell(stdout); }
long bn_tell_stderr() { return ftell(stderr); }

Standard input and output must be redirect to files. On Unix the redirection may be done with the execution arguments:

-exec-arguments < /path/to/input.txt > /path/to/output.txt

On Windows (and all operating systems) by calling the functions to reopen the standard i/o. The functions to tell, will give the number of bytes read or printed. Functions can be called from GDB with print or call

print bn_tell_stdout()
call bn_tell_stdin()
jeissonh commented 7 years ago

I believe a flush() is required before telling() the redirected standard output/error files

jeissonh commented 7 years ago

Code injection already implemented.

Standard I/O redirection is managed in issue #122.