00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifdef HAVE_CONFIG_H
00022 #include "config.h"
00023 #endif
00024
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <assert.h>
00028
00029 #include "libdefs.h"
00030 #include "error.h"
00031 #include "arrays.h"
00032 #include "alphabet.h"
00033 #include "fileutils.h"
00034 #include "sequences.h"
00035 #include "dbfiles.h"
00036 #include "suffixarray.h"
00037 #include "projectfile.h"
00038 #include "suffixarrayext.h"
00039 #include "verify.h"
00040
00041 #include "suffixarray.32"
00042 #include "suffixarrayext.32"
00043 #include "suffixarrayext.templ.c"
00044
00045 #include "suffixarray.64"
00046 #include "suffixarrayext.64"
00047 #include "suffixarrayext.templ.c"
00048
00049 #include "suffixarray.undef"
00050 #include "suffixarrayext.undef"
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 int fid_suffixarray_load_from_project(fid_Suffixarray *esa,
00068 fid_Projectfile *project,
00069 fid_Tablerequest tables,
00070 fid_Error *error)
00071 {
00072 int retval=1;
00073
00074 assert(esa != NULL);
00075 assert(project != NULL);
00076
00077 VERIFY_REQUEST(tables,error);
00078
00079 if((retval=fid_suffixarray_load_from_files(esa,project->prjbasename,tables,
00080 project->uisize,error)) == 0)
00081 {
00082 fid_SWITCH48(project->uisize,
00083 {
00084 if(sanity_checks_32(esa,project,tables,error) == 0)
00085 {
00086 return 0;
00087 }
00088 },
00089 {
00090 if(sanity_checks_64(esa,project,tables,error) == 0)
00091 {
00092 return 0;
00093 }
00094 });
00095 }
00096
00097 if(retval == 0)
00098 {
00099
00100 fid_suffixarray_free(esa);
00101 }
00102
00103 return -1;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 int fid_suffixarray_load_special(fid_Suffixarray *esa, const char *prjbasename,
00131 fid_Tablerequest tables,
00132 fid_Uintsize uisize_request,
00133 int ignore_byteorder, fid_Error *error)
00134 {
00135 fid_Projectfile project;
00136 int retcode;
00137
00138 VERIFY_REQUEST(tables,error);
00139
00140 if((retcode=fid_projectfile_parse_from_file(&project,prjbasename,error)) == 0)
00141 {
00142 if(ignore_byteorder ||
00143 (project.endianess_known &&
00144 #ifdef WORDS_BIGENDIAN
00145 !project.littleendian
00146 #else
00147 project.littleendian
00148 #endif
00149 ))
00150 {
00151 if(uisize_request == fid_UINTSIZE_UNDEF ||
00152 uisize_request == project.uisize)
00153 {
00154 retcode=fid_suffixarray_load_from_project(esa,&project,tables,error);
00155 }
00156 else
00157 {
00158 fid_error_throw(error,"Enhanced suffix array \"%s\" has integer size "
00159 "%u, requested size %u.",
00160 prjbasename,(project.uisize == fid_UINTSIZE_32)?32:64,
00161 (uisize_request == fid_UINTSIZE_32)?32:64);
00162 retcode=-1;
00163 }
00164 }
00165 else
00166 {
00167 if(project.endianess_known)
00168 {
00169 fid_error_throw(error,"Enhanced suffix array \"%s\" has wrong "
00170 "byte-order (%s endian), cannot use it on this "
00171 "architecture.",
00172 prjbasename,project.littleendian?"little":"big");
00173 }
00174 else
00175 {
00176 fid_error_throw(error,"Enhanced suffix array \"%s\" has unknown "
00177 "byte-order, cannot use it. Set the littleendian "
00178 "variable in file %s.prj to the correct value (i.e., "
00179 "either 0 or 1), and try again.",
00180 prjbasename,prjbasename);
00181 }
00182 retcode=-1;
00183 }
00184 fid_projectfile_free(&project);
00185 }
00186
00187 return retcode;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 int fid_suffixarray_load(fid_Suffixarray *esa, const char *prjbasename,
00212 fid_Tablerequest tables, fid_Error *error)
00213 {
00214 return fid_suffixarray_load_special(esa,prjbasename,tables,
00215 fid_UINTSIZE_UNDEF,0,error);
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 int fid_projectfile_init_from_suffixarray(fid_Projectfile *project,
00236 const fid_DBfiles *dbfiles,
00237 const char *prjbasename,
00238 const fid_Suffixarray *esa,
00239 fid_Error *error)
00240 {
00241 if(fid_projectfile_init(project,prjbasename,error) == -1)
00242 {
00243 return -1;
00244 }
00245
00246 if(fid_dbfiles_copy(&project->dbfiles,dbfiles,error) == -1)
00247 {
00248 return -1;
00249 }
00250
00251 project->uisize=esa->uisize;
00252
00253 fid_SWITCH48(project->uisize,
00254 {
00255 project->integer_size_in_bytes=4;
00256 init_from_esa_32(project,esa);
00257 },
00258 {
00259 project->integer_size_in_bytes=8;
00260 init_from_esa_64(project,esa);
00261 });
00262
00263 project->integer_size_in_bits=8*project->integer_size_in_bytes;
00264
00265 return 0;
00266 }
00267
00268