示例#1
0
/**
 * Read a directory, saving the file information in entries
 * @param folder the folder where the files are
 * @param passed VAR param number of passed tests
 * @param failed VAR param number of failed tests
 * @return number of files found or 0 on failure
 */
static int read_dir( char *folder, int *passed, int *failed, plugin_log *log )
{
    int n_files = 0;
    DIR *dir;
    struct dirent *ent;
    if ((dir = opendir(folder)) != NULL) 
    {
        while ((ent = readdir(dir)) != NULL) 
        {
            int flen;
            int old_passed = *passed;
            if ( strcmp(ent->d_name,".")!=0&&strcmp(ent->d_name,"..")!=0 )
            {
                char *path = create_path(folder,ent->d_name);
                //printf("building tree for %s\n",ent->d_name);
                char *txt = read_file( path, &flen );
                if ( txt == NULL )
                    break;
                else
                {
                    int tlen = strlen(txt);
                    long mem2,mem1 = get_mem_usage();
                    int64_t time2,time1 = epoch_time();
                    int ulen = measure_from_encoding( txt, flen, "utf-8" );
                    if ( ulen > 0 )
                    {
                        UChar *dst = calloc( ulen+1, sizeof(UChar) );
                        if ( dst != NULL )
                        {
                            int res = convert_from_encoding( txt, flen, dst, 
                                ulen+1, "utf-8" );
                            if ( res )
                            {
                                suffixtree *tree = suffixtree_create( dst, 
                                    ulen, log );
                                if ( tree != NULL )
                                {
                                    mem2 = get_mem_usage();
                                    time2 = epoch_time();
                                    entry *e = calloc( 1, sizeof(entry) );
                                    if ( e != NULL )
                                    {
                                        e->file = strdup(ent->d_name);
                                        e->space = mem2-mem1;
                                        e->time = time2-time1;
                                        e->size = flen;
                                        append_entry( e );
                                        (*passed)++;
                                        n_files++;
                                    }
                                    else
                                    {
                                        n_files = 0;
                                        dispose_entries();
                                        fprintf(stderr,
                                            "test: failed to allocate entry\n");
                                        break;
                                    }
                                    suffixtree_dispose( tree );
                                }
                            }
                            free(dst);
                        }
                    }
                    free( txt );
                }
                if ( *passed == old_passed )
                {
                    (*failed)++;
                    fprintf(stderr,"suffixtree: failed to create tree %s\n",path);
                }
                if ( path != NULL )
                    free( path );
            }
        }
        closedir( dir );
    }
    else
        fprintf(stderr,"test: failed to open directory %s\n",folder);
    return n_files;
}
示例#2
0
double mikrokopter::common::getTime()
{
  boost::posix_time::ptime epoch_time(boost::gregorian::date(1970, 1, 1));
  boost::posix_time::ptime current_time = boost::posix_time::microsec_clock::local_time();
  return(static_cast<double>((current_time - epoch_time).total_nanoseconds()) * 1.0e-9);
}