static void grn_ctx_ql_init(grn_ctx *ctx, int flags) { if (!ctx->impl) { grn_ctx_impl_init(ctx); if (ERRP(ctx, GRN_ERROR)) { return; } } if (flags & GRN_CTX_BATCH_MODE) { ctx->impl->batchmode = 1; } if ((ctx->impl->objects = grn_array_create(ctx, NULL, sizeof(grn_cell), GRN_ARRAY_TINY))) { if ((ctx->impl->symbols = grn_hash_create(ctx, NULL, GRN_TABLE_MAX_KEY_SIZE, sizeof(grn_cell), GRN_OBJ_KEY_VAR_SIZE|GRN_HASH_TINY))) { if (!ERRP(ctx, GRN_ERROR)) { grn_ql_init_globals(ctx); if (!ERRP(ctx, GRN_ERROR)) { return; } } grn_hash_close(ctx, ctx->impl->symbols); ctx->impl->symbols = NULL; } else { MERR("ctx->impl->symbols init failed"); } grn_array_close(ctx, ctx->impl->objects); ctx->impl->objects = NULL; } else { MERR("ctx->impl->objects init failed"); } }
grn_rc grn_ctx_init(grn_ctx *ctx, int flags) { if (!ctx) { return GRN_INVALID_ARGUMENT; } // if (ctx->stat != GRN_QL_FIN) { return GRN_INVALID_ARGUMENT; } ERRCLR(ctx); ctx->flags = flags; ctx->stat = GRN_QL_WAIT_EXPR; ctx->encoding = grn_gctx.encoding; ctx->seqno = 0; ctx->seqno2 = 0; ctx->subno = 0; ctx->impl = NULL; if (flags & GRN_CTX_USE_QL) { grn_ctx_ql_init(ctx, flags); if (ERRP(ctx, GRN_ERROR)) { return ctx->rc; } } MUTEX_LOCK(grn_glock); ctx->next = grn_gctx.next; ctx->prev = &grn_gctx; grn_gctx.next->prev = ctx; grn_gctx.next = ctx; MUTEX_UNLOCK(grn_glock); return ctx->rc; }
/* read/write multiple wishbone registers */ void wou_cmd (wou_param_t *w_param, const uint8_t func, const uint16_t wb_addr, const uint16_t dsize, const uint8_t *data) { if (dsize > MAX_DSIZE) { ERRP ("ERROR Trying to write to too many registers (%d > %d)\n", dsize, MAX_DSIZE); return; } wou_append (w_param->board, func, wb_addr, dsize, data); return; }
grn_ctx * grn_ctx_open(int flags) { grn_ctx *ctx = GRN_GMALLOCN(grn_ctx, 1); if (ctx) { grn_ctx_init(ctx, flags|GRN_CTX_ALLOCATED); if (ERRP(ctx, GRN_ERROR)) { GRN_GFREE(ctx); ctx = NULL; } } return ctx; }
int main(int argc, char *argv[]) { FILE *out_fp = NULL; // for the output file FILE *hdr_fp = NULL; // the header input file FILE *fivr_fp = NULL; // the finger image view record files int h_opt, f_opt, o_opt, to_opt, p_opt; struct finger_image_record *fir; struct stat sb; char ch; int ret, exit_code; int out_type; char pm; exit_code = EXIT_SUCCESS; h_opt = f_opt = o_opt = to_opt = p_opt = 0; out_type = FIR_STD_ANSI; while ((ch = getopt(argc, argv, "h:f:o:t:p")) != -1) { switch (ch) { case 'h': if ((hdr_fp = fopen(optarg, "r")) == NULL) OPEN_ERR_EXIT(optarg); h_opt = 1; break; case 'f': if ((fivr_fp = fopen(optarg, "r")) == NULL) OPEN_ERR_EXIT(optarg); f_opt = 1; break; case 't': pm = *(char *)optarg; switch (pm) { case 'o': out_type = fir_stdstr_to_type( argv[optind]); if (out_type < 0) usage(); optind++; to_opt++; break; default: usage(); break; /* not reached */ } break; case 'o': if (stat(optarg, &sb) == 0) ERR_EXIT("File '%s' exists, remove it first.\n", optarg); if ((out_fp = fopen(optarg, "wb")) == NULL) OPEN_ERR_EXIT(optarg); o_opt = 1; break; case 'p': p_opt = 1; break; default: usage(); break; } } if ((h_opt && f_opt && o_opt) == 0) usage(); // Read in the file containing the header information if (new_fir(out_type, &fir) < 0) ALLOC_ERR_EXIT("Finger Image Record (general header)"); if (load_hdr(hdr_fp, fir) != READ_OK) { exit_code = EXIT_FAILURE; ERR_OUT("Could not read header"); } // Read in each Finger Image View Record add to the Finger Image Record do { ret = load_fivr(fivr_fp, fir); if (ret == READ_ERROR) { exit_code = EXIT_FAILURE; ERRP("Reading image view record"); goto err_out; } } while (ret == READ_OK); fir->record_length = total_length; // Validate the Finger Image Record if (validate_fir(fir) != VALIDATE_OK) { fprintf(stdout, "Finger Image Record is invalid.\n"); } else { fprintf(stdout, "Finger Image Record is valid.\n"); } if (p_opt) print_fir(stdout, fir); // Write out the FIR if (write_fir(out_fp, fir) != WRITE_OK) { fprintf(stderr, "Error writing the Finger Image Record\n"); } else { fprintf(stdout, "Finger Image Record written.\n"); } err_out: free_fir(fir); if (o_opt) fclose(out_fp); if (h_opt) fclose(hdr_fp); if (f_opt) fclose(fivr_fp); exit(exit_code); }
int load_fivr(FILE *fp, struct finger_image_record *fir) { struct finger_image_view_record *fivr; int ret; char filename[MAXPATHLEN]; char *buf; struct stat sb; FILE *image_fp; if (new_fivr(&fivr) < 0) ALLOC_ERR_RETURN("Finger Image View Record"); // This scan follows the layout of Table 4 in 381-2004 ret = fscanf(fp, "%u %hhu %hhu %hhu %hhu %hhu %hu %hu %hhu", &fivr->length, &fivr->finger_palm_position, &fivr->count_of_views, &fivr->view_number, &fivr->quality, &fivr->impression_type, &fivr->horizontal_line_length, &fivr->vertical_line_length, &fivr->reserved); if (ret == EOF) return (READ_EOF); else if (ret != 9) return (READ_ERROR); if (fscanf(fp, "%s", filename) != 1) return (READ_ERROR); // Even though we read the length from the header, we set it to // the correct size here. fivr->length = FIVR_HEADER_LENGTH; if (stat(filename, &sb) == 0) { if ((image_fp = fopen(filename, "rb")) == NULL) { ERRP ("Could not read image file %s", filename); } else { buf = (char *)malloc(sb.st_size); if (buf == NULL) { ERRP("Could not allocate memory to read image"); } else { if (fread(buf, 1, sb.st_size, image_fp) <= 0) { ERRP("Could not read image file %s", filename); } else { fivr->length += sb.st_size; add_image_to_fivr(buf, fivr); } } } } else { ERRP("Could not locate image file %s", filename); } add_fivr_to_fir(fivr, fir); total_length += fivr->length; return (READ_OK); }