|
|
@@ -39,14 +39,26 @@ void sighandler(int signal) |
|
|
|
|
|
|
|
void bytecode(unsigned char * mem, int heap_size, int stack_size) |
|
|
|
{ |
|
|
|
char mode[] = "-0"; |
|
|
|
char *argv[] = { "program", mode, "arg" }; |
|
|
|
char args[10][1024]; |
|
|
|
char *argv[] = { args[0], args[1], args[2], args[3], args[4], |
|
|
|
args[5], args[6], args[7], args[8], args[9] }; |
|
|
|
int i, argc; |
|
|
|
char c; |
|
|
|
|
|
|
|
if(sys_read(0, mode + 1, 1) != 1) |
|
|
|
if(sys_read(0, &c, 1) != 1) |
|
|
|
sys_exit(-5); |
|
|
|
argc = (unsigned char)c; |
|
|
|
|
|
|
|
for(i = 0; i < argc; i++) |
|
|
|
{ |
|
|
|
char *p = argv[i]; |
|
|
|
do |
|
|
|
if(sys_read(0, p, 1) != 1) |
|
|
|
sys_exit(-5); |
|
|
|
while(*p++); |
|
|
|
} |
|
|
|
|
|
|
|
main(sizeof(argv)/sizeof(*argv), argv); |
|
|
|
main(argc, argv); |
|
|
|
|
|
|
|
c = 0; |
|
|
|
if(sys_write(1, &c, 1) != 1) |
|
|
@@ -80,10 +92,8 @@ static int myatoi(const char *str) |
|
|
|
sys_write(1, b + 1, (int)(buf + 127 - b)); \ |
|
|
|
} while(0) |
|
|
|
|
|
|
|
static void msg(const char *f, ...) |
|
|
|
static void out(FILE *stream, const char *f, va_list args) |
|
|
|
{ |
|
|
|
va_list args; |
|
|
|
va_start(args, f); |
|
|
|
#ifdef BYTECODE |
|
|
|
static char const *hex2char = "0123456789abcdef"; |
|
|
|
|
|
|
@@ -141,22 +151,18 @@ static void msg(const char *f, ...) |
|
|
|
} |
|
|
|
else if(f[0] == 'g') |
|
|
|
{ |
|
|
|
double g = va_arg(args, double), h = 9.9f; |
|
|
|
int i; |
|
|
|
if(g < 0.f) |
|
|
|
{ |
|
|
|
sys_write(1, "-", 1); |
|
|
|
g = -g; |
|
|
|
} |
|
|
|
double g = va_arg(args, double), h = 0.0000001; |
|
|
|
int i = g; |
|
|
|
WRITE_INT(i, 10); |
|
|
|
for(i = 0; i < 7; i++) |
|
|
|
{ |
|
|
|
sys_write(1, hex2char + (int)g, 1); |
|
|
|
if(i == 0) |
|
|
|
sys_write(1, ".", 1); |
|
|
|
g = (g - (int)g) * 10; |
|
|
|
h = h / 10.f; |
|
|
|
h *= 10; |
|
|
|
if(g < h) |
|
|
|
break; |
|
|
|
if(i == 0) |
|
|
|
sys_write(1, ".", 1); |
|
|
|
sys_write(1, hex2char + (int)g, 1); |
|
|
|
} |
|
|
|
} |
|
|
|
else if(f[0] == 'p') |
|
|
@@ -196,9 +202,24 @@ static void msg(const char *f, ...) |
|
|
|
} |
|
|
|
} |
|
|
|
#else |
|
|
|
vprintf(f, args); |
|
|
|
fflush(stdout); |
|
|
|
vfprintf(stream, f, args); |
|
|
|
fflush(stream); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
static void err(const char *f, ...) |
|
|
|
{ |
|
|
|
va_list args; |
|
|
|
va_start(args, f); |
|
|
|
out(stderr, f, args); |
|
|
|
va_end(args); |
|
|
|
} |
|
|
|
|
|
|
|
static void msg(const char *f, ...) |
|
|
|
{ |
|
|
|
va_list args; |
|
|
|
va_start(args, f); |
|
|
|
out(stdout, f, args); |
|
|
|
va_end(args); |
|
|
|
} |
|
|
|
|
|
|
@@ -752,7 +773,7 @@ static double *dbs(double const *src, double const *orig, |
|
|
|
changes++; |
|
|
|
} |
|
|
|
|
|
|
|
fprintf(stderr, "did %i changes\n", changes); |
|
|
|
err("did %i changes\n", changes); |
|
|
|
|
|
|
|
if(changes == 0) |
|
|
|
break; |
|
|
@@ -828,13 +849,15 @@ static double *merge(double const *im1, double const *im2, double t) |
|
|
|
|
|
|
|
static void usage(char *argv[]) |
|
|
|
{ |
|
|
|
fprintf(stderr, "Usage: %s <mode> [ARGS...]\n", argv[0]); |
|
|
|
fprintf(stderr, "Allowed modes:\n"); |
|
|
|
fprintf(stderr, " -1 <src> raster FS displacement study on src\n"); |
|
|
|
fprintf(stderr, " -2 <src1> <src2> raster FS displacement study on blends of src1 and src2\n"); |
|
|
|
fprintf(stderr, " -3 <src> quick (a,b,c,d) ED kernel analysis on src\n"); |
|
|
|
fprintf(stderr, " -4 <src> exhaustive (a,b,c,d) ED kernel analysis on src\n"); |
|
|
|
fprintf(stderr, " -5 <src> exhaustive displacement study on src\n"); |
|
|
|
msg("Usage: %s <mode> [ARGS...]\n", argv[0]); |
|
|
|
msg("Allowed modes:\n"); |
|
|
|
msg(" -1 <src> raster FS displacement study on src\n"); |
|
|
|
msg(" -2 <src1> <src2> raster FS displacement study on blends of src1 and src2\n"); |
|
|
|
msg(" -3 <src> quick (a,b,c,d) ED kernel analysis on src\n"); |
|
|
|
msg(" -4 <src> exhaustive (a,b,c,d) ED kernel analysis on src\n"); |
|
|
|
msg(" -5 <src> exhaustive displacement study on src\n"); |
|
|
|
msg(" -6 <src> restrained (a,b,c,d) ED kernel analysis on src\n"); |
|
|
|
msg(" -7 <src> restrained displacement study on src\n"); |
|
|
|
} |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
@@ -844,14 +867,14 @@ int main(int argc, char *argv[]) |
|
|
|
|
|
|
|
if(argc < 2) |
|
|
|
{ |
|
|
|
fprintf(stderr, "%s: too few arguments\n", argv[0]); |
|
|
|
err("%s: too few arguments\n", argv[0]); |
|
|
|
usage(argv); |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
|
|
|
|
if(argv[1][0] != '-' || !(mode = atoi(argv[1] + 1))) |
|
|
|
{ |
|
|
|
fprintf(stderr, "%s: invalid mode `%s'\n", argv[0], argv[1]); |
|
|
|
err("%s: invalid mode `%s'\n", argv[0], argv[1]); |
|
|
|
usage(argv); |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|