File: lexdump.c

package info (click to toggle)
sword 1.7.3+dfsg-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 12,584 kB
  • ctags: 5,515
  • sloc: cpp: 41,736; sh: 11,924; ansic: 6,447; objc: 1,362; makefile: 1,239; cs: 897; java: 821; perl: 784; pascal: 681; tcl: 350; xml: 180; python: 79
file content (84 lines) | stat: -rw-r--r-- 2,072 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/******************************************************************************
 *
 *  lexdump.c -	This utility outputs a specified ordinal entry from a lex
 *
 * $Id: lexdump.c 2833 2013-06-29 06:40:28Z chrislit $
 *
 * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org)
 *	CrossWire Bible Society
 *	P. O. Box 2528
 *	Tempe, AZ  85280-2528
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation version 2.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#ifdef _MSC_VER
	#pragma warning( disable: 4996 )
#endif

#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>

#ifndef __GNUC__
#include <io.h>
#else
#include <unistd.h>
#endif

#ifndef O_BINARY
#define O_BINARY 0
#endif

int main(int argc, char **argv) {
	char *tmpbuf;
	int idxfd, datfd, r;
	long offset;
	unsigned int size;
	char datbuf[255];

	if (argc != 3) {
		fprintf(stderr, "usage: %s <datapath/datafilebasename> <index>\n", argv[0]);
		exit(1);
	}

	tmpbuf = calloc(strlen(argv[1]) + 11,1);
	sprintf(tmpbuf, "%s.idx", argv[1]);
	idxfd = open(tmpbuf, O_RDONLY|O_BINARY);
	sprintf(tmpbuf, "%s.dat", argv[1]);
	datfd = open(tmpbuf, O_RDONLY|O_BINARY);
	free(tmpbuf);

	offset = atoi(argv[2]) * 6;
	lseek(idxfd, offset, SEEK_SET);
	r = read(idxfd, &offset, 4);
	if (r != 4)
		perror("ERROR: read failed in main");
	r = read(idxfd, &size, 2);
	if (r != 2)
		perror("ERROR: read failed in main");
	printf("offset: %ld; size: %d\n", offset, size);
	lseek(datfd, offset, SEEK_SET);
	r = read(datfd, datbuf, 40);
	if (r != 40)
		perror("ERROR: read failed in main");
	datbuf[40] = 0;
	printf("%s\n", datbuf);
	close(datfd);
	close(idxfd);
	return 0;

}