char *read_piece(piece_t *piece, unsigned long number) { int c; unsigned long rows, columns, cell, i, j; scanf("%lu", &rows); if (!rows) { return NULL; } scanf("%lu", &columns); if (!columns) { return NULL; } while (fgetc(stdin) != '\n'); if (!set_piece(piece, number, rows, columns, 0UL)) { return NULL; } cell = 0; for (i = 0; i < piece->rows; i++) { j = 0; do { c = fgetc(stdin); if (c == '\n') { break; } else if (isblock(c)) { piece->blocks_n++; piece->cells[cell] = (char)c; } else { piece->cells[cell] = ' '; } cell++; j++; } while (j < piece->columns1); if (j < piece->columns1) { while (j < piece->columns1) { piece->cells[cell++] = ' '; j++; } } else { while (fgetc(stdin) != '\n'); } piece->cells[cell++] = '\n'; } piece->cells[cell] = 0; if (!piece->blocks_n || !set_piece_blocks(piece)) { FREE(piece->cells); } return piece->cells; }
/* * allocate a block or frag */ daddr64_t alloc(int size, int mode) { int i, frag; daddr64_t d, blkno; rdfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize, (char *)&acg); if (acg.cg_magic != CG_MAGIC) { warnx("cg 0: bad magic number"); return (0); } if (acg.cg_cs.cs_nbfree == 0) { warnx("first cylinder group ran out of space"); return (0); } for (d = 0; d < acg.cg_ndblk; d += sblock.fs_frag) if (isblock(&sblock, cg_blksfree(&acg), d / sblock.fs_frag)) goto goth; warnx("internal error: can't find block in cyl 0"); return (0); goth: blkno = fragstoblks(&sblock, d); clrblock(&sblock, cg_blksfree(&acg), blkno); acg.cg_cs.cs_nbfree--; sblock.fs_cstotal.cs_nbfree--; fscs[0].cs_nbfree--; if (mode & IFDIR) { acg.cg_cs.cs_ndir++; sblock.fs_cstotal.cs_ndir++; fscs[0].cs_ndir++; } if (Oflag <= 1) { cg_blktot(&acg)[cbtocylno(&sblock, d)]--; cg_blks(&sblock, &acg, cbtocylno(&sblock, d)) [cbtorpos(&sblock, d)]--; } if (size != sblock.fs_bsize) { frag = howmany(size, sblock.fs_fsize); fscs[0].cs_nffree += sblock.fs_frag - frag; sblock.fs_cstotal.cs_nffree += sblock.fs_frag - frag; acg.cg_cs.cs_nffree += sblock.fs_frag - frag; acg.cg_frsum[sblock.fs_frag - frag]++; for (i = frag; i < sblock.fs_frag; i++) setbit(cg_blksfree(&acg), d + i); } wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize, (char *)&acg); return (d); }
/* * allocate a block or frag */ ufs2_daddr_t alloc(int size, int mode) { int i, blkno, frag; uint d; bread(&disk, part_ofs + fsbtodb(&sblock, cgtod(&sblock, 0)), (char *)&acg, sblock.fs_cgsize); if (acg.cg_magic != CG_MAGIC) { printf("cg 0: bad magic number\n"); exit(38); } if (acg.cg_cs.cs_nbfree == 0) { printf("first cylinder group ran out of space\n"); exit(39); } for (d = 0; d < acg.cg_ndblk; d += sblock.fs_frag) if (isblock(&sblock, cg_blksfree(&acg), d / sblock.fs_frag)) goto goth; printf("internal error: can't find block in cyl 0\n"); exit(40); goth: blkno = fragstoblks(&sblock, d); clrblock(&sblock, cg_blksfree(&acg), blkno); if (sblock.fs_contigsumsize > 0) clrbit(cg_clustersfree(&acg), blkno); acg.cg_cs.cs_nbfree--; sblock.fs_cstotal.cs_nbfree--; fscs[0].cs_nbfree--; if (mode & IFDIR) { acg.cg_cs.cs_ndir++; sblock.fs_cstotal.cs_ndir++; fscs[0].cs_ndir++; } if (size != sblock.fs_bsize) { frag = howmany(size, sblock.fs_fsize); fscs[0].cs_nffree += sblock.fs_frag - frag; sblock.fs_cstotal.cs_nffree += sblock.fs_frag - frag; acg.cg_cs.cs_nffree += sblock.fs_frag - frag; acg.cg_frsum[sblock.fs_frag - frag]++; for (i = frag; i < sblock.fs_frag; i++) setbit(cg_blksfree(&acg), d + i); } /* XXX cgwrite(&disk, 0)??? */ wtfs(fsbtodb(&sblock, cgtod(&sblock, 0)), sblock.fs_cgsize, (char *)&acg); return ((ufs2_daddr_t)d); }
std::pair< std::string, std::string > iAIDA::AIDA_HBookStore::HBook::getCWNtupleVariableDescription( const int& id, const int& iVar ) { int tupleId = id; int var = iVar; char block[10] = {'\0'}; char chtag[1000] = {'\0'}; int itype = 0; hntvdef_( &tupleId, &var, chtag, block, &itype, 1000, 10 ); std::istringstream ischtag( chtag ); std::string schtag; ischtag >> schtag; std::istringstream isblock( block ); std::string sblock; isblock >> sblock; return std::make_pair( sblock, schtag ); }
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); }