1 /* @source dbxuncompress application
2 **
3 ** Uncompress a compressed dbx index
4 **
5 ** @author Copyright (C) 2011 Peter Rice (pmr@ebi.ac.uk)
6 ** @@
7 **
8 ** This program is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License
10 ** as published by the Free Software Foundation; either version 2
11 ** of the License, or (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 ******************************************************************************/
22
23 #include "emboss.h"
24
25
26
27
28 /* @prog dbxuncompress ********************************************************
29 **
30 ** Uncompress a compressed dbx index
31 **
32 ******************************************************************************/
33
main(int argc,char ** argv)34 int main(int argc, char **argv)
35 {
36 AjPStr dbname = NULL;
37 AjPStr idir = NULL;
38 AjPStr fieldname = NULL;
39 AjPFile outf = NULL;
40
41 const AjPStr fieldext;
42 AjPBtcache cache = NULL;
43 AjBool secondary;
44 AjBool compressed;
45 ajuint kwlimit;
46 ajuint idlimit;
47 ajuint refcount;
48 ajuint pripagesize;
49 ajuint secpagesize;
50 ajuint pricachesize;
51 ajuint seccachesize;
52 ajulong pripagecount;
53 ajulong secpagecount;
54 ajuint order;
55 ajuint nperbucket;
56 ajuint level;
57 ajuint sorder;
58 ajuint snperbucket;
59 ajulong count;
60 ajulong countall;
61
62 embInit("dbxuncompress", argc, argv);
63
64 dbname = ajAcdGetString("dbname");
65 idir = ajAcdGetDirectoryName("indexdir");
66 fieldname = ajAcdGetString("field");
67 outf = ajAcdGetOutfile("outfile");
68
69 if(!ajStrGetLen(idir))
70 {
71 /* if not forced by the user, find the index directory for the database */
72 if(!ajNamDbGetIndexdir(dbname, &idir))
73 ajDie("Database '%S' has no indexdirectory defined", dbname);
74 }
75 fieldext = ajBtreeFieldGetExtensionS(fieldname);
76 if(!ajBtreeReadParamsS(dbname, fieldext,
77 idir, &secondary, &compressed,
78 &kwlimit, &idlimit, &refcount,
79 &pripagesize, &secpagesize,
80 &pricachesize, &seccachesize,
81 &pripagecount, &secpagecount,
82 &order, &nperbucket,
83 &level, &sorder, &snperbucket, &count, &countall))
84 {
85 ajDie("Cannot find index file '%S' for database '%S",
86 fieldname, dbname);
87 }
88
89 if(!compressed)
90 ajDie("index '%S' for database '%S' is not compressed",
91 fieldname, dbname);
92
93 ajFmtPrintF(outf, "Uncompressing index '%S' for database '%S'\n",
94 fieldname, dbname);
95
96 /* opening a compressed index for update automatically uncompresses */
97
98 cache = ajBtreeCacheNewUpdateS(dbname, fieldext, idir);
99
100 if(!cache)
101 ajDie("Cannot open index file '%S' for update for database '%S'",
102 fieldname, dbname);
103
104 ajFmtPrintF(outf, "Index '%S' uncompressed\n", fieldname);
105
106 /* set to uncompressed so it will close the expanded index as-is */
107
108 cache->compressed = ajFalse;
109
110 ajBtreeWriteParamsS(cache, dbname, fieldext, idir);
111
112 ajBtreeCacheDel(&cache); /* close cache and index */
113
114 ajFmtPrintF(outf, "Completed\n");
115
116 ajStrDel(&dbname);
117 ajStrDel(&fieldname);
118 ajStrDel(&idir);
119
120 ajFileClose(&outf);
121
122 embExit();
123
124 return 0;
125 }
126