File: dbfdel.c

package info (click to toggle)
php3-dbase 1%3A3.0.5-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 264 kB
  • ctags: 596
  • sloc: ansic: 1,826; makefile: 140; sh: 33
file content (48 lines) | stat: -rw-r--r-- 937 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (c) 1993 Brad Eacker,
 *              (Music, Intuition, Software, and Computers)
 * All Rights Reserved
 */

#define	USAGE	"usage: dbfdel <file> [<record> <record> ...]\n"

/*
 * display the records of the database in question to the stdout
 */
#include <stdio.h>
#include <fcntl.h>

#include "dbf.h"

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);
}