예제 #1
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_read_double(dbf_handle_t dbf, int col_id, double* value) {
	EW(dbf_check_col(dbf, col_id));
	column_t* col = &dbf->cols[col_id];
	EW(dbf_check_col_type(dbf, col, FIELD_DOUBLE));

	*value = *(double*)(dbf->row + col->offset);
	return 8;
}
예제 #2
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_read_int(dbf_handle_t dbf, int col_id, int* value) {
	EW(dbf_check_col(dbf, col_id));
	column_t* col = &dbf->cols[col_id];
	EW(dbf_check_col_type(dbf, col, FIELD_INTEGER));

	*value = *(uint32_t*)(dbf->row + col->offset);
	return 4;
}
예제 #3
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_read_bool(dbf_handle_t dbf, int col_id, bool* value) {
	EW(dbf_check_col(dbf, col_id));
	column_t* col = &dbf->cols[col_id];
	EW(dbf_check_col_type(dbf, col, FIELD_BOOLEAN));

	char c = *(dbf->row + col->offset);
	*value = (c == 'T' || c == 't' || c == 'Y' || c == 'y');
	return 1;
}
예제 #4
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_full_table_scan(dbf_handle_t dbf, int col_id, const void* value) {
	char buf[BUFSIZE];

	for (int i = dbf->pos + 1; i < dbf->row_count; i++) {
		EW(dbf_seek(dbf, i));
		if (!dbf_is_deleted(dbf)) {
			EW(dbf_read(dbf, col_id, buf, BUFSIZE));
			if (strcmp(buf, value) == 0) {
				return TRUE;
			}
		}
	}
	dbf->pos = -1;
	return FALSE;
}
예제 #5
0
double Decoder::decodeLat ( string data )
{
	//selects the part of the string to be decoded for latitude
	string latstr = data.substr( 7, 6 );
	double lat, latMin, latTenMin;

	//decode the first character, then mult by LATMULT
	lat = LATMULT * latDecode( latstr[0] );
	//add the decoded second char to lat
	lat +=  latDecode( latstr[1] );

	//decode the third char, then mult by LATMULT
	latMin = LATMULT * latDecode( latstr[2] );
	//add the decoded fourth char to latMin
	latMin += latDecode( latstr[3] );
	//decode the fourth char to see if it is in the north or south hemisphere
	_n_s = NS ( latstr[3] );

	//decode the fifth char, then mult by LATMULT
	latTenMin = LATMULT * latDecode( latstr[4] );
	//send the fifth char to find the offset
	_offset = offset( latstr[4] );
	//decode the sixth char and add to latTenMin
	latTenMin += latDecode( latstr[5] );
	//decode the sixth char to see if it is in the east or west hemisphere
	_e_w = EW ( latstr[5] );


	return convertLat( lat, latMin, latTenMin );
}
예제 #6
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_find_next(dbf_handle_t dbf) {
	if (dbf->last_find_use_index) {
		if (!dbf->index) {
			set_error(ERR_DBF_NO_INDEX, dbf, NULL);
			return ERROR;
		}
		if (!dbf->index->last_search) {
			set_error(ERR_DBF_FIND_NEXT, dbf, NULL);
			return ERROR;
		}
		int pos;
		do {
			EW(pos = dbf_idx_next(dbf->index));
			if (pos == NOT_FOUND) {
				dbf->pos = -1;
				return FALSE;
			}
			dbf_seek(dbf, pos - 1);
		} while (dbf_is_deleted(dbf));
		return TRUE;
	} else {
		if (dbf->last_find_col_id == -1) {
			set_error(ERR_DBF_FIND_NEXT, dbf, NULL);
			return ERROR;
		} else {
			return dbf_full_table_scan(dbf, dbf->last_find_col_id, dbf->last_find_value);
		}
	}
}
예제 #7
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_find(dbf_handle_t dbf, int id, bool use_index, const void* value) {
	if (use_index) {
		if (!dbf->index) {
			set_error(ERR_DBF_NO_INDEX, dbf, NULL);
			return ERROR;
		}
		if (id < 0 || id > dbf->index->index_count) {
			set_error(ERR_DBF_INVALID_INDEX_ID, dbf, "index=%i", id);
			return ERROR;
		}
		int pos;
		dbf->last_find_use_index = true;
		EW(pos = dbf_idx_find(dbf->index, id, value));
		if (pos == NOT_FOUND) {
			dbf->pos = -1;
			return FALSE;
		}
		dbf_seek(dbf, pos - 1);
		if (dbf_is_deleted(dbf)) {
			return dbf_find_next(dbf);
		} else return TRUE;
	} else {
		dbf->last_find_col_id = id;
		if (dbf->last_find_value) free(dbf->last_find_value);
		dbf->last_find_value = strdup(value);
		dbf->last_find_use_index = false;
		dbf->pos = -1;
		return dbf_full_table_scan(dbf, id, value);
	}
}
예제 #8
0
파일: index.c 프로젝트: rkaldy/libfoxpro
bool dbf_uncompress_init(search_context_t* sc, FILE* f) {
	compressed_node_t header;

	EW(sfread(&header, sizeof(compressed_node_t), f));
	EW(sfread(sc->buf, SC_BUF_SIZE, f));
	sc->bytes_total        = header.bytes_total;
	if (header.bytes_total <= 4) {
		sc->mask.s.record_number = header.record_number_mask;
		sc->mask.s.dup_count     = header.dup_count_mask << header.record_number_bits;
		sc->mask.s.trail_count   = header.trail_count_mask << (header.record_number_bits + header.dup_count_bits);
	} else {
		sc->mask.l.record_number = (uint64_t)header.record_number_mask;
		sc->mask.l.dup_count     = (uint64_t)header.dup_count_mask << header.record_number_bits;
		sc->mask.l.trail_count   = (uint64_t)header.trail_count_mask << (header.record_number_bits + header.dup_count_bits);
	}
	sc->dup_count_shr      = header.record_number_bits;
	sc->trail_count_shr	   = header.record_number_bits + header.dup_count_bits;
	sc->key_pos            = SC_BUF_SIZE;
	sc->idx_pos            = 0;
	return TRUE;
}
예제 #9
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_seek(dbf_handle_t dbf, int pos) {
	if (pos < 0 || pos >= dbf->row_count) {
		set_error(ERR_DBF_INVALID_RECORD_ID, dbf, "row=%i", pos);
		return ERROR;
	}
	fseek(dbf->file, dbf->first_row + pos * dbf->row_size, SEEK_SET);
	EW(sfread(dbf->row, dbf->row_size, dbf->file));
	if (dbf->row[0] != FLAG_RECORD_OK && dbf->row[0] != FLAG_RECORD_DELETED) {
		set_error(ERR_DBF_BAD_FORMAT, dbf, "row=%i", pos);
		return ERROR;
	}
	dbf->pos = pos;
	return OK;
}
예제 #10
0
파일: foxpro.c 프로젝트: rkaldy/libfoxpro
int dbf_read(dbf_handle_t dbf, int col_id, char* buf, size_t buf_len) {
	EW(dbf_check_col(dbf, col_id));
	column_t* col = &dbf->cols[col_id];

	if (col->type == FIELD_TYPE[FIELD_MEMO] || col->type == FIELD_TYPE[FIELD_PICTURE]) {
		int pos = *(uint32_t*)(dbf->row + col->offset);
		return dbf_get_memo_field(dbf->memo, pos, col->binary, buf, buf_len);
	}
	else if (col->binary) {
		int len = MIN(col->size, buf_len);
		memcpy(buf, dbf->row + col->offset, len);
		return len;
	}
	else {
		int len = MIN(col->size, buf_len - 1);
		memcpy(buf, dbf->row + col->offset, len);
		len = trim(buf, len);
		return len;
	}
}
예제 #11
0
std::string JITDebugRegisterer::MakeELF(const Function *F, DebugInfo &I) {
    // Stack allocate an empty module with an empty LLVMContext for the ELFWriter
    // API.  We don't use the real module because then the ELFWriter would write
    // out unnecessary GlobalValues during finalization.
    LLVMContext Context;
    Module M("", Context);

    // Make a buffer for the ELF in memory.
    std::string Buffer;
    raw_string_ostream O(Buffer);
    ELFWriter EW(O, TM);
    EW.doInitialization(M);

    // Copy the binary into the .text section.  This isn't necessary, but it's
    // useful to be able to disassemble the ELF by hand.
    ELFSection &Text = EW.getTextSection(const_cast<Function *>(F));
    Text.Addr = (uint64_t)I.FnStart;
    // TODO: We could eliminate this copy if we somehow used a pointer/size pair
    // instead of a vector.
    Text.getData().assign(I.FnStart, I.FnEnd);

    // Copy the exception handling call frame information into the .eh_frame
    // section.  This allows GDB to get a good stack trace, particularly on
    // linux x86_64.  Mark this as a PROGBITS section that needs to be loaded
    // into memory at runtime.
    ELFSection &EH = EW.getSection(".eh_frame", ELF::SHT_PROGBITS,
                                   ELF::SHF_ALLOC);
    // Pointers in the DWARF EH info are all relative to the EH frame start,
    // which is stored here.
    EH.Addr = (uint64_t)I.EhStart;
    // TODO: We could eliminate this copy if we somehow used a pointer/size pair
    // instead of a vector.
    EH.getData().assign(I.EhStart, I.EhEnd);

    // Add this single function to the symbol table, so the debugger prints the
    // name instead of '???'.  We give the symbol default global visibility.
    ELFSym *FnSym = ELFSym::getGV(F,
                                  ELF::STB_GLOBAL,
                                  ELF::STT_FUNC,
                                  ELF::STV_DEFAULT);
    FnSym->SectionIdx = Text.SectionIdx;
    FnSym->Size = I.FnEnd - I.FnStart;
    FnSym->Value = 0;  // Offset from start of section.
    EW.SymbolList.push_back(FnSym);

    EW.doFinalization(M);
    O.flush();

    // When trying to debug why GDB isn't getting the debug info right, it's
    // awfully helpful to write the object file to disk so that it can be
    // inspected with readelf and objdump.
    if (JITEmitDebugInfoToDisk) {
        std::string Filename;
        raw_string_ostream O2(Filename);
        O2 << "/tmp/llvm_function_" << I.FnStart << "_" << F->getNameStr() << ".o";
        O2.flush();
        std::string Errors;
        raw_fd_ostream O3(Filename.c_str(), Errors);
        O3 << Buffer;
        O3.close();
    }

    return Buffer;
}