00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _moot_UTILS_H
00030 #define _moot_UTILS_H
00031
00032 #include <stdio.h>
00033 #include <string.h>
00034 #include <string>
00035 #include <list>
00036
00037 #include <mootIO.h>
00038 #include <mootCIO.h>
00039
00040 namespace moot {
00041 using namespace std;
00042 using namespace mootio;
00043
00044
00047
00052 bool moot_parse_doubles(char *str, double *dbls, size_t ndbls);
00053
00054
00055
00056
00068 void moot_normalize_ws(const char *buf,
00069 size_t len,
00070 std::string &out,
00071 bool trim_left=true,
00072 bool trim_right=true);
00073
00084 void moot_normalize_ws(const std::string &in,
00085 std::string &out,
00086 bool trim_left=true,
00087 bool trim_right=true);
00088
00098 inline void moot_normalize_ws(const char *s,
00099 std::string &out,
00100 bool trim_left=true,
00101 bool trim_right=true)
00102 {
00103 moot_normalize_ws(s, strlen(s), out, trim_left, trim_right);
00104 };
00105
00115 inline std::string moot_normalize_ws(const char *buf,
00116 size_t len,
00117 bool trim_left=true,
00118 bool trim_right=true)
00119 {
00120 std::string out;
00121 out.reserve(len);
00122 moot_normalize_ws(buf,len, out, trim_left,trim_right);
00123 return out;
00124 };
00125
00134 inline std::string moot_normalize_ws(const char *s,
00135 bool trim_left=true,
00136 bool trim_right=true)
00137 {
00138 return moot_normalize_ws(s,strlen(s), trim_left,trim_right);
00139 };
00140
00149 inline std::string moot_normalize_ws(const std::string &s,
00150 bool trim_left=true,
00151 bool trim_right=true)
00152 {
00153 return moot_normalize_ws(s.data(),s.size(), trim_left,trim_right);
00154 };
00155
00156
00157
00158
00166 inline void moot_remove_newlines(char *buf, size_t len)
00167 {
00168 for (; len > 0; len--, buf++) {
00169 if (*buf == '\n') *buf = ' ';
00170 }
00171 };
00172
00174 inline void moot_remove_newlines(char *s)
00175 {
00176 moot_remove_newlines(s, strlen(s));
00177 };
00178
00180 inline void moot_remove_newlines(std::string &s)
00181 {
00182 for (std::string::iterator si = s.begin(); si != s.end(); si++) {
00183 if (*si == '\n') *si = ' ';
00184 }
00185 };
00186
00193 void moot_strtok(const std::string &s,
00194 const std::string &delim,
00195 std::list<std::string> &out);
00196
00202 inline std::list<std::string> moot_strtok(const std::string &s,
00203 const std::string &delim)
00204 {
00205 std::list<std::string> slist;
00206 moot_strtok(s,delim,slist);
00207 return slist;
00208 };
00210
00211
00214
00216 bool moot_file_exists(const char *filename);
00217
00219 std::string moot_unextend(const char *filename);
00220
00227 char *moot_extension(const char *filename, size_t pos);
00228
00230 inline char *moot_extension(const char *filename)
00231 {
00232 return moot_extension(filename, strlen(filename));
00233 };
00234
00244 bool hmm_parse_model_name(const std::string &modelname,
00245 std::string &binfile,
00246 std::string &lexfile,
00247 std::string &ngfile,
00248 std::string &lcfile);
00249
00258 bool hmm_parse_model_name_text(const std::string &modelname,
00259 std::string &lexfile,
00260 std::string &ngfile,
00261 std::string &lcfile);
00262
00263
00264
00269 class cmdutil_file_churner {
00270 public:
00271
00272 char *progname;
00273 char **inputs;
00274 int ninputs;
00276
00277 bool use_list;
00279
00280 mifstream in;
00281 mifstream list;
00283
00284 std::string line;
00286 public:
00288 cmdutil_file_churner(char *my_progname=NULL,
00289 char **my_inputs=NULL,
00290 int my_ninputs=0,
00291 bool my_use_list=false)
00292 : progname(my_progname),
00293 inputs(my_inputs),
00294 ninputs(my_ninputs),
00295 use_list(my_use_list)
00296 {};
00297
00299 ~cmdutil_file_churner() {};
00300
00302 FILE *first_input_file();
00303
00305 std::string &first_input_name();
00306
00308 FILE *next_input_file();
00309
00311 std::string &next_input_name();
00312
00313 private:
00315 FILE *next_list_file();
00316 };
00318
00319
00323 std::string moot_banner(void);
00324
00326 std::string moot_program_banner(const std::string &prog_name,
00327 const std::string &prog_version,
00328 const std::string &prog_author,
00329 bool is_free=true);
00331
00332 };
00333
00334 #endif