The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lexdump.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * lexdump.c - This utility outputs a specified ordinal entry from a lex
4  *
5  * $Id: lexdump.c 2833 2013-06-29 06:40:28Z chrislit $
6  *
7  * Copyright 1999-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #ifdef _MSC_VER
24  #pragma warning( disable: 4996 )
25 #endif
26 
27 #include <ctype.h>
28 #include <stdio.h>
29 #include <fcntl.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <errno.h>
33 #include <stdlib.h>
34 #include <string.h>
35 
36 #ifndef __GNUC__
37 #include <io.h>
38 #else
39 #include <unistd.h>
40 #endif
41 
42 #ifndef O_BINARY
43 #define O_BINARY 0
44 #endif
45 
46 int main(int argc, char **argv) {
47  char *tmpbuf;
48  int idxfd, datfd;
49  long offset;
50  unsigned int size;
51  char datbuf[255];
52 
53  if (argc != 3) {
54  fprintf(stderr, "usage: %s <datapath/datafilebasename> <index>\n", argv[0]);
55  exit(1);
56  }
57 
58  tmpbuf = calloc(strlen(argv[1]) + 11,1);
59  sprintf(tmpbuf, "%s.idx", argv[1]);
60  idxfd = open(tmpbuf, O_RDONLY|O_BINARY);
61  sprintf(tmpbuf, "%s.dat", argv[1]);
62  datfd = open(tmpbuf, O_RDONLY|O_BINARY);
63  free(tmpbuf);
64 
65  offset = atoi(argv[2]) * 6;
66  lseek(idxfd, offset, SEEK_SET);
67  read(idxfd, &offset, 4);
68  read(idxfd, &size, 2);
69  printf("offset: %ld; size: %d\n", offset, size);
70  lseek(datfd, offset, SEEK_SET);
71  read(datfd, datbuf, 40);
72  datbuf[40] = 0;
73  printf("%s\n", datbuf);
74  close(datfd);
75  close(idxfd);
76  return 0;
77 
78 }
#define O_BINARY
Definition: lexdump.c:43
int main(int argc, char **argv)
Definition: addcomment.cpp:32
free(preg->fastmap)
#define SEEK_SET
Definition: zconf.h:244
int size
Definition: regex.c:5043