#include #include #include #include #include #include #include "maputil.h" using namespace std; int main (int argc, char *argv[]) { glocal const char *prefix = "/tmp/"; glocal SSTRINGS mapmsgs; int ret = (argc, argv); setproginfo ("splitlog",PACKAGE_REV ,"Split a log in multiple file using message files\n" "(with time stamp). The file produced will be named\n" "after the messages.\n" "\n" "The file produced are in the same format as the original\n" "so are suitable for use with maplog.\n"); setarg ('M',"mapmsg","Message file produced by mapmsg" ,glocal.mapmsgs,true); setarg ('p',"prefix","Prefix to create files",glocal.prefix,false); int ret = -1; if (argc != 1){ usage(); }else{ glocal int nofile = 0; glocal MALLOC_STATS_MSGS msgs; glocal FILE *fout = NULL; maputil_readmsgs (glocal.mapmsgs,glocal.msgs); maputil_setends (glocal.msgs,true); glocal MALLOC_STATS_MSGS::iterator cur = glocal.msgs.begin(); ret = (argv[0],true); long long t = map_s2ll (line); while (t >= glocal.cur->end){ if (glocal.fout != NULL){ fclose (glocal.fout); glocal.fout = NULL; } glocal.cur++; } if (glocal.fout == NULL){ SSTRING tmp; tmp.setfromf ("%s%03d-%s",glocal.prefix,glocal.nofile++ ,glocal.cur->msg.c_str()); glocal.fout = fopen (tmp.get(),"w"); if (glocal.fout == NULL){ fprintf (stderr,"Can't open file %s (%s)\n" ,tmp.get(),strerror(errno)); exit (-1); }else{ printf ("File %s\n",tmp.get()); } } fprintf (glocal.fout,"%s\n",line); return 0; } return ret; return ret; }