Exemple #1
0
int main(int argc, char *argv[])
{
  long characters, words, lines;

  if (argc == 1) {
    wc(stdin, &characters, &words, &lines);
    print_totals(characters, words, lines);
    putchar('\n');
    return 0;
  }

  long c_total = 0, w_total = 0, l_total = 0;
  FILE *fp;

  for (int i = 1; i < argc; i++) {
    if ((fp = fopen(argv[i], "rb")) == NULL)
      print_e(errno, argv[0], argv[i]);

    wc(fp, &characters, &words, &lines);

    if (fclose(fp) == EOF)
      print_e(errno, argv[0], argv[i]);

    print_totals(characters, words, lines);
    printf("\t%s\n", argv[i]);
    if (argc > 2)
      c_total += characters; w_total += words; l_total += lines;
  }
  if (argc > 2) {
    print_totals(c_total, w_total, l_total);
    printf("\ttotal\n");
  }

  return 0;
}
Exemple #2
0
static void print_detailed(const matstat_state_t *states, size_t nelem, unsigned int test_min, const stat_limits_t *limits)
{
    if (LOG2_STATS) {
        print_str("   interval     count       sum       sum_sq    min   max  mean  variance\n");
        for (unsigned int k = 0; k < nelem; ++k) {
            char buf[20];
            unsigned int num = (1 << k);
            if (num >= TEST_NUM) {
                break;
            }
            unsigned int start = num + test_min;
            if (num == 1) {
                /* special case, bitarithm_msb will return 0 for both 0 and 1 */
                start = test_min;
            }
            print(buf, fmt_lpad(buf, fmt_u32_dec(buf, start), 4, ' '));
            print_str(" - ");
            print(buf, fmt_lpad(buf, fmt_u32_dec(buf, test_min + (num * 2) - 1), 4, ' '));
            print_str(": ");
            print_statistics(&states[k], limits);
        }
        print_str("      TOTAL  ");
    }
    else {
        print_str("interval    count       sum       sum_sq    min   max  mean  variance\n");
        for (unsigned int k = 0; k < nelem; ++k) {
            char buf[10];
            print(buf, fmt_lpad(buf, fmt_u32_dec(buf, k + test_min), 7, ' '));
            print_str(": ");
            print_statistics(&states[k], limits);
        }
        print_str("  TOTAL: ");
    }
    print_totals(states, nelem, limits);
}
Exemple #3
0
void tex::show_page_stats(int b, int pi, int c)
	{
	begin_diagnostic();
	print_nl("%");
	print(" t=");
	print_totals();
	print(" g=");
	print_scaled(page_goal);
	print(" b=");
	if (b == AWFUL_BAD) {
		print_char('*');
		} 
	else {
		print_int(b);
		}
	print(" p=");
	print_int(pi);
	print(" c=");
	if (c == AWFUL_BAD) {
		print("*");
	} else {
		print_int(c);
	}
	if (c <= least_page_cost) {
		print("#");
	}
	end_diagnostic(FALSE);
}
Exemple #4
0
/** inspect contents of mmap */
static void
inspect_contents(void* base)
{
	udb_glob_d* g;
	udb_alloc_d* a;
	struct inspect_totals t;
	memset(&t, 0, sizeof(t));
	g = inspect_glob_data(base);
	a = inspect_alloc(g);
	/* walk through file */
	inspect_all_chunks(base, g, a, &t);
	print_totals(&t);
}
Exemple #5
0
void tex::show_cur_page()
	{
	ptr	p, q;
	int	t;

	if (page_head == page_tail)
		return;
	print_nl("### current page:");
	if (output_active)
		print(" (held over for next output)");
	show_box(link(page_head));
	if (page_contents > EMPTY) {
		print_nl("total height ");
		print_totals();
		print_nl(" goal height ");
		print_scaled(page_goal);
		p = link(page_ins_head);
		while (p != page_ins_head) {
			print_ln();
			print_esc("insert");
			t = subtype(p);
			print_int(t);
			print(" adds ");
			t = x_over_n(page_ins_height(p), 1000) * count(t);
			print_scaled(t);
			if (type(p) == SPLIT_UP) {
				q = page_head;
				t = 0;
				do {
					q = link(q);
					if (type(q) == INS_NODE
					&& subtype(q) == subtype(p))
						incr(t);
				} while (q != broken_ins(p));
				print(", #");
				print_int(t);
				print(" might split");
			}
			p = link(p);
		}
	}
}
Exemple #6
0
/**
*   Re-print report to log, aligning markers
*/
void anchors_print(summary_stat_t * totals)
{
    time_t timer;
    anchored_line_t * line;
    TCHAR * buf = malloc((g_anchors[ANCHORS_COUNT-1]+1)*sizeof(TCHAR));
    
    timer = time(NULL);
    _ftprintf(g_report_file, _T("\n==============================================================================="));
    _ftprintf(g_report_file, _T("\nCurrent time is %s"), _tasctime(localtime(&timer)));

    // Output lines from linked list
    while (NULL != (line = g_first_line))
    {
        TCHAR * p = line->line;
        if (buf && line->anchors[0])
        {
            int i=0,j,k=0; 
            for (j = 0; j < ANCHORS_COUNT; j++)
            {
                while(i < line->anchors[j] && (buf[k++] = p[i]) != 0) 
                {
                    i++;
                }
                while(k < g_anchors[j]) 
                {
                    buf[k++] = ' ';
                }
            }
            buf[k] = '\0';
            p = buf;
        }
        _fputts(p, g_report_file);
        g_first_line = g_first_line->link;
        free(line);
    }
    print_totals(totals, g_report_file);
    if(buf) free(buf);
}   
int main( int argc, char **argv)
{
/* Index default to -1 as flage for special human consideration */
int i,j,k,nrow, ncol, *sites, **site_members,nsites, nspecies,*table,index=-1,total_columns=0,column_differs=0,column_4d_differs=0,*spec_breakdown,same;
int **base_count,**bases_in_4d;
char **seq_name, **site_species, **species,*token,*spec_name,ref;

/* Needed for Webb's library functions */
argv0 = "analyze";
if ((argc != 3) && (argc != 4)  )
    print_usage();


/* Determine which species to use as reference */
if(argc == 4)
    {
    token = strtok(argv[3], "=");
    spec_name = strtok(NULL, " \n");
    }
else
    spec_name="human";

/* Read the alignment */
site_species = read_malign(argv[1], &nrow, &ncol, &seq_name);

/* Now read the 4d sites... */
site_members = read_sites(argv[2], &nspecies, &nsites, &species, &sites);

/* Make sure nspecies and nrow correspond -subtract one because of implicit human in 4d*/
if(nspecies != (nrow-1))
    fatal("Species in alignment must correspond to number of species in 4d sites");

/* Build conversion table */
table=ckalloc(nspecies * sizeof(int));

for(i=0;i<nspecies;i++)
    for(j=0;j<nrow;j++)
	if(SAME_STRING(species[i],seq_name[j]))
	    table[i]=j;


/* Build species breakdown table */
spec_breakdown=ckalloc(nspecies * sizeof(int));
	  
for(i=0;i<nspecies;i++)
    spec_breakdown[i]=0;

/* Find species */	   
if(!SAME_STRING(spec_name,"human")){
    for(i=0;i<nspecies;i++)
	if(SAME_STRING(species[i],spec_name))
	    index=i;

    if(index==-1)
	fatal("Species not found");

}


/* Build count tables */
base_count=ckalloc(ALPHA_SIZE * sizeof(int *));
for(i=0;i<ALPHA_SIZE;i++)
    base_count[i]=ckalloc((ALPHA_SIZE+1) * sizeof(int));

bases_in_4d=ckalloc(ALPHA_SIZE * sizeof(int *));
for(i=0;i<ALPHA_SIZE;i++)
    bases_in_4d[i]=ckalloc((ALPHA_SIZE+1) * sizeof(int)); 

/* Initialize base count arrays */
for(i=0;i<ALPHA_SIZE;i++)
    for(j=0;j<ALPHA_SIZE;j++)
	base_count[i][j]=(bases_in_4d[i][j]=0);

/* For each 4d site */
for(i=0;i<nsites;i++)
    {
    /* If the species is present... Special exception for human*/
    if(index==-1 || site_members[index][i])
	{
	/* Generate total bases */	
	
	total_columns++;
	same=1;
	
	if(index!=-1)
	    ref=toupper(site_species[table[index]][sites[i]]);
	else
	    ref=toupper(site_species[0][sites[i]]);
	
	/* Check for homogeneity */
	    for(j=0;j<nspecies;j++)
		{
		if(j==index)
		    continue;
		if(toupper(site_species[table[j]][sites[i]])!=ref)
		    same=0;
		}
	    if(!same)
		{
		column_differs++;
		/* Find mix of bases */
		for(j=0;j<nspecies;j++)
		    {
		    if(j==index)
			continue;
		    base_count[translate(ref)][translate(site_species[table[j]][sites[i]])]++;
		    }
		
		}
	    /* Check for homogeneity within 4d species */
	    same=1;
	    
	    for(j=0;j<nspecies;j++)
		{
		if(j==index)
		    continue;
		/* If species is present at site */
		if(site_members[j][i])
		    {
		    spec_breakdown[j]++;
		    if(toupper(site_species[table[j]][sites[i]]) != ref)
			{
			same=0;
			}
		    }
		}
	    if(!same)
		{
		column_4d_differs++;
		/* Find mix of bases */
		for(j=0;j<nspecies;j++)
		    {
		    if(j==index)
			continue;
		    if(site_members[j][i])
			bases_in_4d[translate(ref)][translate(site_species[table[j]][sites[i]])]++;
		    }
		
		}
	}
    }


printf("\n\n");
printf("Results of Bases Substitution at 4d sites.\n");
printf("------------------------------------------\n\n");

printf("Considering all species (%s as Reference)\n",spec_name);
printf("--------------------------------------------\n\n");
print_totals(total_columns, column_differs, &base_count, "Human");

printf("\nConsidering species which share the site (%s as Reference)\n",spec_name);
printf("-------------------------------------------------------------\n\n");
print_totals(total_columns, column_4d_differs, &bases_in_4d, "Human");
printf("\n");

/* Result of species breakdown */
for(i=0;i<nspecies;i++)
    {
    if(index==i)
	continue;
    printf("Species %-8s occured %5d (%2.2f %)\n",species[i],spec_breakdown[i],(float)(spec_breakdown[i] * 100)/total_columns);
    }
return 0;
}
Exemple #8
0
int main(int argc, char *argv[])
{
	int r = EXIT_OK;
	int i, ii;
	int m;
	time_t t_total;

#if defined(__EMX__)
	_response(&argc,&argv);
	_wildcard(&argc,&argv);
#endif

	if (argv[0])
		argv0 = argv[0];
	align_mem();
	(void) my_clock();

	printf("\nLZO real-time data compression library (v%s, %s).\n",
	        LZO_VERSION_STRING, LZO_VERSION_DATE);
	printf("Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer\n\n");

	if (lzo_init() != LZO_E_OK)
	{
		printf("lzo_init() failed !!!\n");
		exit(EXIT_LZO_INIT);
	}

	if (argc < 2)
		usage(argv0,-1,0);
	i = get_options(argc,argv);

	if (methods_n == 0)
		add_method(default_method);
	if (methods_n > 1 && opt_read_from_stdin)
	{
		printf("%s: cannot use multiple methods and '-@'\n", argv0);
		exit(EXIT_USAGE);
	}

	if (opt_block_size < 16)
		opt_block_size = 16;
	if (opt_block_size > MAX_BLOCK_SIZE)
		opt_block_size = MAX_BLOCK_SIZE;

	dict_len = 0;
#ifndef USE_DICT
	opt_dict = 0;
#else
	if (opt_dict)
	{
		opt_optimize_compressed_data = 0;
		if (opt_dictionary_file)
		{
			read_dict(opt_dictionary_file);
			if (opt_max_dict_len > 0 && dict_len > (lzo_uint) opt_max_dict_len)
				dict_len = opt_max_dict_len;
			if (dict_len > 0)
				printf("Using dictionary '%s', %ld bytes, ID 0x%08lx.\n",
				        opt_dictionary_file,
			            (long) dict_len, (long) dict_adler32);
		}
		if (dict_len <= 0)
		{
			init_default_dict();
			if (opt_max_dict_len > 0 && dict_len > (lzo_uint) opt_max_dict_len)
				dict_len = opt_max_dict_len;
			printf("Using default dictionary, %ld bytes, ID 0x%08lx.\n",
			        (long) dict_len, (long) dict_adler32);
		}
		if (opt_max_dict_len == -1)
			printf("Dictionary size will be adjusted to file size.\n");
		else if (opt_max_dict_len <= 0)
			printf("Dictionary size will be adjusted to file size.\n");
	}
#endif

	t_total = time(NULL);
	(void) my_clock();
	ii = i;
	for (m = 0; m < methods_n && r == EXIT_OK; m++)
	{
		int method = methods[m];

		i = ii;
		if (i >= argc && opt_calgary_corpus_path == NULL && !opt_read_from_stdin)
			usage(argv0,-1,0);
		if (m == 0 && opt_verbose >= 1)
			printf("%lu block-size\n\n", (long) opt_block_size);

		if (!info(method,NULL))
			info(method,stdout);

#ifdef USE_CORPUS
		if (opt_calgary_corpus_path != NULL)
			r = do_corpus(calgary_corpus,method,opt_calgary_corpus_path,
			              opt_c_loops,opt_d_loops);
		else
#endif
		{
			for ( ; i < argc && r == EXIT_OK; i++)
			{
				r = do_file(method,argv[i],opt_c_loops,opt_d_loops,NULL,NULL);
				if (r == EXIT_FILE)		/* ignore file errors */
					r = EXIT_OK;
			}
			if (opt_read_from_stdin)
			{
				char buf[512], *p;

				while (r == EXIT_OK && fgets(buf,sizeof(buf)-1,stdin) != NULL)
				{
					buf[sizeof(buf)-1] = 0;
					p = buf + strlen(buf);
					while (p > buf && is_space(p[-1]))
							*--p = 0;
					p = buf;
					while (*p && is_space(*p))
						p++;
					if (*p)
						r = do_file(method,p,opt_c_loops,opt_d_loops,NULL,NULL);
					if (r == EXIT_FILE)		/* ignore file errors */
						r = EXIT_OK;
				}
				opt_read_from_stdin = 0;
			}
		}
	}
	t_total = time(NULL) - t_total;

	if (opt_totals)
		print_totals();
	if (opt_execution_time || (methods_n > 1 && opt_verbose >= 1))
		printf("\n%s: execution time: %lu seconds\n", argv0, (long) t_total);
	if (r != EXIT_OK)
		printf("\n%s: exit code: %d\n", argv0, r);

	return r;
}
Exemple #9
0
void print_results(const result_presentation_t *pres, const matstat_state_t *ref_states, const matstat_state_t *int_states)
{
    static char buf[48]; /* String formatting temporary buffer, not thread safe */
    print_str("------------- BEGIN STATISTICS --------------\n");
    print_str("===== Reference timer statistics =====\n");
    print_str("Limits: mean: [");
    print_s32_dec(pres->ref_limits->mean_low);
    print_str(", ");
    print_s32_dec(pres->ref_limits->mean_high);
    print_str("], variance: [");
    print_u32_dec(pres->ref_limits->variance_low);
    print_str(", ");
    print_u32_dec(pres->ref_limits->variance_high);
    print_str("]\n");
    print_str("Target error (actual trigger time - expected trigger time), in reference timer ticks\n");
    print_str("positive: timer under test is late, negative: timer under test is early\n");

    if (DETAILED_STATS) {
        static const unsigned int count = ((LOG2_STATS) ? (TEST_LOG2NUM) : (TEST_NUM));
        unsigned k = 0;
        for (unsigned g = 0; g < pres->num_groups; ++g) {
            for (unsigned c = 0; c < pres->groups[g].num_sub_labels; ++c) {
                print_str("=== ");
                print_str(pres->groups[g].label);
                print(" ", 1);
                print_str(pres->groups[g].sub_labels[c]);
                print_str(" ===\n");
                print_detailed(&ref_states[k * count], count, pres->offsets[k], pres->ref_limits);
                ++k;
            }
        }
    }
    else {
        print_str("function              count       sum       sum_sq    min   max  mean  variance\n");
        unsigned k = 0;
        for (unsigned g = 0; g < pres->num_groups; ++g) {
            print("\n", 1);
            print(buf, fmt_lpad(buf, fmt_str(buf, pres->groups[g].label), 18, ' '));
            print(" ", 1);
            print_totals(&ref_states[k], pres->groups[g].num_sub_labels, pres->ref_limits);
            for (unsigned c = 0; c < pres->groups[g].num_sub_labels; ++c) {
                print(buf, fmt_lpad(buf, fmt_str(buf, pres->groups[g].sub_labels[c]), 18, ' '));
                print(" ", 1);
                print_statistics(&ref_states[k], pres->ref_limits);
                ++k;
            }
        }
    }
    print_str("===== introspective statistics =====\n");
    print_str("Limits: mean: [");
    print_s32_dec(pres->int_limits->mean_low);
    print_str(", ");
    print_s32_dec(pres->int_limits->mean_high);
    print_str("], variance: [");
    print_u32_dec(pres->int_limits->variance_low);
    print_str(", ");
    print_u32_dec(pres->int_limits->variance_high);
    print_str("]\n");
    print_str("self-referencing error (TUT time elapsed - expected TUT interval), in timer under test ticks\n");
    print_str("positive: timer target handling is slow, negative: TUT is dropping ticks or triggering callback early\n");
    print_str("function              count       sum       sum_sq    min   max  mean  variance\n");
    for (unsigned k = 0, g = 0; g < pres->num_groups; ++g) {
        print("\n", 1);
        print(buf, fmt_lpad(buf, fmt_str(buf, pres->groups[g].label), 18, ' '));
        print(" ", 1);
        print_totals(&int_states[k], pres->groups[g].num_sub_labels, pres->int_limits);
        for (unsigned c = 0; c < pres->groups[g].num_sub_labels; ++c) {
            print(buf, fmt_lpad(buf, fmt_str(buf, pres->groups[g].sub_labels[c]), 18, ' '));
            print(" ", 1);
            print_statistics(&int_states[k], pres->int_limits);
            ++k;
        }
    }

    print_str("-------------- END STATISTICS ---------------\n");
}
Exemple #10
0
void show_activities(void)
{
    /*tex Index into |nest|: */
    int p;
    /*tex The mode: */
    int m;
    /*tex For showing the current page: */
    halfword q, r;
    /*tex Ditto: */
    int t;
    tprint_nl("");
    print_ln();
    for (p = nest_ptr; p >= 0; p--) {
        m = nest[p].mode_field;
        tprint_nl("### ");
        print_mode(m);
        tprint(" entered at line ");
        print_int(abs(nest[p].ml_field));
        if (nest[p].ml_field < 0)
            tprint(" (\\output routine)");
        if (p == 0) {
            /*tex Show the status of the current page */
            if (page_head != page_tail) {
                tprint_nl("### current page:");
                if (output_active)
                    tprint(" (held over for next output)");
                show_box(vlink(page_head));
                if (page_contents > empty) {
                    tprint_nl("total height ");
                    print_totals();
                    tprint_nl(" goal height ");
                    print_scaled(page_goal);
                    r = vlink(page_ins_head);
                    while (r != page_ins_head) {
                        print_ln();
                        tprint_esc("insert");
                        t = subtype(r);
                        print_int(t);
                        tprint(" adds ");
                        if (count(t) == 1000)
                            t = height(r);
                        else
                            t = x_over_n(height(r), 1000) * count(t);
                        print_scaled(t);
                        if (type(r) == split_up_node) {
                            q = page_head;
                            t = 0;
                            do {
                                q = vlink(q);
                                if ((type(q) == ins_node)
                                    && (subtype(q) == subtype(r)))
                                    incr(t);
                            } while (q != broken_ins(r));
                            tprint(", #");
                            print_int(t);
                            tprint(" might split");
                        }
                        r = vlink(r);
                    }
                }
            }
            if (vlink(contrib_head) != null)
                tprint_nl("### recent contributions:");
        }
        show_box(vlink(nest[p].head_field));
        /*tex Show the auxiliary field, |a|. */
        switch (abs(m) / (max_command_cmd + 1)) {
            case 0:
                tprint_nl("prevdepth ");
                if (nest[p].prev_depth_field <= ignore_depth)
                    tprint("ignored");
                else
                    print_scaled(nest[p].prev_depth_field);
                if (nest[p].pg_field != 0) {
                    tprint(", prevgraf ");
                    print_int(nest[p].pg_field);
                    if (nest[p].pg_field != 1)
                        tprint(" lines");
                    else
                        tprint(" line");
                }
                break;
            case 1:
                tprint_nl("spacefactor ");
                print_int(nest[p].space_factor_field);
                break;
            case 2:
                if (nest[p].incompleat_noad_field != null) {
                    tprint("this will be denominator of:");
                    show_box(nest[p].incompleat_noad_field);
                }
                break;
        }
    }
}