diff --git a/build/sonar-project.properties b/build/sonar-project.properties new file mode 100644 index 000000000..b1673de7d --- /dev/null +++ b/build/sonar-project.properties @@ -0,0 +1,10 @@ +# must be unique in a given SonarQube instance +sonar.projectKey=LifeLines:LATEST + +# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. +sonar.projectName=LifeLines +sonar.projectVersion=LATEST + +# Path is relative to the sonar-project.properties file. +#sonar.sources=src/arch,src/btree,src/gedlib,src/interp,src/liflines,src/stdlib,src/tools,src/ui +sonar.sources=src diff --git a/build/sonar.sh b/build/sonar.sh new file mode 100644 index 000000000..904af529a --- /dev/null +++ b/build/sonar.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# NOTE: This script assumes that: +# - the sonarqube server is running on the default port +# - the C/C++ module has been installed in SonciQube +# - the sonar-scanner is installed and in $PATH + +# Check for configuration file +if [ ! -f sonar-project.properties ] +then + echo "ERROR: Could not find sonarqube properties file!" + exit +fi + +# Get and unzip build wrapper +wget http://localhost:9000/static/cpp/build-wrapper-linux-x86.zip +unzip build-wrapper-linux-x86.zip + +# Build with build wrapper +(cd ..; build/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir build/sonar_build_wrapper_output make clean all) + +# Run analysis +# NOTE: This assumes that: +# - the sonarqube server is running on the default port +# - the sonar-scanner is installed and in $PATH +(cd ..; sonar-scanner -Dproject.settings=build/sonar-project.properties -Dsonar.cfamily.build-wrapper-output=build/sonar_build_wrapper_output) + +# Remove build wrapper and scanner files +rm -rf sonar_build_wrapper_output +rm -rf ../.scannerwork + +# Remove build wrapper +rm -rf build-wrapper-linux-x86 +rm -f build-wrapper-linux-x86.zip diff --git a/configure.ac b/configure.ac index 179c6981d..0714a601f 100644 --- a/configure.ac +++ b/configure.ac @@ -82,6 +82,39 @@ case $host in ;; esac +dnl Specify bit width if requrested +AC_ARG_WITH(32bit, + [ --with-32bit Build in 32-bit mode ], + [build_32bit=$withval], + [build_32bit=no]) + +AC_ARG_WITH(64bit, + [ --with-64bit Build in 64-bit mode ], + [build_64bit=$withval], + [build_64bit=no]) + +if test "$build_32bit" = "yes" +then + if test "${ac_cv_prog_gcc}" = "yes"; then + CFLAGS="${CFLAGS} -m32" + LDFLAGS="${LDFLAGS} -m32" + else + echo "The use of --with-32bit is only supported when using gcc!" + exit + fi +fi + +if test "$build_64bit" = "yes" +then + if test "${ac_cv_prog_gcc}" = "yes"; then + CFLAGS="${CFLAGS} -m64" + LDFLAGS="${LDFLAGS} -m64" + else + echo "The use of --with-64bit is only supported when using gcc!" + exit + fi +fi + dnl ************************************************************** dnl Handle Docs Target dnl ************************************************************** diff --git a/src/gedlib/charmaps.c b/src/gedlib/charmaps.c index 915f41932..6800adaa9 100644 --- a/src/gedlib/charmaps.c +++ b/src/gedlib/charmaps.c @@ -87,8 +87,10 @@ static XNODE create_xnode(XNODE, INT, STRING); static BOOLEAN init_map_from_str(STRING str, CNSTRING mapname, TRANTABLE * ptt, ZSTR zerr); static void maperror(CNSTRING errmsg); static void remove_xnodes(XNODE); +#ifdef DEBUG static void show_xnode(XNODE node); static void show_xnodes(INT indent, XNODE node); +#endif static XNODE step_xnode(XNODE, INT); static INT translate_match(TRANTABLE tt, CNSTRING in, CNSTRING * out); @@ -607,7 +609,6 @@ show_trantable (TRANTABLE tt) } } } -#endif /* DEBUG */ /*=============================================== * show_xnodes -- DEBUG routine that shows XNODEs @@ -638,6 +639,8 @@ show_xnode (XNODE node) } else llwprintf("\n"); } +#endif /* DEBUG */ + /*=================================================== * custom_translatez -- Translate string via custom translation table * zstr: [I/O] string to be translated (in-place) diff --git a/src/gedlib/dblist.c b/src/gedlib/dblist.c index f58c7b570..71b882e80 100644 --- a/src/gedlib/dblist.c +++ b/src/gedlib/dblist.c @@ -41,7 +41,6 @@ INT get_dblist (STRING path, LIST * dblist, LIST * dbdesclist) { STRING dirs=0; - INT ndirs=0; STRING p=0; ASSERT(!(*dblist)); ASSERT(!(*dbdesclist)); @@ -51,7 +50,6 @@ get_dblist (STRING path, LIST * dblist, LIST * dbdesclist) return 0; dirs = (STRING)stdalloc(strlen(path)+2); /* find directories in dirs & delimit with zeros */ - ndirs = chop_path(path, dirs); /* now process each directory */ for (p=dirs; *p; p+=strlen(p)+1) { add_dbs_to_list(*dblist, *dbdesclist, p); diff --git a/src/gedlib/indiseq.c b/src/gedlib/indiseq.c index 903f5e4c1..206d80166 100644 --- a/src/gedlib/indiseq.c +++ b/src/gedlib/indiseq.c @@ -1396,7 +1396,7 @@ indi_to_families (NODE indi, BOOLEAN fams) { INT temp = atoi(indi_to_key(spouse) + 1); if (temp && temp != mykeynum) - spkeynum = temp; + spkeynum = temp; //TODO is this right? this loop doesn't do anything } ENDFAMSPOUSES append_indiseq_ival(seq, fkey, NULL, mykeynum, TRUE, FALSE); diff --git a/src/gedlib/xreffile.c b/src/gedlib/xreffile.c index 4f797b7b3..7a6f1b10f 100644 --- a/src/gedlib/xreffile.c +++ b/src/gedlib/xreffile.c @@ -47,8 +47,8 @@ extern BTREE BTR; * and other keys in file; remaining words are keys, in respective * order, for the records; first in each group is next unused key; * rest are keys of deleted records - * nixrefs==1 means there are no deleted INDI keys - * nixrefs==2 means there is one deleted INDI key (ixrefs[1]) + * n==1 means there are no deleted INDI keys + * n==2 means there is one deleted INDI key (ixrefs[1]) *=================================================================*/ /* In memory, data is kept in a DELETESET @@ -86,7 +86,6 @@ struct deleteset_s }; typedef struct deleteset_s *DELETESET; - /********************************************* * local function prototypes *********************************************/ @@ -98,6 +97,7 @@ static BOOLEAN addsxref_impl(INT key, DUPS dups); static BOOLEAN addexref_impl(INT key, DUPS dups); static BOOLEAN addxref_impl(CNSTRING key, DUPS dups); static BOOLEAN addxxref_impl(INT key, DUPS dups); +static void dumpxrecs(STRING type, DELETESET set, INT *offset); static INT find_slot(INT keynum, DELETESET set); static void freexref(DELETESET set); static DELETESET get_deleteset_from_type(char ctype); @@ -365,6 +365,54 @@ writexrefs (void) fflush(xreffp); return TRUE; } +/*================================ + * dumpxrefs -- Print xrefs to stdout + * storage order: IFESX + *==============================*/ +void +dumpxrefs (void) +{ + INT offset = 0; + + printf("NOTE: n is always the number of deleted keys PLUS ONE.\n"); + printf("NOTE: Each entry indicates the next available key value.\n\n"); + + /* Dump "n" values */ + printf("0x%02x: I n: 0x%08x (%d)\n", offset, irecs.n, irecs.n); + offset += sizeof(irecs.n); + printf("0x%02x: F n: 0x%08x (%d)\n", offset, frecs.n, frecs.n); + offset += sizeof(frecs.n); + printf("0x%02x: E n: 0x%08x (%d)\n", offset, erecs.n, erecs.n); + offset += sizeof(erecs.n); + printf("0x%02x: S n: 0x%08x (%d)\n", offset, srecs.n, srecs.n); + offset += sizeof(srecs.n); + printf("0x%02x: X n: 0x%08x (%d)\n", offset, xrecs.n, xrecs.n); + offset += sizeof(xrecs.n); + + /* Dump "recs" values */ + dumpxrecs("I", &irecs, &offset); + dumpxrecs("F", &frecs, &offset); + dumpxrecs("E", &erecs, &offset); + dumpxrecs("S", &srecs, &offset); + dumpxrecs("X", &xrecs, &offset); + + /* Dump size */ + printf("0x%02x: EOF (0x%02x)\n", offset, offset); +} +/*================================ + * dumpxrecs -- Print DELETESET to stdout + *==============================*/ +static void +dumpxrecs (STRING type, DELETESET set, INT *offset) +{ + INT i; + + for (i=0; in; i++) + { + printf("0x%02x: %s[%02d]: 0x%08x (%d)\n", *offset, type, i, (set->recs)[i], (set->recs)[i]); + *offset += sizeof((set->recs)[i]); + } +} /*===================================== * find_slot -- Find slot at which to add key *===================================*/ diff --git a/src/hdrs/btree.h b/src/hdrs/btree.h index 62c4da9ed..b2f25d12f 100644 --- a/src/hdrs/btree.h +++ b/src/hdrs/btree.h @@ -71,6 +71,7 @@ add it to any database that does not yet have it. */ typedef struct { char name[18]; /* KF_NAME */ + char pad[2]; /* matches padding added by compiler */ INT magic; /* KF_MAGIC */ /* byte alignment check */ INT version; /* KF_VER */ } KEYFILE2; diff --git a/src/hdrs/gedcom.h b/src/hdrs/gedcom.h index b5b8677ef..9818a82fd 100644 --- a/src/hdrs/gedcom.h +++ b/src/hdrs/gedcom.h @@ -250,6 +250,7 @@ BOOLEAN create_database(STRING dbused, INT *lldberr); NODE create_node(STRING, STRING, STRING, NODE); NODE create_temp_node(STRING, STRING, STRING, NODE); void delete_metarec(STRING key); +void dumpxrefs(void); BOOLEAN edit_mapping(INT); BOOLEAN edit_valtab_from_db(STRING, TABLE*, INT sep, STRING, STRING (*validator)(TABLE tab, void * param), void *param); BOOLEAN equal_tree(NODE, NODE); diff --git a/src/interp/builtin.c b/src/interp/builtin.c index 431071a12..20a5e871c 100644 --- a/src/interp/builtin.c +++ b/src/interp/builtin.c @@ -1152,7 +1152,7 @@ llrpt_alpha (PNODE node, SYMTAB stab, BOOLEAN *eflg) i = pvalue_to_int(val); delete_pvalue_ptr(&val); if (i < 1 || i > 26) - sprintf(scratch, "XX"); + sprintf(scratch, "_"); else sprintf(scratch, "%c", 'a' + i - 1); return create_pvalue_from_string(scratch); diff --git a/src/interp/lex.c b/src/interp/lex.c index 3e2072f40..2e7034407 100644 --- a/src/interp/lex.c +++ b/src/interp/lex.c @@ -210,7 +210,7 @@ lextok (PACTX pactx, YYSTYPE * lvalp, INT c, INT t) p = tokbuf; while (TRUE) { while ((c = inchar(pactx)) != EOF && c != '"' && c != '\\') { - if (p-tokbuf > sizeof(tokbuf)/sizeof(tokbuf[0]) - 3) { + if (p-tokbuf > (int)(sizeof(tokbuf)/sizeof(tokbuf[0]) - 3)) { /* Overflowing tokbuf buffer */ /* TODO: (Perry, 2006-06-30) I don't know how to fail gracefully from here inside parser */ char msg[512]; diff --git a/src/liflines/browse.c b/src/liflines/browse.c index 3f21db093..d101d62c1 100644 --- a/src/liflines/browse.c +++ b/src/liflines/browse.c @@ -1635,7 +1635,7 @@ static void save_nkey_list (STRING key, struct hist * histp) { FILE * fp=0; - INT next, prev, count, temp; + INT next, count, temp; size_t rtn; count = get_hist_count(histp); @@ -1649,7 +1649,6 @@ save_nkey_list (STRING key, struct hist * histp) rtn = fwrite(&count, 4, 1, fp); ASSERT(rtn==1); rtn = fwrite(&count, 4, 1, fp); ASSERT(rtn==1); - prev = -1; next = histp->start; while (1) { /* write type & number, 4 bytes each */ @@ -1657,7 +1656,6 @@ save_nkey_list (STRING key, struct hist * histp) rtn = fwrite(&temp, 4, 1, fp); ASSERT(rtn==1); temp = histp->list[next].keynum; rtn = fwrite(&temp, 4, 1, fp); ASSERT(rtn==1); - prev = next; next = (next+1) % histp->size; if (next == histp->past_end) break; /* finished them all */ @@ -1684,7 +1682,7 @@ static void history_record (RECORD rec, struct hist * histp) { NKEY nkey = nkey_zero(); - INT prev, next, i; + INT next, i; INT count = get_hist_count(histp); INT protect = getlloptint("HistoryBounceSuppress", 0); if (!histp->size) return; @@ -1704,13 +1702,11 @@ history_record (RECORD rec, struct hist * histp) if (protect>count) protect=count; /* traverse from most recent back (bounce suppression) */ - prev = -1; next = (histp->past_end-1); if (next < 0) next += histp->size; for (i=0; ilist[next])) return; - prev = next; if (--next < 0) next += histp->size; } /* it is a new one so add it to circular list */ @@ -1828,13 +1824,12 @@ static INDISEQ get_history_list (struct hist * histp) { INDISEQ seq=0; - INT next, prev; + INT next; if (!histp->size || histp->start==-1) { return NULL; } /* add all items of history to seq */ seq = create_indiseq_null(); - prev = -1; next = histp->start; while (1) { NODE node=0; @@ -1843,7 +1838,6 @@ get_history_list (struct hist * histp) STRING key = node_to_key(node); append_indiseq_null(seq, key, NULL, TRUE, FALSE); } - prev = next; next = (next+1) % histp->size; if (next == histp->past_end) break; /* finished them all */ diff --git a/src/liflines/cscurses.c b/src/liflines/cscurses.c index 2f9f3b01c..6aa88c994 100644 --- a/src/liflines/cscurses.c +++ b/src/liflines/cscurses.c @@ -139,10 +139,13 @@ mvccwprintw (WINDOW *wp, int y, int x, ...) { va_list args; char * fmt; + int ret; va_start(args, x); wmove(wp, y, x); fmt = va_arg(args, char *); - return vccwprintw(wp, fmt, args); + ret = vccwprintw(wp, fmt, args); + va_end(args); + return ret; } /*============================ * vccwprintw -- vwprintw with codeset convert from internal to GUI diff --git a/src/liflines/import.c b/src/liflines/import.c index daca1d8e5..9560cc0eb 100644 --- a/src/liflines/import.c +++ b/src/liflines/import.c @@ -343,12 +343,10 @@ static void restore_record (NODE node, INT type, INT num) { STRING old, new, str, key; - char scratch[10]; if (!node) return; ASSERT(old = nxref(node)); new = translate_key(rmvat(old)); - sprintf(scratch, "%6ld", num); switch (type) { case INDI_REC: break; case FAM_REC: break; diff --git a/src/liflines/llexec.c b/src/liflines/llexec.c index 0c517548d..a2f65c114 100644 --- a/src/liflines/llexec.c +++ b/src/liflines/llexec.c @@ -111,7 +111,6 @@ main (int argc, char **argv) LIST exprogs=NULL; TABLE exargs=NULL; STRING progout=NULL; - BOOLEAN graphical=TRUE; STRING configfile=0; STRING crashlog=NULL; int i=0; @@ -256,7 +255,7 @@ main (int argc, char **argv) progout = optarg; break; case 'z': /* nongraphical box */ - graphical = FALSE; +// graphical = FALSE; break; case 'C': /* specify config file */ configfile = optarg; diff --git a/src/stdlib/generic.c b/src/stdlib/generic.c index 17993749e..446054d0a 100644 --- a/src/stdlib/generic.c +++ b/src/stdlib/generic.c @@ -303,7 +303,7 @@ clear_generic (GENERIC *gen) case GENERIC_INT: break; case GENERIC_FLOAT: stdfree(gen->data.fval); - gen->data.fval = 0; + gen->data.fval = 0; // TODO fall through OK?? case GENERIC_STRING: stdfree(gen->data.sval); gen->data.sval = 0; diff --git a/src/stdlib/version.c b/src/stdlib/version.c index 079005a90..a0e349197 100644 --- a/src/stdlib/version.c +++ b/src/stdlib/version.c @@ -59,7 +59,7 @@ print_version (CNSTRING program) printf("%s (lifelines) %s\n", program, get_lifelines_version(48)); printf("\n"); - printf(_("Copyright (C) 1991-2018 Thomas T. Wetmore IV and contributors.")); + printf(_("Copyright (C) 1991-2019 Thomas T. Wetmore IV and contributors.")); printf("\n"); printf(_("This is free software; see the source for copying conditions. There is NO\n" "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.")); diff --git a/src/tools/.gitignore b/src/tools/.gitignore index d2e62b0ac..871451153 100644 --- a/src/tools/.gitignore +++ b/src/tools/.gitignore @@ -4,4 +4,5 @@ Makefile.in .deps btedit dbverify +lldump lltest diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index aeb0a9099..10b90faf1 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -4,12 +4,13 @@ # AUTOMAKE_OPTIONS = no-dependencies # what are we going to build? -bin_PROGRAMS = btedit dbverify lltest +bin_PROGRAMS = btedit dbverify lldump lltest # what goes into btedit, dbverify and lltest? btedit_SOURCES = btedit.c wprintf.c dbverify_SOURCES = dbverify.c wprintf.c lltest_SOURCES = lltest.c wprintf.c +lldump_SOURCES = lldump.c wprintf.c # what libraries do btedit, dbverify and lltest need? btedit_LDADD = ../btree/libbtree.a ../stdlib/libstdlib.a \ @@ -19,6 +20,10 @@ dbverify_LDADD = ../gedlib/libgedcom.a ../btree/libbtree.a \ ../stdlib/libstdlib.a ../arch/libarch.a \ @LIBINTL@ @LIBICONV@ +lldump_LDADD = ../gedlib/libgedcom.a ../btree/libbtree.a \ + ../stdlib/libstdlib.a ../arch/libarch.a \ + @LIBINTL@ @LIBICONV@ + lltest_LDADD = ../btree/libbtree.a ../stdlib/libstdlib.a \ @LIBINTL@ @LIBICONV@ @@ -57,4 +62,6 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ # since we're not doing dependencies automagically... btedit.o: ../hdrs/standard.h ../hdrs/mystring.h ../hdrs/btree.h dbverify.o: ../hdrs/standard.h ../hdrs/btree.h ../hdrs/gedcom.h +lldump.o: ../hdrs/standard.h ../hdrs/mystring.h ../hdrs/btree.h lltest.o: ../hdrs/standard.h ../hdrs/mystring.h ../hdrs/btree.h + diff --git a/src/tools/dbverify.c b/src/tools/dbverify.c index 550efab28..2c8c7ec70 100644 --- a/src/tools/dbverify.c +++ b/src/tools/dbverify.c @@ -235,7 +235,7 @@ print_usage (void) #endif llstrncpyf(verstr, sizeof(verstr), uu8, title , get_lifelines_version(sizeof(verstr)-1-strlen(title))); - printf(_("usage: dbverify -(flags) \n")); + printf(_("usage: dbverify [flags] \n")); printf(_("flags:\n")); printf(_("\t-a = Perform all checks (does not include fixes)\n")); printf(_("\t-g = Check for ghosts (names/refns)\n")); diff --git a/src/tools/lldump.c b/src/tools/lldump.c new file mode 100644 index 000000000..7c994d4f3 --- /dev/null +++ b/src/tools/lldump.c @@ -0,0 +1,547 @@ +/* + Copyright (c) 2019 Matthew Emmerton + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/*================================================================= + * lldump.c -- Command that dumps LifeLines databaes. + *===============================================================*/ + +#include "llstdlib.h" +#include "btree.h" +#include "gedcom.h" +#include "version.h" + +/********************************************* + * required global variables + *********************************************/ +/* defined in liflines/main.c */ +STRING readpath_file = NULL; /* normally defined in liflines/main.c */ +STRING readpath = NULL; /* normally defined in liflines/main.c */ +BOOLEAN readonly = FALSE; /* normally defined in liflines/main.c */ +BOOLEAN writeable = FALSE; /* normally defined in liflines/main.c */ +BOOLEAN immutable = FALSE; /* normally defined in liflines/main.c */ +int opt_finnish = 0; +int opt_mychar = 0; +BTREE BTR; + +/*================================== + * work -- what the user wants to do + *================================*/ +struct work { + INT dump_btree; + INT dump_key; + INT dump_record; + INT dump_xref; +}; +static struct work todo; + +/********************************************* + * local function prototypes + *********************************************/ + +/* alphabetical */ +void crashlog (STRING fmt, ...); +void crashlogn (STRING fmt, ...); +void dump_block(STRING dir); +void dump_index(STRING dir); +void dump_keyfile(STRING dir); +void dump_xref(STRING dir); +void print_block(BLOCK block, INT *offset); +void print_index(INDEX index, INT *offset); +void print_keyfile1(KEYFILE1 kfile1); +void print_keyfile2(KEYFILE2 kfile2); +static void print_usage(void); +void print_xrefs(void); +static void vcrashlog (int newline, const char * fmt, va_list args); + +/********************************************* + * local function definitions + * body of module + *********************************************/ + +/*========================================= + * main -- Main procedure of lldump command + *=======================================*/ +int +main (int argc, + char **argv) +{ + char cmdbuf[512]; + char *ptr, *flags, *dbname; + RECORD_STATUS recstat; + BOOLEAN cflag=FALSE; /* create new db if not found */ + BOOLEAN writ=1; /* request write access to database */ + BOOLEAN immut=FALSE; /* immutable access to database */ + INT lldberrnum=0; + int rtn=0; + int i=0; + + /* TODO: needs locale & gettext initialization */ + +#ifdef WIN32 + /* TO DO - research if this is necessary */ + _fmode = O_BINARY; /* default to binary rather than TEXT mode */ +#endif + + /* handle conventional arguments --version and --help */ + /* needed for help2man to synthesize manual pages */ + for (i=1; i")); + printf("\n\n"); + printf(_("options:\n")); + printf(_("\t-a = Dump ALL records\n")); + printf(_("\t-b = Dump btree (INDEX)\n")); + printf(_("\t-k = Dump key files (KEYFILE1, KEYFILE2)\n")); + printf(_("\t-x = Dump xref file (DELETESET)\n")); + printf(_("\t-r = Dump records (BLOCK)\n")); + printf("\n"); + printf(_("\t--help\tdisplay this help and exit")); + printf("\n"); + printf(_("\t--version\toutput version information and exit")); + printf("\n\n"); + printf(_("Examples:")); + printf("\n"); + printf(_("\tlldump %s"), fname); + printf("\n\n"); + printf(_("Report bugs to https://github.com/MarcNo/lifelines/issues")); + printf("\n"); +} +/*=============================================== + * dump_index -- open and print index to stdout + *=============================================*/ +void dump_index(STRING dir) +{ + char scratch[200]; + struct stat sbuf; + char buffer[BUFLEN]; + FILE *fi; + INDEX index; + INT offset = 0; + + sprintf(scratch, "%s/aa/aa", dir); + if (stat(scratch, &sbuf) || !S_ISREG(sbuf.st_mode)) { + printf("Error opening master index\n"); + goto error2; + } + + if (!(fi = fopen(scratch, LLREADBINARY))) { + printf("Error opening master index\n"); + goto error2; + } + + if (fread(&buffer, BUFLEN, 1, fi) != 1) { + printf("Error reading master index\n"); + goto error1; + } + + index = (INDEX)buffer; + + print_index(index, &offset); + +error1: + fclose(fi); +error2: + return; +} +/*=============================== + * print_index -- print INDEX to stdout + *=============================*/ +void print_index(INDEX index, INT *offset) +{ + INT n; + + printf("INDEX\n"); + printf("0x%04x: ix_self: %d\n", *offset, index->ix_self); + *offset += sizeof(index->ix_self); + + printf("0x%04x: ix_type: %d\n", *offset, index->ix_type); + *offset += sizeof(index->ix_type); + +#if 0 +#if __WORDSIZE != 16 + printf("0x%04x: ix_pad1: %d\n", *offset, index->ix_pad1); + *offset += sizeof(index->ix_pad1); +#endif +#endif + + printf("0x%04x: ix_parent: %d\n", *offset, index->ix_parent); + *offset += sizeof(index->ix_parent); + + printf("0x%04x: ix_nkeys: %d\n", *offset, index->ix_nkeys); + *offset += sizeof(index->ix_nkeys); + + for (n=0; nix_rkeys[n]); + *offset += sizeof(index->ix_rkeys[n]); + } + +#if 0 +#if __WORDSIZE != 16 + printf("0x%04x: ix_pad2: %d\n", *offset, index->ix_pad2); + *offset += sizeof(index->ix_pad2); +#endif +#endif + + for (n=0; nix_fkeys[n]); + *offset += sizeof(index->ix_fkeys[n]); + } + + printf("0x%04x: EOF (0x%04x)\n", *offset, BUFLEN); + printf("\n"); +} +/*=============================================== + * dump_block -- open and print block to stdout + *=============================================*/ +void dump_block(STRING dir) +{ + char scratch[200]; + struct stat sbuf; + char buffer[BUFLEN]; + FILE *fb; + BLOCK block; + INT offset = 0; + + sprintf(scratch, "%s/ab/aa", dir); + if (stat(scratch, &sbuf) || !S_ISREG(sbuf.st_mode)) { + printf("Error opening master block\n"); + goto error2; + } + + if (!(fb = fopen(scratch, LLREADBINARY))) { + printf("Error opening master block\n"); + goto error2; + } + + if (fread(&buffer, BUFLEN, 1, fb) != 1) { + printf("Error reading master bock\n"); + goto error1; + } + + block = (BLOCK)buffer; + + print_block(block, &offset); + +error1: + fclose(fb); +error2: + return; +} + +/*=============================== + * print_block -- print BLOCK to stdout + *=============================*/ +void print_block(BLOCK block, INT *offset) +{ + INT n; + + printf("BLOCK\n"); + printf("0x%04x: ix_self: %d\n", *offset, block->ix_self); + *offset += sizeof(block->ix_self); + + printf("0x%04x: ix_type: %d\n", *offset, block->ix_type); + *offset += sizeof(block->ix_type); + +#if 0 +#if __WORDSIZE != 16 + printf("0x%04x: ix_pad1: %d\n", *offset, block->ix_pad1); + *offset += sizeof(block->ix_pad1); +#endif +#endif + + printf("0x%04x: ix_parent: %d\n", *offset, block->ix_parent); + *offset += sizeof(block->ix_parent); + + printf("0x%04x: ix_nkeys: %d\n", *offset, block->ix_nkeys); + *offset += sizeof(block->ix_nkeys); + + for (n=0; nix_rkeys[n]); + *offset += sizeof(block->ix_rkeys[n]); + } + +#if 0 +#if __WORDSIZE != 16 + printf("0x%04x: ix_pad2: %d\n", *offset, block->ix_pad2); + *offset += sizeof(block->ix_pad2); +#endif +#endif + + for (n=0; nix_offs[n]); + *offset += sizeof(block->ix_offs[n]); + + printf("0x%04x: ix_lens[%04d]: 0x%08x\n", *offset, n, block->ix_lens[n]); + *offset += sizeof(block->ix_lens[n]); + } + + printf("0x%04x: EOF (0x%04x)\n", *offset, BUFLEN); + printf("\n"); +} +/*=============================== + * dump_keyfile -- open and print KEYFILE1 and KEYFILE2 to stdout + *=============================*/ +void dump_keyfile(STRING dir) +{ + char scratch[200]; + struct stat sbuf; + KEYFILE1 kfile1; + KEYFILE2 kfile2; + FILE *fk; + long size; + + sprintf(scratch, "%s/key", dir); + if (stat(scratch, &sbuf) || !S_ISREG(sbuf.st_mode)) { + printf("Error opening keyfile\n"); + goto error2; + } + + if (!(fk = fopen(scratch, LLREADBINARY))) { + printf("Error opening keyfile\n"); + goto error2; + } + + if (fseek(fk, 0, SEEK_END)) { + printf("Error seeking to end of keyfile\n"); + goto error1; + } + + size = ftell(fk); + + if (fseek(fk, 0, SEEK_SET)) { + printf("Error seeking to start of keyfile\n"); + goto error1; + } + + if (size != sizeof(kfile1) && + size != (sizeof(kfile1) + sizeof(kfile2))) { + printf("Error: keyfile size invalid (%d), valid sizes are %d and %d\n", + size, sizeof(kfile1), sizeof(kfile1)+sizeof(kfile2)); + goto error1; + } + + if (fread(&kfile1, sizeof(kfile1), 1, fk) != 1) { + printf("Error reading keyfile\n"); + goto error1; + } + + print_keyfile1(kfile1); + + if (fread(&kfile2, sizeof(kfile2), 1, fk) != 1) { + printf("Error reading keyfile2\n"); + goto error1; + } + + print_keyfile2(kfile2); + +error1: + fclose(fk); +error2: + return; +} +/*=============================== + * print_keyfile1 -- print KEYFILE1 to stdout + *=============================*/ +void print_keyfile1(KEYFILE1 kfile1) +{ + INT offset = 0; + + printf("KEYFILE1\n"); + printf("========\n"); + + printf("0x%02x: mkey: 0x%08x (%d)\n", offset, kfile1.k_mkey, kfile1.k_mkey); + offset += sizeof(kfile1.k_mkey); + + printf("0x%02x: fkey: 0x%08x\n", offset, kfile1.k_fkey); + offset += sizeof(kfile1.k_fkey); + + printf("0x%02x: ostat: 0x%08x (%d)\n", offset, kfile1.k_ostat, kfile1.k_ostat); + offset += sizeof(kfile1.k_ostat); + + printf("0x%02x: EOF (0x%02x)\n", offset, sizeof(kfile1)); + printf("\n"); +} +/*=============================== + * print_keyfile2 -- print KEYFILE2 to stdout + *=============================*/ +void print_keyfile2(KEYFILE2 kfile2) +{ + INT offset = 0; + + printf("KEYFILE2\n"); + printf("========\n"); + + printf("0x%02x: name: '%-18.18s'\n", offset, kfile2.name); + offset += sizeof(kfile2.name); +#if WORDSIZE != 16 + printf("0x%02x: pad: 0x%04x\n", offset, kfile2.pad); + offset += sizeof(kfile2.pad); +#endif + printf("0x%02x: magic: 0x%08x\n", offset, kfile2.magic); + offset += sizeof(kfile2.magic); + + printf("0x%02x: version: 0x%08x (%d)\n", offset, kfile2.version, kfile2.version); + offset += sizeof(kfile2.version); + + printf("0x%02x: EOF (0x%02x)\n", offset, sizeof(kfile2)); + printf("\n"); +} +/*=============================== + * dump_xref -- open and print xrefs to stdout + *=============================*/ +void dump_xref(STRING dir) +{ + if (!openxref(FALSE)) + { + printf("Error opening/reading xrefs\n"); + goto error1; + } + + print_xrefs(); + +error1: + closexref(); + return; +} +/*=============================== + * print_xrefs -- print xrefs to stdout + *=============================*/ +void print_xrefs(void) +{ + printf("XREFFILE\n"); + printf("========\n"); + dumpxrefs(); +} +/*=============================== + * vcrashlog -- Send crash info to screen + * internal implementation + *=============================*/ +static void +vcrashlog (int newline, const char * fmt, va_list args) +{ + vprintf(fmt, args); + if (newline) { + printf("\n"); + } +} +/*=============================== + * crashlog -- Send string to crash log and screen + *=============================*/ +void +crashlog (STRING fmt, ...) +{ + va_list args; + va_start(args, fmt); + vcrashlog(0, fmt, args); + va_end(args); +} +/*=============================== + * crashlogn -- Send string to crash log and screen + * add carriage return to end line + *=============================*/ +void +crashlogn (STRING fmt, ...) +{ + va_list args; + va_start(args, fmt); + vcrashlog(1, fmt, args); + va_end(args); +} + diff --git a/src/tools/lltest.c b/src/tools/lltest.c index ad18b2e29..03bb234fc 100644 --- a/src/tools/lltest.c +++ b/src/tools/lltest.c @@ -72,10 +72,7 @@ main (int argc, char **argv) { BTREE btree; - char cmdbuf[512]; - char *editor; - char *dbname, *key; - RECORD_STATUS recstat; + char *dbname; BOOLEAN cflag=FALSE; /* create new db if not found */ BOOLEAN writ=1; /* request write access to database */ BOOLEAN immut=FALSE; /* immutable access to database */