/* Convert a string of hex chars to a buffer of unsigned chars. */ void argv_to_buf(unsigned char **bufp, size_t *lenp, char *arg) { unsigned char *buf; size_t len, i; *bufp = NULL; *lenp = 0; len = strlen(arg); if (len % 2) { fprintf(stderr, "Argument ``%s'' must have even length.\n", arg); return; } buf = malloc(len/2); if (buf == NULL && len > 0) { fprintf(stderr, "Out of memory!\n"); return; } for(i=0;i<len/2;++i) { int hi = ctoh(arg[2*i]); int lo = ctoh(arg[2*i+1]); if (hi < 0 || lo < 0) { free(buf); fprintf(stderr, "Illegal hex char in argument ``%s''.\n", arg); return; } buf[i] = (hi << 4) + lo; } *bufp = buf; *lenp = len/2; }
// // FUNCTION: getPosition() // // PURPOSE: Returns the x and y coordinates of the item tile in the sprite bitmap // void Game::getPosition(int code, int &x, int &y, bool transparency) { // Convert code to hexadecimal char tmp = code; string prt = ""; prt += tmp; string str = ctoh(prt); y = str[1]; if (str[1] >= 'A' && str[1] <= 'F') y -= 7; y -= '0'; y *= 32; x = (transparency) ? (str[0] - '0' + 3) * 32 : (str[0] - '0') * 32; }
int urlencode(const char *src, size_t srclen, char *dst, size_t dstlen) { size_t bytes = 0; while (srclen > 0 && dstlen > 0) { if (isalnum(*src)) { *dst++ = *src++, bytes++, srclen--, dstlen--; } else { if (dstlen < 3) break ; *dst++ = '%'; *dst++ = ctoh(((*src >> 4) & 0xF)); *dst++ = ctoh(((*src) & 0xF)); src++, bytes += 3, srclen--, dstlen -= 3; } } if (srclen) return -ENOSPC; return bytes; }
int main (int argc, char **argv) { FILE *f; int i; int done=0; int maxy=0; int maxx=0; srand (time (0)); if (argc < 2) { printf ("USAGE: rube [-d] [-q] [-i] [-y delay] [-f skip] foo.rub\n"); exit (0); } for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-d")) { debug = 0; } if (!strcmp(argv[i], "-q")) { quiet = 1; debug = 0; } if (!strcmp(argv[i], "-i")) { interactive = 1; debug = 1; } if (!strcmp(argv[i], "-y")) { deldur = atoi(argv[i + 1]); } if (!strcmp(argv[i], "-f")) { debskip = atoi(argv[i + 1]); } } if (!quiet) printf ("Cat's Eye Technologies' RUBE Interpreter v1.5\n"); f = fopen (argv[argc - 1], "r"); if (f == NULL) { printf ("Error : couldn't open '%s' for input.\n", argv[argc - 1]); exit (0); } while (!feof (f)) { int cur = fgetc(f); pg[y * LINEWIDTH + x].c = cur; if (cur == '\n') { pg[y * LINEWIDTH + x].c = ' '; x = 0; y++; if (y >= PAGEHEIGHT) break; } else { x++; if (x > maxx) maxx = x; if (x >= LINEWIDTH) { x = 0; y++; if (y >= PAGEHEIGHT) break; } } } fclose (f); maxy = y; #if MSDOS _setcursortype(_NOCURSOR); #endif if (debug) { printf ("%c[1;1H%c[2J", 27, 27); } while (!done) /*** Intepreting Phase */ { if ((debug) && (!(frame++ % debskip) || (!frame))) { printf ("%c[1;1H", 27); for(y = 0; (y <= maxy) && (y <= SCREENHEIGHT); y++) { for(x = 0; (x <= maxx) && (x <= SCREENWIDTH); x++) { int cur = pg[y * LINEWIDTH + x].c; putc(isprint(cur) ? cur : ' ', stdout); } printf("\n"); } } else { /* putc('.', stdout); */ } fflush (stdout); fflush (stdin); for (x=0; x<=(maxx); x++) { for (y=0; y<=(maxy); y++) { int cur = pg[y * LINEWIDTH + x].c; if (cur <= 32) { if (iscrate(curd(0,-1))) nex = curd(0,-1); /* falling in from above */ if (curd(0,-1) == '(') nex = '('; if (curd(0,-1) == ')') nex = ')'; if (curd(1,1) == 'W') nex = curd(2,2); if (curd(-1,1) == 'W') nex = curd(-2,2); if ((curd(1,1) == 'V') && iscrate(curd(2,1))) nex = curd(2,1); if ((curd(-1,1) == 'V') && iscrate(curd(-2,1))) nex = curd(-2,1); if (curd(1,-1) == 'M') nex = curd(2,-2); if (curd(-1,-1) == 'M') nex = curd(-2,-2); if ((curd(1,-1) == 'A') && iscrate(curd(2,-1))) nex = curd(2,-1); if ((curd(-1,-1) == 'A') && iscrate(curd(-2,-1))) nex = curd(-2,-1); if (curd(0,-1) == '~') nex = '~'; if ((curd(-1,0) == '~') && (issupport(curd(-1,1)))) nex = '~'; if ((curd(1,0) == '~') && (issupport(curd(1,1)))) nex = '~'; if (curd(1,-1) == '+') { if (iscrate(curd(1,0)) && iscrate(curd(2,0))) { nex = htoc((ctoh(curd(1,0))+ctoh(curd(2,0))) % 16); } } if (curd(-1,-1) == '+') { if (iscrate(curd(-1,0)) && iscrate(curd(-2,0))) { nex = htoc((ctoh(curd(-1,0))+ctoh(curd(-2,0))) % 16); } } if (curd(1,-1) == '-') { if (iscrate(curd(1,0)) && iscrate(curd(2,0))) { int z; z = ctoh(curd(2,0)) - ctoh(curd(1,0)); while (z < 0) z += 16; nex = htoc(z); } } if (curd(-1,-1) == '-') { if (iscrate(curd(-1,0)) && iscrate(curd(-2,0))) { int z; z = ctoh(curd(-2,0)) - ctoh(curd(-1,0)); while (z < 0) z += 16; nex = htoc(z); } } if ((curd(1,-1) == 'K') && (iscrate(curd(1,-2)))) { if(ctoh(curd(1,-2)) < ctoh(curd(1,0))) nex = curd(1,-2); } if ((curd(-1,-1) == 'K') && (iscrate(curd(-1,-2)))) { if(ctoh(curd(-1,-2)) >= ctoh(curd(-1,0))) nex = curd(-1,-2); } if ((iscrate(curd(-1,0))) && (curd(-1,1) == '>')) nex = curd(-1,0); if ((iscrate(curd(1,0))) && (curd(1,1) == '<')) nex = curd(1,0); if (curd(0,-1) == ':') nex = curd(0,-2); if ((curd(0,-1) == ';') && (iscrate(curd(0,-2)))) nex = curd(0,-2); if ((curd(0,1) == '.') && (iscrate(curd(0,2)))) nex = curd(0,2); if ((curd(-1,0) == '(') && (curd(1,0) == ')')) /* collision */ { nex = ' '; } else { if ((curd(-1,0) == '(') && (issupport(curd(-1,1)))) nex = '('; if ((curd(1,0) == ')') && (issupport(curd(1,1)))) nex = ')'; if ((curd(0,1) == '/') || (curd(0,1) == '\\')) { if ((curd(-1,1) == '(') && (issupport(curd(-1,2)))) nex = '('; if ((curd(1,1) == ')') && (issupport(curd(1,2)))) nex = ')'; } } if (iscrate(curd(-1,0))) { /* shift crates */ int bx=-1; while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1)))) { if (curd(bx-1,0) == '(') { nex = curd(-1,0); } bx--; } } if (iscrate(curd(1,0))) { int bx=1; while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1)))) { if (curd(bx+1,0) == ')') { nex = curd(1,0); } bx++; } } } else switch (cur) { case '(': if (((curd(1,0) == '(') || (curd(1,0) <= ' ') || (curd(0,1) <= ' ') || (curd(0,1) == '('))) nex = ' '; if (isramp(curd(0,1))) nex = ' '; if (isramp(curd(1,0))) nex = ' '; if (isramp(curd(-1,0))) nex = ' '; if ((isblock(curd(1,0))) || (curd(1,-1) == ',') || (curd(1,0) == '*')) nex = ')'; if (iscrate(curd(1,0))) { int bx=1; while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1)))) { if (isblock(curd(bx+1,0))) { nex = ')'; } bx++; } } break; case ')': if (((curd(-1,0) == ')') || (curd(-1,0) <= ' ') || (curd(0,1) <= ' ') || (curd(0,1) == ')'))) nex = ' '; if (isramp(curd(0,1))) nex = ' '; if (isramp(curd(1,0))) nex = ' '; if (isramp(curd(-1,0))) nex = ' '; if ((isblock(curd(-1,0))) || (curd(-1,-1) == ',') || (curd(-1,0) == '*')) nex = '('; if (iscrate(curd(-1,0))) { int bx=-1; while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1)))) { if (isblock(curd(bx-1,0))) { nex = '('; } bx--; } } break; case 'O': if ((iscrate(curd(0,-1))) && (iscrate(curd(0,-2)))) { int d; d = ctoh(curd(0,-1)) + ctoh(curd(0,-2)) * 16; if (curd(0, 1) == 'b') { if (debug) { char s[80]; printf ("%c[%d;%dH", 27, 25, debopos); sprintf(s, "%d ", (int)d); debopos += strlen(s); if (debopos > SCREENWIDTH) { debopos = 1; printf ("%c[%d;%dH%c[K", 27, 25, 1, 27); debopos += strlen(s); } printf("%s", s); } else { printf("%d ", (int)d); } } if (curd(0, 1) == 'c') { if (debug) { printf ("%c[%d;%dH", 27, 25, debopos++); if (debopos > SCREENWIDTH) { debopos = 1; printf ("%c[%d;%dH%c[K", 27, 25, 1, 27); debopos++; } printf ("%c", (char)d); } else { putc((char)d, stdout); } } } case 'A': if (iscrate(curd(-1,0)) || iscrate(curd(1,0))) nex = 'V'; else nex = cur; break; case 'V': if (iscrate(curd(-1,0)) || iscrate(curd(1,0))) nex = 'A'; else nex = cur; break; default: nex = cur; } if (iscrate(cur)) { if (issupport(curd(0,1))) nex = cur; else nex = ' '; if ((curd(1,0) <= ' ') && (curd(0,1) == '>')) nex = ' '; if ((curd(-1,0) <= ' ') && (curd(0,1) == '<')) nex = ' '; if ((curd(1,-1) == 'W') && (curd(2,-2) == cur)) nex = ' '; if ((curd(-1,-1) == 'W') && (curd(2,-2) == cur)) nex = ' '; if ((curd(1,1) == 'M') && (curd(2,2) == cur)) nex = ' '; if ((curd(-1,1) == 'M') && (curd(-2,2) == cur)) nex = ' '; if (curd(1,0) == 'V') nex = ' '; if (curd(-1,0) == 'V') nex = ' '; if (curd(1,0) == 'A') nex = ' '; if (curd(-1,0) == 'A') nex = ' '; if (iscrate(curd(-1,0)) && ((curd(-1,-1) == '+') || (curd(-1,-1) == '-'))) nex = ' '; if (iscrate(curd(1,0)) && ((curd(1,-1) == '+') || (curd(1,-1) == '-'))) nex = ' '; if ((iscrate(curd(-1,0)) || iscrate(curd(1,0))) && ((curd(0,-1) == '+') || (curd(0,-1) == '-'))) nex = ' '; } } } /* fix nex array */ for (x=0; x<=(maxx); x++) { for (y=0; y<=(maxy); y++) { int cur = pg[y * LINEWIDTH + x].c; switch (cur) { case '*': if (curd(-1,0) == ')') nex = ' '; if (curd(1,0) == '(') nex = ' '; break; case 'O': if ((iscrate(curd(0,-1))) && (iscrate(curd(0,-2)))) { nexd(0,-1)=' '; nexd(0,-2)=' '; } break; } if (iscrate(cur)) { if (curd(1,0) == ')') { int bx=0; int flag=0; while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1)))) { if (curd(bx-1,0) <= ' ') { flag = 1; } bx--; } if (flag) { bx=0; while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1)))) { nexd(bx-1,0) = curd(bx,0); bx--; } nex = ')'; nexd(1,0) = ' '; } } if (curd(-1,0) == '(') { int bx=0; int flag=0; while (iscrate(curd(bx,0)) && (issupport(curd(bx,1)))) { if (curd(bx+1,0) <= ' ') { flag=1; } bx++; } if (flag) { bx=0; while ((iscrate(curd(bx,0))) && (issupport(curd(bx,1)))) { nexd(bx+1,0) = curd(bx,0); bx++; } nex = '('; nexd(-1,0)= ' '; } } if ((curd(-1,0)=='C') || (curd(1,0)=='C') || (curd(0,-1)=='C') || (curd(0,1)=='C')) nex = ' '; } if ((curd(-1,0)=='F') || (curd(1,0)=='F') || (curd(0,-1)=='F') || (curd(0,1)=='F')) nex = ' '; } } if (interactive) { char s[80]; fgets(s, 79, stdin); if (s[0] == 'q') done = 1; } else { if (deldur > 0) { rube_delay (deldur); } #ifdef MSDOS if (kbhit()) { char c; c = getch(); if (c == 27) done = 1; } #endif } memcpy(pg, pg2, LINEWIDTH * PAGEHEIGHT * sizeof(cell)); } if (debug) printf ("%c[22;1H", 27); #if MSDOS _setcursortype(_NORMALCURSOR); #endif exit (0); }
/* Read the fingerprint store from a FILE* into the given * OtrlUserState. Use add_app_data to add application data to each * ConnContext so created. The FILE* must be open for reading. */ gcry_error_t otrl_privkey_read_fingerprints_FILEp(OtrlUserState us, FILE *storef, void (*add_app_data)(void *data, ConnContext *context), void *data) { ConnContext *context; char storeline[1000]; unsigned char fingerprint[20]; size_t maxsize = sizeof(storeline); if (!storef) return gcry_error(GPG_ERR_NO_ERROR); while(fgets(storeline, maxsize, storef)) { char *username; char *accountname; char *protocol; char *hex; char *trust; char *tab; char *eol; Fingerprint *fng; int i, j; /* Parse the line, which should be of the form: * username\taccountname\tprotocol\t40_hex_nybbles\n */ username = storeline; tab = strchr(username, '\t'); if (!tab) continue; *tab = '\0'; accountname = tab + 1; tab = strchr(accountname, '\t'); if (!tab) continue; *tab = '\0'; protocol = tab + 1; tab = strchr(protocol, '\t'); if (!tab) continue; *tab = '\0'; hex = tab + 1; tab = strchr(hex, '\t'); if (!tab) { eol = strchr(hex, '\r'); if (!eol) eol = strchr(hex, '\n'); if (!eol) continue; *eol = '\0'; trust = NULL; } else { *tab = '\0'; trust = tab + 1; eol = strchr(trust, '\r'); if (!eol) eol = strchr(trust, '\n'); if (!eol) continue; *eol = '\0'; } if (strlen(hex) != 40) continue; for(j=0, i=0; i<40; i+=2) { fingerprint[j++] = (ctoh(hex[i]) << 4) + (ctoh(hex[i+1])); } /* Get the context for this user, adding if not yet present */ context = otrl_context_find(us, username, accountname, protocol, 1, NULL, add_app_data, data); /* Add the fingerprint if not already there */ fng = otrl_context_find_fingerprint(context, fingerprint, 1, NULL); otrl_context_set_trust(fng, trust); } return gcry_error(GPG_ERR_NO_ERROR); }