void PROGRAM() { GETTOKEN(); BLOCK(0); if(TOKEN != periodsym) { ERROR("Error number 9, period expected."); } //the halt at the end of the program printToFile(9, 0, 2); }
/* * Import a character to the movie * Imports characters from an other movie. filename (URL) points to a SWF * file with exported characters. * * returns a SWFCharacter object */ SWFCharacter SWFMovie_importCharacter(SWFMovie movie, const char *filename /* URL to movie */, const char *name /* idetifier of character */) { SWFCharacter res; SWFImportBlock importer; int id; res = (SWFCharacter) malloc(sizeof(struct SWFCharacter_s)); SWFCharacterInit(res); CHARACTERID(res) = id = ++SWF_gNumCharacters; BLOCK(res)->type = SWF_DEFINESPRITE; BLOCK(res)->writeBlock = NULL; BLOCK(res)->complete = completeSWFImportCharacter; BLOCK(res)->dtor = (destroySWFBlockMethod) destroySWFCharacter; importer = SWFMovie_addImport(movie, filename, name, id); SWFCharacter_addDependency(res, (SWFCharacter) importer); return res; }
// Extracts a file (PRG, SEQ) byte-by-byte to stdout. void read_file(char *d, int track, int sector) { char *b = BLOCK(d, track, sector); while (b) { if (b[0]) { write(1, &b[2], 254); } else { write(1, &b[2], (unsigned char)b[1]-1); } b = nextblock(d, b); } }
void bitmap_set(struct bitmap *self, size_t pos) { size_t block = BLOCK(pos); if (block >= self->word_alloc) { self->word_alloc = block * 2; self->words = realloc(self->words, self->word_alloc); } self->words[block] |= MASK(pos); }
/* * init_matrix - Fill in matrix M with random values. */ static void init_matrix(Matrix M, int nb) { int I, J, K, i, j, k; /* Initialize random number generator. */ srand(1); /* For each element of each block, fill in random value. */ for (I = 0; I < nb; I++) for (J = 0; J < nb; J++) for (i = 0; i < BLOCK_SIZE; i++) for (j = 0; j < BLOCK_SIZE; j++) BLOCK(MATRIX(M, I, J), i, j) = ((double)rand()) / (double)RAND_MAX; /* Inflate diagonal entries. */ for (K = 0; K < nb; K++) for (k = 0; k < BLOCK_SIZE; k++) BLOCK(MATRIX(M, K, K), k, k) *= 10.0; }
void SWFShape_addStyleHeader(SWFShape shape) { SWFOutput out = newSWFOutput(); SWFOutput_writeUInt16(out, CHARACTERID(shape)); SWFOutput_writeRect(out, SWFCharacter_getBounds(CHARACTER(shape))); if (shape->isUsingNewStyles) { shape->nFills2 = 0; shape->nLines2 = 0; } SWFOutput_writeFillStyles(out, shape->fills2, shape->nFills2, BLOCK(shape)->type); SWFOutput_writeLineStyles(out, shape->lines2, shape->nLines2, BLOCK(shape)->type); /* prepend shape->out w/ shape header */ SWFOutput_setNext(out, shape->out); shape->out = out; }
void SWFShape_addStyleHeader(SWFShape shape) { SWFOutput out = newSWFOutput(); SWFOutput_writeUInt16(out, CHARACTERID(shape)); SWFOutput_writeRect(out, SWFCharacter_getBounds(CHARACTER(shape))); if(shape->useVersion == SWF_SHAPE4) { SWFOutput_writeRect(out, shape->edgeBounds); SWFOutput_writeUInt8(out, shape->flags); } SWFOutput_writeFillStyles(out, shape->fills, shape->nFills, BLOCK(shape)->type, shape->edgeBounds); SWFOutput_writeLineStyles(out, shape->lines, shape->nLines, BLOCK(shape)->type); /* prepend shape->out w/ shape header */ SWFOutput_setNext(out, shape->out); shape->out = out; }
/* font machinery: if a regular font (outlines in fdb) is used, it is added to the textfield as type Font and later converted to a FontChar while a Font, characters can be added (embedded) an Imported font stays as is, so does a BrowserFont */ void SWFTextField_setFont(SWFTextField field, SWFBlock font) { if(font == NULL) return; if ( BLOCK(font)->type == SWF_BROWSERFONT ) { field->fonttype = BrowserFont; field->font.browserFont = (SWFBrowserFont)font; SWFCharacter_addDependency((SWFCharacter)field, (SWFCharacter)font); field->flags |= SWFTEXTFIELD_HASFONT; } else if ( BLOCK(font)->type == SWF_DEFINEFONT || BLOCK(font)->type == SWF_DEFINEFONT2) { SWFFontCharacter fc = (SWFFontCharacter)font; if(checkSWFFontCharacter(fc)) { SWF_warn("font is empty or has no layout information\n"); return; } field->fonttype = Imported; field->font.fontchar = fc; SWFCharacter_addDependency( (SWFCharacter)field, (SWFCharacter)font); field->flags |= SWFTEXTFIELD_HASFONT | SWFTEXTFIELD_USEFONT; } else if (BLOCK(font)->type == SWF_MINGFONT) { if(!(SWFFont_getFlags((SWFFont)font) & SWF_FONT_HASLAYOUT)) { SWF_warn("font is empty or has no layout information\n"); return; } field->fonttype = Font; field->font.font = (SWFFont)font; field->flags |= SWFTEXTFIELD_HASFONT | SWFTEXTFIELD_USEFONT; } else SWF_warn("SWFTextField_setFont: not a valid font object\n"); }
/* only dif is type 2 allows transparency.. */ SWFText newSWFText2() { SWFText text = newSWFText(); /* If malloc failed, return NULL to signify this */ if (NULL == text) return NULL; BLOCK(text)->type = SWF_DEFINETEXT2; return text; }
// Parte da esquerda void block::FIRELEFT() { e[0] = e[7] = true; BLOCK(NR, 12, 0); DOT(NR, 0, 0, 11, 31); DOT(DR, 12, 0, 12); DOT(UR, 12, 14, 14, 15); DOT(NR, 14, 0, 23, 24); DOT(NR, 15, 0, 25); DOT(UR, 12, 0, 32); DOT(DR, 12, 14, 34, 35); }
// Parte da direita void block::FIRERIGHT() { e[0] = e[7] = true; BLOCK(NR, 12, 0); DOT(UR, 12, 14, 11, 12); DOT(DR, 12, 0, 14); DOT(NR, 0, 0, 15, 35); DOT(NR, 15, 0, 21); DOT(NR, 14, 0, 22, 23); DOT(DR, 12, 14, 31, 32); DOT(UR, 12, 0, 34); }
// Bomb punch item void block::PUNCHIT() { e[0] = e[3] = true; item = 'p'; BLOCK(NR, 14, 0); VLINE(NR, 13, 0, 3); VLINE(B2, 12, 14, 5); DOT(DR, 13, 14, 14); DOT(NR, 15, 0, 21, 22); DOT(NR, 13, 0, 24); DOT(UR, 13, 14, 34); }
/* Get neatly aligned memory, initializing or growing the heap info table as necessary. */ static __ptr_t morecore (__malloc_size_t size) { __ptr_t result; malloc_info *newinfo, *oldinfo; __malloc_size_t newsize; result = align (size); if (result == NULL) return NULL; /* Check if we need to grow the info table. */ if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize) { newsize = heapsize; while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize) newsize *= 2; newinfo = (malloc_info *) align (newsize * sizeof (malloc_info)); if (newinfo == NULL) { (*__morecore) (-size); return NULL; } MEMCPY (newinfo, _heapinfo, heapsize * sizeof (malloc_info)); MEMSET (&newinfo[heapsize], 0, (newsize - heapsize) * sizeof (malloc_info)); oldinfo = _heapinfo; newinfo[BLOCK (oldinfo)].busy.type = 0; newinfo[BLOCK (oldinfo)].busy.info.size = BLOCKIFY (heapsize * sizeof (malloc_info)); _heapinfo = newinfo; /* Account for the _heapinfo block itself in the statistics. */ _bytes_used += newsize * sizeof (malloc_info); ++_chunks_used; _free_internal (oldinfo); heapsize = newsize; } _heaplimit = BLOCK ((char *) result + size); return result; }
/* Allocate memory from the heap. */ void * _fusion_shmalloc( shmalloc_heap *heap, size_t size ) { void *result; size_t block, blocks, lastblocks, start; register size_t i; struct list *next; D_DEBUG_AT( Fusion_SHMHeap, "%s( %p, %zu )\n", __FUNCTION__, heap, size ); D_MAGIC_ASSERT( heap, shmalloc_heap ); /* Some programs will call shmalloc (0). We let them pass. */ if (size == 0) return NULL; if (size < sizeof (struct list)) size = sizeof (struct list); /* Determine the allocation policy based on the request size. */ if (size <= BLOCKSIZE / 2) { /* Small allocation to receive a fragment of a block. Determine the logarithm to base two of the fragment size. */ register size_t log = 1; --size; while ((size /= 2) != 0) ++log; /* Look in the fragment lists for a free fragment of the desired size. */ next = heap->fraghead[log].next; if (next != NULL) { /* There are free fragments of this size. Pop a fragment out of the fragment list and return it. Update the block's nfree and first counters. */ result = (void *) next; next->prev->next = next->next; if (next->next != NULL) next->next->prev = next->prev; block = BLOCK (result); if (--(heap->heapinfo[block].busy.info.frag.nfree) != 0) heap->heapinfo[block].busy.info.frag.first = (unsigned long int) ((unsigned long int) ((char *) next->next - (char *) NULL) % BLOCKSIZE) >> log; /* Update the statistics. */ heap->chunks_used++; heap->bytes_used += 1 << log; heap->chunks_free--; heap->bytes_free -= 1 << log; } else {
/* * print_matrix - Print matrix M. */ static void print_matrix(Matrix M, int nb) { int i, j; /* Print out matrix. */ for (i = 0; i < nb * BLOCK_SIZE; i++) { for (j = 0; j < nb * BLOCK_SIZE; j++) printf(" %6.4f", BLOCK(MATRIX(M, i / BLOCK_SIZE, j / BLOCK_SIZE), i % BLOCK_SIZE, j % BLOCK_SIZE)); printf("\n"); } }
/* block_graph: * Add induced edges. */ static void block_graph(Agraph_t * g, block_t * sn) { Agnode_t *n; Agedge_t *e; Agraph_t *subg = sn->sub_graph; for (n = agfstnode(subg); n; n = agnxtnode(subg, n)) { for (e = agfstout(g, n); e; e = agnxtout(g, e)) { if (BLOCK(e->head) == sn) aginsert(subg, e); } } }
// Calculate exact file size by reading entire file. // Fast since its all in ram. int file_size(char *d, int track, int sector) { int size = 0; char *b = BLOCK(d, track, sector); while (b) { if (b[0]) { size += 254; } else { size += (unsigned char)b[1]-1; } b = nextblock(d, b); } return size; }
// Fire up item void block::FIREIT() { e[0] = e[3] = true; item = 'f'; BLOCK(NR, 12, 0); DOT(NR, 10, 0, 11, 15); DOT(DR, 12, 10, 12, 14); DOT(UR, 12, 14, 22, 24); DOT(UR, 14, 15, 23); DOT(UR, 12, 10, 31, 35); DOT(DR, 12, 14, 32, 33, 34); }
/* growMap: based on hash.c:hsplit() from Larry Wall's Perl. growMap doubles the size of the hash table. It is called when FILL_PERCENT of the buckets in the hash table contain values. This routine is efficient since the entries in the table don't need to be rehashed (even though the entries are redistributed across the both halves of the hash table). */ INLINE unsigned long sval_hash(svalue_t x) { switch(x.type) { case T_STRING: return HASH(BLOCK(x.u.string)); case T_NUMBER: return (unsigned long)x.u.number; case T_OBJECT: //return HASH(BLOCK(x.u.ob->obname)); default: return (unsigned long)(((POINTER_INT)((x).u.number)) >> 5); } }
void block::MONSTER4() { ZERO(); e[0] = e[5] = true; monster = '4'; BLOCK(NR, 12, 0); DOT(NR, 0, 0, 11, 15); DOT(DR, 12, 0, 12, 14, 21, 25); DOT(E2, 0, 12, 22); DOT(E3, 0, 12, 24); DOT(UT, 0, 12, 32, 34); DOT(SQ, 0, 12, 33); }
SWFSceneData newSWFSceneData() { SWFSceneData sdata= (SWFSceneData)malloc(sizeof(struct SWFSceneData_s)); SWFCharacterInit((SWFCharacter)sdata); BLOCK(sdata)->type = SWF_DEFINESCENEANDFRAMEDATA; BLOCK(sdata)->writeBlock = writeSWFSceneDataToMethod; BLOCK(sdata)->complete = completeSWFSceneData; BLOCK(sdata)->dtor = (destroySWFBlockMethod) destroySWFSceneData; sdata->sceneCount = 0; sdata->sceneOffset = NULL; sdata->sceneName = NULL; sdata->frameLabelCount = 0; sdata->frameNumber = NULL; sdata->frameLabel = NULL; sdata->out = NULL; return sdata; }
/* * test_result - Check that matrix LU contains LU decomposition of M. */ static int test_result(Matrix LU, Matrix M, int nb) { int I, J, K, i, j, k; double diff, max_diff; double v; /* Initialize test. */ max_diff = 0.0; /* Find maximum difference between any element of LU and M. */ for (i = 0; i < nb * BLOCK_SIZE; i++) for (j = 0; j < nb * BLOCK_SIZE; j++) { I = i / BLOCK_SIZE; J = j / BLOCK_SIZE; v = 0.0; for (k = 0; k < i && k <= j; k++) { K = k / BLOCK_SIZE; v += BLOCK(MATRIX(LU, I, K), i % BLOCK_SIZE, k % BLOCK_SIZE) * BLOCK(MATRIX(LU, K, J), k % BLOCK_SIZE, j % BLOCK_SIZE); } if (k == i && k <= j) { K = k / BLOCK_SIZE; v += BLOCK(MATRIX(LU, K, J), k % BLOCK_SIZE, j % BLOCK_SIZE); } diff = fabs(BLOCK(MATRIX(M, I, J), i % BLOCK_SIZE, j % BLOCK_SIZE) - v); if (diff > max_diff) max_diff = diff; } /* Check maximum difference against threshold. */ if (max_diff > 0.00001) return 0; else return 1; }
block block_bind_referenced(block binder, block body, int bindflags) { assert(block_has_only_binders(binder, bindflags)); bindflags |= OP_HAS_BINDING; block refd = gen_noop(); for (inst* curr; (curr = block_take(&binder));) { block b = inst_block(curr); if (block_bind_subblock(b, body, bindflags)) { refd = BLOCK(refd, b); } else { block_free(b); } } return block_join(refd, body); }
void LinnCreate::insertEntry(le32 dirInode, le32 entryInode, char *name, FileType type) { LinnGroup *group; LinnInode *inode; LinnDirectoryEntry *entry; le32 entryNum, blockNum; /* Point to the correct group. */ group = BLOCKPTR(LinnGroup, super->groupsTable); if (dirInode != ZERO) { group += (dirInode / super->inodesPerGroup); } /* Fetch inode. */ inode = BLOCKPTR(LinnInode, group->inodeTable) + (dirInode % super->inodesPerGroup); /* Calculate entry and block number. */ entryNum = inode->size / sizeof(LinnDirectoryEntry); blockNum = (entryNum * sizeof(LinnDirectoryEntry)) / super->blockSize; /* Direct block. */ if (blockNum < LINN_INODE_DIR_BLOCKS) { /* Allocate a new block, if needed. */ if (!inode->block[blockNum]) { inode->block[blockNum] = BLOCK(super); } /* Point to the fresh entry. */ entry = BLOCKPTR(LinnDirectoryEntry, inode->block[blockNum]) + (entryNum % super->blockSize); /* Fill it. */ entry->inode = entryInode; entry->type = type; strncpy(entry->name, name, LINN_DIRENT_NAME_LEN); entry->name[LINN_DIRENT_NAME_LEN - 1] = ZERO; } /* Indirect block. */ else { printf("%s: indirect blocks not (yet) supported for directories\n", prog); exit(EXIT_FAILURE); } /* Increment directory size. */ inode->size += sizeof(LinnDirectoryEntry); }
void SWFShape_end(SWFShape shape) { int i; byte* buffer; if ( shape->isEnded ) return; shape->isEnded = TRUE; buffer = SWFOutput_getBuffer(shape->out); if (shape->isUsingNewStyles == FALSE) { buffer[0] = (SWFOutput_numBits(shape->nFills2) << 4) + SWFOutput_numBits(shape->nLines2); } for ( i=0; i<shape->nRecords; ++i ) { if ( i < shape->nRecords-1 || shape->records[i].type != SHAPERECORD_STATECHANGE ) { SWFShape_writeShapeRecord(shape, shape->records[i]); } free(shape->records[i].record.stateChange); /* all in union are pointers */ } SWFOutput_writeBits(shape->out, 0, 6); /* end tag */ SWFOutput_byteAlign(shape->out); /* addStyleHeader creates a new output and adds the existing one after itself- so even though it's called afterwards it's written before, as it should be */ if ( BLOCK(shape)->type > 0 ) /* i.e., shape with style */ SWFShape_addStyleHeader(shape); free(shape->records); shape->records = NULL; shape->nRecords = 0; shape->lines = &shape->lines2; shape->fills = &shape->fills2; shape->nLines = &shape->nLines2; shape->nFills = &shape->nFills2; }
/* Worker: mask elements outside block */ static void exmask( int mask, int block, int el, int (*idx_fn)( int, int ) ) { int i, idx; rb->yield(); for( i = 0 ; i < 9 ; ++i ) { idx = (*idx_fn)( el, i ); if( block != BLOCK( idx ) && IS_EMPTY( idx ) ) board[ idx ] |= mask; } }
int main(int argc, char* argv[]) { if (argc < 2) { fprintf(stdout, "Usage: %s <disk.d64> [track] [sector]\n", argv[0]); return 1; } char *d = load_disk(argv[1]); if (argc == 4) { read_file(d, atoi(argv[2]), atoi(argv[3])); return 0; } char label[19]; // Includes null & quotes // Read Disk header char *b = BLOCK(d, DIR_TRACK, 0); // Volume label #ifdef D1581 trim(&label[1], &b[4], sizeof(label)-2); label[0] = '"'; strcat(label, "\""); printf("0 %s %c %c\n", label, b[0x19], b[0x1a]); #else trim(&label[1], &b[0x90], sizeof(label)-2); label[0] = '"'; strcat(label, "\""); printf("0 %s %2.2s %2.2s\n", label, &b[0xa2], &b[0xa5]); #endif assert(b[0] == DIR_TRACK); #ifdef D1581 assert(b[1] == 3); assert(b[2] == 'D'); #else assert(b[1] == 1); assert(b[2] == 'A'); #endif //hexdump(b); //write(1, &b[0x90], 16); lsdir(d, nextblock(d, b)); printf("%d BLOCKS FREE.\n", compute_blocks_free(&b[0])); }
const char * ref_string (const char * str) { block_t *b; b = BLOCK(str); #ifdef DEBUG if (b != findblock(str)) { fatal("stralloc.c: called ref_string on non-shared string: %s.\n", str); } #endif /* defined(DEBUG) */ if (REFS(b)) REFS(b)++; NDBG(b); ADD_STRING(SIZE(b)); return str; }
SWFDBLBitmapData newSWFDBLBitmapData_fromData(dblData data) { SWFDBLBitmapData dbl; dbl = (SWFDBLBitmapData)malloc(sizeof(struct SWFDBLBitmapData_s)); /* If malloc failed, return NULL to signify this */ if (NULL == dbl) return NULL; SWFCharacterInit((SWFCharacter)dbl); CHARACTERID(dbl) = ++SWF_gNumCharacters; BLOCK(dbl)->writeBlock = writeSWFDBLBitmapDataToMethod; BLOCK(dbl)->complete = completeSWFDBLBitmap; BLOCK(dbl)->dtor = (destroySWFBlockMethod) destroySWFDBLBitmapData; dbl->width = data->width; dbl->height = data->height; dbl->format = data->format; dbl->format2 = data->format2; dbl->data = data->data; if(data->hasalpha) BLOCK(dbl)->type = SWF_DEFINELOSSLESS2; else BLOCK(dbl)->type = SWF_DEFINELOSSLESS; BLOCK(dbl)->length = data->length; BLOCK(dbl)->length += 7; /* character id, format, width, height */ if(dbl->format == 3) BLOCK(dbl)->length++; CHARACTER(dbl)->bounds = newSWFRect(0, dbl->width, 0, dbl->height); #if TRACK_ALLOCS dbl->gcnode = ming_gc_add_node(dbl, (dtorfunctype)destroySWFDBLBitmapData); #endif return dbl; }
void AquireSemaphore(Semaphore* sem) { if(NumThreads <= 1) { return; } assert(sem); // check if we have zero shits left to give if(__sync_fetch_and_sub(&sem->value, 1) < 0) { // we do // queue up for the toilet. // add ourselves to the waiting list sem->contestants.push_back(GetCurrentThread()); } while(sem->value <= 0) BLOCK(); }