Exemplo n.º 1
0
int main6(int argc, char *argv[]) {  
  Intstack cell, co;
  int rank, upb, nr = 0;
  assert(argc > 1);
  rank = atoi(argv[1]);
  upb = 1 << rank;
  co = newIntstack(upb, NULL);
  cell = readCell();
  while (cell) {
    nr = getCnr();
    printCell(nr, cell);
    complement(upb, cell, co);
    printf("COM ");
    printCell(0, co);
    freestack(cell);
    printf("\n");
    cell = readCell();
  }
  freestack(cell);
  freestack(co);
#if 0
  reportTime();
  reportCnt();
#endif
  finalizeScanner();
  return 0;
}
Exemplo n.º 2
0
void GLECSVData::parseBlock() {
	m_pos = 0;
	m_size = m_buffer.size();
	m_data = &m_buffer[0];
	GLECSVDataStatus status = ignoreHeader();
	while (status != GLECSVDataStatusEOF) {
		status = readCell();
	}
}
Exemplo n.º 3
0
unsigned char countBombs(int row, int col, Board* board){
    unsigned char retval = 0;
    retval += (readCell(row-1, col-1, board) & SPACE_MINE) ? 1 : 0;
    retval += (readCell(row-1, col, board) & SPACE_MINE) ? 1 : 0;
    retval += (readCell(row-1, col+1, board) & SPACE_MINE) ? 1 : 0;
    retval += (readCell(row, col+1, board) & SPACE_MINE) ? 1 : 0;
    retval += (readCell(row+1, col+1, board) & SPACE_MINE) ? 1 : 0;
    retval += (readCell(row+1, col, board) & SPACE_MINE) ? 1 : 0;
    retval += (readCell(row+1, col-1, board) & SPACE_MINE) ? 1 : 0;
    retval += (readCell(row, col-1, board) & SPACE_MINE) ? 1 : 0;
    return retval;
}
Exemplo n.º 4
0
void readCells(FILE *in, FILE *out)
{
    uint32_t *cellOffsets = calloc( Hdr.cellCount, sizeof( uint32_t ) );
    if( cellOffsets != NULL ) {
        unsigned int count;
        fseek( in, Hdr.cellOffsetOffset, SEEK_SET );
        fread( cellOffsets, sizeof( uint32_t ), Hdr.cellCount, in );
        fputs( "\nCells\n", out );
        for( count = 0; count < Hdr.cellCount; count++ ) {
            fseek( in, cellOffsets[ count ], SEEK_SET );
            fprintf( out, "  Cell #%u at offset %8.8x\n", count, cellOffsets[ count ] );
            readCell( in, out );
            }
        }
    free( cellOffsets );
    }
Exemplo n.º 5
0
unsigned char probe(int row, int col, Board* board){
    unsigned char cellVal = readCell(row, col, board);
    if(cellVal & SPACE_HIDDEN){
        cellVal = cellVal & (~(SPACE_HIDDEN|SPACE_FLAG));
        board->content[(row*board->columns)+col] = cellVal;
        if(cellVal == 0){
            probe(row-1, col-1, board);
            probe(row-1, col, board);
            probe(row-1, col+1, board);
            probe(row, col+1, board);
            probe(row+1, col+1, board);
            probe(row+1, col, board);
            probe(row+1, col-1, board);
            probe(row, col-1, board);
        }
    }
    return cellVal;
}
Exemplo n.º 6
0
    void preload(const utymap::BoundingBox& bbox)
    {
        int minLat = (int)bbox.minPoint.latitude;
        int minLon = (int)bbox.minPoint.longitude;

        int maxLat = (int)bbox.maxPoint.latitude;
        int maxLon = (int)bbox.maxPoint.longitude;

        int latDiff = maxLat - minLat;
        int lonDiff = maxLon - minLon;

        for (int j = 0; j <= latDiff; j++)
            for (int i = 0; i <= lonDiff; i++) {
                HgtCellKey cellKey(minLat + j, minLon + i);

                if (cells_.find(cellKey) != cells_.end()) 
                    continue;

                std::string path = getFilePath(cellKey);
                CellPtr cell = readCell(path);
                // TODO limit loaded cells.
                cells_[cellKey] = cell;
            }
    }
Exemplo n.º 7
0
int loadRgbImage(const char* fileName, RgbImage* image, float scale) {
	int c;
	int i;
	int j;
	char w[256];
	RgbPixel** pixels;
	FILE *fp;

	printf("Loading %s ...\n", fileName);

	fp = fopen(fileName, "r");
	if (!fp) {
		printf("Warning: Oops! Cannot open %s!\n", fileName);
		return 0;
	}

	c = readCell(fp, w);
	image->w = atoi(w);
	c = readCell(fp, w);
	image->h = atoi(w);

	printf("%d x %d\n", image->w, image->h);

	pixels = (RgbPixel**)malloc(image->h * sizeof(RgbPixel*));

	if (pixels == NULL) {
		printf("Warning: Oops! Cannot allocate memory for the pixels!\n");

		fclose(fp);

		return 0;
	}

	c = 0;
	for(i = 0; i < image->h; i++) {
		pixels[i] = (RgbPixel*)malloc(image->w * sizeof(RgbPixel));
		if (pixels[i] == NULL) {
			c = 1;
			break;
		}
	}

	if (c == 1) {
		printf("Warning: Oops! Cannot allocate memory for the pixels!\n");

		for (i--; i >= 0; i--)
			free(pixels[i]);
		free(pixels);

		fclose(fp);

		return 0;
	}

	for(i = 0; i < image->h; i++) {
		for(j = 0; j < image->w; j++) {
			c = readCell(fp, w);
			pixels[i][j].r = atoi(w) / scale;

			c = readCell(fp, w);
			pixels[i][j].g = atoi(w) / scale;

			c = readCell(fp, w);
			pixels[i][j].b = atoi(w) / scale;

			pixels[i][j].cluster = 0;
			pixels[i][j].distance = 0.;
		}
	}
	image->pixels = pixels;

	c = readCell(fp, w);
	image->meta = (char*)malloc(strlen(w) * sizeof(char));
	if(image->meta == NULL) {
		printf("Warning: Oops! Cannot allocate memory for the pixels!\n");

		for (i = 0; i < image->h; i++)
			free(pixels[i]);
		free(pixels);

		fclose(fp);

		return 0;

	}
	strcpy(image->meta, w);

	printf("%s\n", image->meta);

	printf("w=%d x h=%d\n", image->w, image->h);

	return 1;
}