int main(int argc, char *argv[]) { dbhead_t *dbh; int rec_num; if (argc < 2) { printf(USAGE); exit(1); } argv++; argc--; if ((dbh = dbf_open(*argv, O_RDWR)) == NULL) { fprintf(stderr, "unable to open database file %s\n", *argv); exit(1); } argv++; argc--; while (argc-- > 0) { rec_num = strtol(*argv++, NULL, 0); if (del_dbf_record(dbh, rec_num) < 0) { if (rec_num > dbh->db_records) { fprintf(stderr, "record %d out of bounds\n", rec_num); continue; } else { fprintf(stderr, "unable to delete record %d\n", rec_num); } } } put_dbf_info(dbh); exit(0); }
static Variant HHVM_FUNCTION(dbase_open, const String& filename, int64_t mode) { if (filename.isZero()) { raise_warning("The filename cannot be empty."); return Variant(false); } if ((mode < 0) || (mode > 3)) { raise_warning("Invalid access mode %" PRId64, mode); return Variant(false); } //if (php_check_open_basedir(Z_STRVAL_PP(dbf_name) TSRMLS_CC)) { // RETURN_FALSE; //} dbhead_t* dbh = dbf_open(filename.c_str(), mode); if (dbh == nullptr) { raise_warning("unable to open database %s", filename.c_str()); return Variant(false); } open_dbases->insert(std::make_pair(dbh->db_fd, std::shared_ptr<DBaseConnection>(new DBaseConnection(dbh)))); return Variant(dbh->db_fd); }
int main(int argc, char *argv[]) { dbhead_t *dbh; dbfield_t *dbf, *cur_f; char *fnp; char *cp; int nfields; int rec_cnt, i; extern int optind; int verbose = 0, head = 0, out_num = 0; while ((i = getopt(argc, argv, "vhr")) != EOF) { switch (i) { case 'v': verbose++; break; case 'h': head++; break; case 'r': out_num++; break; default: printf(USAGE); exit(1); } } argc -= optind; argv += optind; if (argc < 1) { printf(USAGE); exit(1); } if ((dbh = dbf_open(*argv, O_RDONLY)) == NULL) { fprintf(stderr, "unable to open database file %s\n", *argv); exit(1); } argv++; argc--; nfields = dbh->db_nfields; dbf = dbh->db_fields; if (verbose) dbf_head_info(dbh); /* put out the field headings */ if (head) { if (out_num) { printf("%8s ", " "); } printf(" "); for (cur_f = dbf; cur_f < &dbf[nfields] ; cur_f++) { fnp = (char *)strdup(cur_f->db_fname); if (strlen(fnp) > (unsigned int)cur_f->db_flen) { fnp[cur_f->db_flen] = 0; } printf(" "); printf(cur_f->db_format, fnp); free((char *)fnp); } printf("\n"); } /* step thru the records */ while (argc-- > 0) { rec_cnt = strtol(*argv++, NULL, 0); if ((cp = get_dbf_record(dbh, rec_cnt)) == NULL) { printf("tried to read bad record %d\n", rec_cnt); break; } if (out_num) { printf("%8d ", rec_cnt); } out_rec(dbh, dbf, cp); free(cp); } exit(0); }