X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=minsk.c;h=4b4b2a3995ac5fd2ab0907a14a7fce692606b5d9;hb=1f1caa3d03716b77e169943c2ece09da7a2e1d87;hp=d9606ef3b424ed857d14cb1b5f448dd47cfd48e1;hpb=9946bcb5ab6feccc486e8ca41d39758e9125f950;p=minsk.git diff --git a/minsk.c b/minsk.c index d9606ef..4b4b2a3 100644 --- a/minsk.c +++ b/minsk.c @@ -4,11 +4,6 @@ * (c) 2010 Martin Mares */ -/* - * TODO: - * - we probably have to disable NOP - */ - /* * Things that are not implemented: * @@ -190,6 +185,8 @@ static void parse_in(void) if (!eol) parse_error("Строка слишком долгая"); *eol = 0; + if (eol > line && eol[-1] == '\r') + *--eol = 0; char *c = line; if (!c[0] || c[0] == ';') @@ -203,6 +200,9 @@ static void parse_in(void) continue; } + if (c[0] == '.') + return; + if (c[0] == '@') { c++; @@ -374,15 +374,13 @@ static void print_ins(int x, int y) eat = 1; break; case 4: // One Russian symbol - bit = 6; - fmt = "r"; + fmt = "xr"; break; case 5: // Russian text fmt = "xrrrrrr"; break; case 6: // One Latin symbol - bit = 6; - fmt = "l"; + fmt = "xl"; break; default: // Latin text fmt = "xllllll"; @@ -439,7 +437,7 @@ static void print_ins(int x, int y) linebuf[pos] = ch; pos = (pos+1) & 0177; } - assert(!bit); + assert(bit >= 0); } static void run(void) @@ -826,9 +824,9 @@ static void run(void) #define TBF_MAX 5 // Max number of tokens in the bucket #define TBF_REFILL_PER_SEC 0.2 // Bucket refill rate (buckets/sec) -#define PID_FILE "/var/run/minsk.pid" -#define UID 65534 -#define GID 65534 +#define PID_FILE "/var/run/pd-minsk.pid" +#define UID 124 +#define GID 125 static void die(char *msg) { @@ -1232,8 +1230,25 @@ static void run_as_daemon(int do_fork) } } +static void init_memory(void) +{ + // For the contest, we fill the whole memory with -00 00 0000 0000 (HALT), + // not +00 00 0000 0000 (NOP). Otherwise, an empty program would reveal + // the location of the password :) + for (int i=0; i<4096; i++) + mem[i] = 01000000000000ULL; + + // Store the password + int pos = 02655; + mem[pos++] = 0574060565373; + mem[pos++] = 0371741405340; + mem[pos++] = 0534051524017; +} + int main(int argc, char **argv) { + init_memory(); + if (argc > 1) { setproctitle_init(argc, argv); @@ -1241,11 +1256,12 @@ int main(int argc, char **argv) run_as_daemon(1); else if (!strcmp(argv[1], "--net")) run_as_daemon(0); + else if (!strncmp(argv[1], "--trace=", 8)) + trace = atoi(argv[1] + 8); else die("Usage: minsk [--daemon | --net]"); } - trace = 3; parse_in(); run(); return 0;