Ejemplo n.º 1
0
static COUNTS *
chrcount(char *path)
{
    char temp[1024];
    char leaf[1024];
    size_t used = 0;
    size_t need = 2;
    COUNTS *result = typeCalloc(need, COUNTS);

    if (isdirectory(path)) {
	FILE *pp = popen("ls -1 -a", "r");
	if (pp != 0) {
	    while (fgets(leaf, sizeof(leaf), pp) != 0) {
		trim(leaf);
		sprintf(temp, "%s/%s", path, leaf);
		if ((used + 1) >= need) {
		    need = (used + 1) * 2;
		    result = realloc(result, sizeof(COUNTS) * need);
		}
		if ((result[used].count = do_count(temp)) >= 0) {
		    result[used].name = strmalloc(leaf);
		    used++;
		    result[used].name = 0;
		}
	    }
	    pclose(pp);
	}
    } else {
	result[0].name = strmalloc(path);
	result[0].count = do_count(path);
    }
    return result;
}
Ejemplo n.º 2
0
void
headers(void)
{
	struct file_list *fl;

	for (fl = ftab; fl != 0; fl = fl->f_next)
		if (fl->f_needs != 0)
			do_count(fl->f_needs, fl->f_needs, 1);
}
Ejemplo n.º 3
0
/*
15.6.2.2531 [ELSE]
“bracket-else”
TOOLS EXT
Compilation: Perform the execution semantics given below.
Execution: ( “hspacesiname ...” -- )
Skipping leading spaces, parse and discard space-delimited words from the parse area,
including nested occurrences of [IF] ...
[THEN] and [IF] ...
[ELSE] ...
[THEN], until the word [THEN] has been parsed and discarded. If the parse area be-
comes exhausted, it is refilled as with REFILL. [ELSE] is an immediate word.
See: 3.4.1 Parsing, A.15.6.2.2531 [ELSE].
15.6.2.2532 [IF]
“bracket-if”
TOOLS EXT
*/
static void do_bracket_else(void)
{
/*

: [else]
	1 ( initialize [if]/[else]/[then] nesting level)
	begin
	bl word count dup 
	0= ( refill input buffer) if drop drop refill 0= if ( refill failed) drop ( drop nesting level) ." error: input exhausted" cr exit then [ over ] ( continue loop) again then
	0 if 2dup ." found word: " type cr then
	2dup s" [if]" compare 0= if ( increase nesting level) rot 1+ rot rot then
	2dup s" [else]" compare 0= if ( special-case for the nesting level) rot dup 1 = if 1- then rot rot then
	s" [then]" compare 0= if ( decrease nesting level) 1- then
	dup 0= until
	drop ; immediate

: [if] 0= if postpone [else] then ; immediate

: [then] ; immediate
*/
	/* initialize [if]/[else]/[then] nesting level */
	sf_push(1);
	do
	{
		do_bl(); do_word(); do_count();
		if (!sf_top())
		{
			/* input exhausted, refill input buffer */
			do_drop(); do_drop(); do_refill();
			if (!sf_pop()) { /* 'refill' failed */ /* drop nesting level */ do_drop(); print_str(__func__);
				print_str("(): input exhausted; aborting\n"); do_abort(); }
			continue;
		}

		do_two_to_r();

		do_two_r_fetch();
		//sf_push((cell) "\04[if]"); do_count(); sf_push((cell) compare_word_xt); do_execute();
		if (sf_pop() == 4) { if (!xmemcmp((void *) sf_pop(), "[if]", 4)) /* increase nesting level */ do_one_plus(); }
		else do_drop();

		do_two_r_fetch();
		//sf_push((cell) "\06[else]"); do_count(); sf_push((cell) compare_word_xt); do_execute();
		if (sf_pop() == 6) { if (!xmemcmp((void *) sf_pop(), "[else]", 6)) /* see if an [if] block should be terminated */ if (sf_top() == 1) do_one_minus(); }
		else do_drop();

		do_two_r_from();
		//sf_push((cell) "\06[then]"); do_count(); sf_push((cell) compare_word_xt); do_execute();
		if (sf_pop() == 6) { if (!xmemcmp((void *) sf_pop(), "[then]", 6)) /* decrease nesting level */ do_one_minus(); }
		else do_drop();
	}
	while (sf_top());
	/* drop nesting level */
	do_drop();

}
Ejemplo n.º 4
0
/*
 * count all the devices of a certain type and recurse to count
 * whatever the device is connected to
 */
void
do_count(const char *dev, const char *hname, int search)
{
	struct device *dp, *mp;
	int count;

	for (count = 0,dp = dtab; dp != 0; dp = dp->d_next)
		if (dp->d_unit != -1 && eq(dp->d_name, dev)) {
			/*
			 * Avoid making .h files for bus types on sun machines
			 */
			if ((machine == MACHINE_SUN2 ||
			     machine == MACHINE_SUN3 ||
			     machine == MACHINE_SUN4)
			    && dp->d_conn == TO_NEXUS){
				return;
			}
			if (dp->d_type == PSEUDO_DEVICE) {
				count =
				    dp->d_slave != UNKNOWN ? dp->d_slave : 1;
				if (dp->d_flags)
					dev = NULL;
				break;
			}
                        if (machine != MACHINE_SUN2 && machine != MACHINE_SUN3
			    && machine != MACHINE_SUN4)
				/* avoid ie0,ie0,ie1 setting NIE to 3 */
			count++;
			/*
			 * Allow holes in unit numbering,
			 * assumption is unit numbering starts
			 * at zero.
			 */
			if (dp->d_unit + 1 > count)
				count = dp->d_unit + 1;
			if (search) {
				mp = dp->d_conn;
                                if (mp != 0 && mp != TO_NEXUS &&
				    mp->d_conn != TO_NEXUS) {
                                        /*
					 * Check for the case of the
					 * controller that the device
					 * is attached to is in a separate
					 * file (e.g. "sd" and "sc").
					 * In this case, do NOT define
					 * the number of controllers
					 * in the hname .h file.
					 */
					if (!file_needed(mp->d_name))
					    do_count(mp->d_name, hname, 0);
					search = 0;
				}
			}
		}
	do_header(dev, hname, count);
}
Ejemplo n.º 5
0
void do_counter_measurement(void)
{
 extern u16 convert_acceleration_value_to_mgrav(u8 value);
 u8 i;
 u16 accel_data, sum1;
 // Get data from sensor
 bmp_as_get_data(sCounter.xyz);
 for ( i = 0, sum1 = 0; i < 3; i ++ ) {
  accel_data = convert_acceleration_value_to_mgrav(sCounter.xyz[i]);
  // Filter acceleration
#if 0
  accel_data = (u16)((accel_data * 0.2) + (sCounter.data[i] * 0.8));
#endif
  accel_data = (u16)((accel_data * 0.1) + (sCounter.data[i] * 0.9));
  sum1 += accel_data;
  // Store average acceleration
  sCounter.data[i] = accel_data;
 }
 if ( sCounter.sum == 0 ) {
     sCounter.low = sum1;
     sCounter.high = sum1;
 } else {
    switch ( sCounter.rise_state) { // init state
    case 0:
        if ( sum1 > sCounter.sum ) {
            sCounter.rise_state = 1;
            sCounter.low = sCounter.sum;
        } else {
            sCounter.rise_state = 2;
            sCounter.high = sCounter.sum;
        }
        break;
    case 1:
    if ( sum1 < sCounter.sum ) { // change direction
       sCounter.high = sCounter.sum;
       sCounter.rise_state = 2;
    }
    break;
    case 2:
        if ( sum1 > sCounter.sum ) {
           sCounter.low = sCounter.sum;
           sCounter.rise_state = 1;
              do_count();
        }
        break;
    }
    }
 sCounter.sum = sum1;
 // Set display update flag
// display.flag.update_counter = 1;
}
Ejemplo n.º 6
0
/** 
 * Returns the number of ways the sentence can be parsed with the
 * specified null count. Assumes that the hash table has already been
 * initialized, and is freed later. The "null_count" here is the
 * number of words that are allowed to have no links to them.
 */
s64 do_parse(Sentence sent, int null_count, Parse_Options opts)
{
	s64 total;
	count_context_t *ctxt = sent->count_ctxt;

	count_set_effective_distance(sent);
	ctxt->current_resources = opts->resources;
	ctxt->local_sent = sent->word;
	ctxt->deletable = sent->deletable;
	ctxt->null_block = opts->null_block;
	ctxt->islands_ok = opts->islands_ok;

	total = do_count(sent, -1, sent->length, NULL, NULL, null_count+1);

	ctxt->local_sent = NULL;
	ctxt->current_resources = NULL;
	return total;
}
Ejemplo n.º 7
0
/* 拷贝函数 */
void my_copy(FILE **fp1, FILE **fp2)
{
	int ret = -1; 
	int n;
	char buf[N] = {0};

	while(ret != 0)
	{
//		printid();
	
		n = do_count();

		fseek(*fp1, n, 0);
		fseek(*fp2, n, 0);

		memset(buf, 0, sizeof(buf));
		ret = fread(buf, 1, N, *fp1);
		fwrite(buf, ret, 1, *fp2);
	}

	return;
}
Ejemplo n.º 8
0
int do_my_wc(int argc, char **argv)
{
    FILE * fs = NULL;
    int myerno = 0;
    char filepath[NAMELEN] = {'\0'};
    char para[NAMELEN] = {'\0'};
    int cmd = 0; //-l -w -c 
    int i = 0;
    //默认统计的是三个参数的个数
    if(1 >= argc){
_USAGE:
        printf("Usage : %s  [%s|%s|%s] <file-name>\n", argv[0], LINE,WORD,CHAR);
        return NG;
    }
    memset(filepath, '\0', NAMELEN);
    
    for(i = 1; i < argc; ++i){
       if('-' == argv[i][0]){
           if(!strcmp(LINE, argv[i])){
               cmd += FORL;
           }else if(!strcmp(WORD, argv[i])){
               cmd += FORW;
           }else if(!strcmp(CHAR, argv[i])){
               cmd += FORC;
           }else{
	       goto _USAGE;
	   }
       }
    }
    if(0 == cmd){
        cmd = 7;
    }
    for(i = 1; i < argc; ++i){
        if('-' != argv[i][0]){
            do_count(argv[i], cmd);
	}
    }
    return OK; 
}
Ejemplo n.º 9
0
int main(void) {
    size_t cmd_buf_sz = 20;
    char buf[cmd_buf_sz];
    jokedb_struct jokedb;

    // load with default jokes (array of joke_struct's)
    load_default_jokes(&jokedb);

    // send INITMSG
    send(INITMSG, cgc_strlen(INITMSG));
    
    // send MENU
    do_menu();
    
    while (1) {
        // send ROOTPROMPT
        cgc_memset(buf, '\0', cmd_buf_sz);
        prompt_user(ROOTPROMPT, buf, cmd_buf_sz);

        // receive user input and check for COMMAND
        if (streq(buf, "LIST") == 0) {
            do_list(&jokedb);
        } else if (streq(buf, "ADD") == 0) {
            do_add(&jokedb);
        } else if (streq(buf, "COUNT") == 0) {
            do_count(&jokedb);
        } else if (streq(buf, "SHOW") == 0) {
            do_show(&jokedb);
        } else if (streq(buf, "HELP") == 0) {
            do_help();
        } else if (streq(buf, "QUIT") == 0) {
            do_quit();
        } else {
            do_menu();
        }
    }
}
Ejemplo n.º 10
0
/**
 * Returns the number of ways the sentence can be parsed with the
 * specified null count. Assumes that the fast-matcher and the count
 * context have already been initialized, and will be freed later. The
 * "null_count" argument is the number of words that are allowed to
 * have no links to them.
 *
 * This the full-fledged parser, but it only 'counts', in order to
 * avoid an explosion of allocated memory structures to hold each
 * possible parse.  Thus, to see an 'actual' parse, a second pass
 * must be made, with build_parse_set(), to get actual parse structures.
 *
 * The work is split up this way for two reasons:
 * 1) A given sentence may have thousands of parses, and the user is
 *    interested in only a few.
 * 2) A given sentence may have billions of parses, in which case,
 *    allocating for each would blow out RAM.
 * So, basically, its good to know how many parses to expect, before
 * starting to allocate parse structures.
 *
 * The count returned here is meant to be completely accurate; it is
 * not an approximation!
 *
 * Currently, the code has been designed to maintain a histogram of
 * the cost of each of the parses. The number and width of the bins
 * is adjustable in histogram.c. At this time, the histogram is not
 * used anywhere, and a 3-5% speedup is available if it is avoided.
 * We plan to use this historgram, later ....
 */
Count_bin do_parse(Sentence sent,
                   fast_matcher_t *mchxt,
                   count_context_t *ctxt,
                   int null_count, Parse_Options opts)
{
	Count_bin hist;

	ctxt->current_resources = opts->resources;
	ctxt->exhausted = false;
	ctxt->checktimer = 0;
	ctxt->local_sent = sent->word;

	/* consecutive blocks of this many words are considered as
	 * one null link. */
	/* ctxt->null_block = 1; */
	ctxt->islands_ok = opts->islands_ok;

	hist = do_count(mchxt, ctxt, -1, sent->length, NULL, NULL, null_count+1);

	ctxt->local_sent = NULL;
	ctxt->current_resources = NULL;
	ctxt->checktimer = 0;
	return hist;
}
Ejemplo n.º 11
0
/** 
 * Returns the number of ways the sentence can be parsed with the
 * specified cost. Assumes that the hash table has already been
 * initialized, and is freed later. The "cost" here is the number
 * of words that are allowed to have no links to them.
 */
s64 do_parse(Sentence sent, int cost, Parse_Options opts)
{
	s64 total;
	count_context_t *ctxt = sent->count_ctxt;

	count_set_effective_distance(sent);
	ctxt->current_resources = opts->resources;
	ctxt->local_sent = sent->word;
	ctxt->deletable = sent->deletable;
	ctxt->null_block = opts->null_block;
	ctxt->islands_ok = opts->islands_ok;

	total = do_count(sent, -1, sent->length, NULL, NULL, cost+1);
	if (verbosity > 1) {
		printf("Total count with %d null links:   %lld\n", cost, total);
	}
	if ((verbosity > 0) && (PARSE_NUM_OVERFLOW < total)) {
		printf("WARNING: Overflow in count! cnt=%lld\n", total);
	}

	ctxt->local_sent = NULL;
	ctxt->current_resources = NULL;
	return total;
}
Ejemplo n.º 12
0
/* Fm-Index Search MAIN */
int main(int argc, char *argv[]) {

	char * program_name = argv[0];
	char * filename, * extfilename = NULL;
	void *index;
	uchar * pattern;
	ulong nchars, position = 0;
	int unbuild, count, locate, extract, display, error;

	nchars = 10;	
	count = locate = extract = unbuild = display = 0;
	
	int next_option;
	const char* short_options = "hlce:s:d:n:";
	const struct option long_options[] = {
		{"help" , 		0,	NULL, 	'h'},
		{"locate",		0,	NULL,	'l'},
		{"count",		0,	NULL,	'c'},
		{"extract",		1,	NULL,	'e'},
		{"display",		1,	NULL,	's'},
		{"unbuild",		1,	NULL,	'd'},
		{"numchars",	1,	NULL,	'n'},
		{NULL,			0,	NULL,	0}
	 };
 
 	if(argc<3) print_usage(program_name);
	
		do { 
		next_option = getopt_long(argc, argv, short_options,
								  long_options, NULL);
		
		switch (next_option) {
			    
			case 'l': /* report position */
         		locate = 1; 
				break;
			
			case 's': /* display len chars sourronding each occ */
         		display = 1;
			    nchars = (ulong) atol(optarg); 
				break;
			
			case 'd': /* unbuild */
         		unbuild = 1;
			    extfilename = (char *) optarg;
				break;
			
	  		case 'e': /* extract */
		 		extract = 1;
				position = (ulong) atol(optarg); 
    	 		break;
			
			case 'c': /* count */
		 		count = 1;
    	 		break;
			
	  		case 'n': /* numchars for extract function */
				extract = 1;
		 		nchars = (ulong) atol(optarg); 
	  	 		break;

			case '?': /* The user specified an invalid option. */
        		fprintf(stderr,"Unknown option.\n");
        		print_usage(program_name);
				break;	
			
			case -1: /* Done with options. */
				break;
			
			default: 
				print_usage(program_name);
    	}
	}
	while (next_option != -1);
	
	if (optind == argc)  {	
		  	fprintf(stderr,"You must supply a pattern and a .fmi filename\n\n");
			print_usage(program_name);
     		exit(1);
    }
	
	/* priorita' extract display locate count */
	if(!(extract || unbuild)) /* pattern */ 
		pattern = (uchar *) argv[optind++];
	else pattern = NULL;
		
	if (optind == argc)  {	
		  	fprintf(stderr,"You must supply a pattern and a .fmi filename\n\n");
			print_usage(program_name);
     		exit(1);
    }
			
	filename = argv[optind];
	
	error = load_index (filename, &index);
	IFERROR (error);

	if (unbuild==1) 
		do_unbuild(index, extfilename);
	if (extract==1) 
		do_extract(index, position, nchars);
	if (display==1) 
		do_display(index, pattern, nchars);
	if (locate==1) 
		do_locate(index, pattern);
	
	do_count(index, pattern);
	exit(0);
}	
Ejemplo n.º 13
0
static Count_bin do_count(fast_matcher_t *mchxt,
                          count_context_t *ctxt,
                          int lw, int rw,
                          Connector *le, Connector *re,
                          int null_count)
{
	Count_bin zero = hist_zero();
	Count_bin total;
	int start_word, end_word, w;
	Table_connector *t;

	assert (0 <= null_count, "Bad null count");

	t = find_table_pointer(ctxt, lw, rw, le, re, null_count);

	if (t) return t->count;

	/* Create the table entry with a tentative null count of 0.
	 * This count must be updated before we return. */
	t = table_store(ctxt, lw, rw, le, re, null_count);

	if (rw == 1+lw)
	{
		/* lw and rw are neighboring words */
		/* You can't have a linkage here with null_count > 0 */
		if ((le == NULL) && (re == NULL) && (null_count == 0))
		{
			t->count = hist_one();
		}
		else
		{
			t->count = zero;
		}
		return t->count;
	}

	/* The left and right connectors are null, but the two words are
	 * NOT next to each-other. */
	if ((le == NULL) && (re == NULL))
	{
		if (!ctxt->islands_ok && (lw != -1))
		{
			/* If we don't allow islands (a set of words linked together
			 * but separate from the rest of the sentence) then the
			 * null_count of skipping n words is just n. */
			if (null_count == (rw-lw-1))
			{
				t->count = hist_one();
			}
			else
			{
				t->count = zero;
			}
			return t->count;
		}
		if (null_count == 0)
		{
			/* There is no solution without nulls in this case. There is
			 * a slight efficiency hack to separate this null_count==0
			 * case out, but not necessary for correctness */
			t->count = zero;
		}
		else
		{
			t->count = zero;
			Disjunct * d;
			int w = lw + 1;
			for (d = ctxt->local_sent[w].d; d != NULL; d = d->next)
			{
				if (d->left == NULL)
				{
					hist_accumv(&t->count, d->cost,
						do_count(mchxt, ctxt, w, rw, d->right, NULL, null_count-1));
				}
			}
			hist_accumv(&t->count, 0.0,
				do_count(mchxt, ctxt, w, rw, NULL, NULL, null_count-1));
		}
		return t->count;
	}

	if (le == NULL)
	{
		start_word = lw+1;
	}
	else
	{
		start_word = le->word;
	}

	if (re == NULL)
	{
		end_word = rw;
	}
	else
	{
		end_word = re->word +1;
	}

	total = zero;

	for (w = start_word; w < end_word; w++)
	{
		Match_node *m, *m1;
		m1 = m = form_match_list(mchxt, w, le, lw, re, rw);
		for (; m != NULL; m = m->next)
		{
			unsigned int lnull_cnt, rnull_cnt;
			Disjunct * d = m->d;
			/* _p1 avoids a gcc warning about unsafe loop opt */
			unsigned int null_count_p1 = null_count + 1;

			for (lnull_cnt = 0; lnull_cnt < null_count_p1; lnull_cnt++)
			{
				bool Lmatch, Rmatch;
				bool leftpcount = false;
				bool rightpcount = false;
				bool pseudototal = false;

				rnull_cnt = null_count - lnull_cnt;
				/* Now lnull_cnt and rnull_cnt are the costs we're assigning
				 * to those parts respectively */

				/* Now, we determine if (based on table only) we can see that
				   the current range is not parsable. */
				Lmatch = (le != NULL) && (d->left != NULL) &&
				         do_match(le, d->left, lw, w);
				Rmatch = (d->right != NULL) && (re != NULL) &&
				         do_match(d->right, re, w, rw);

				/* First, perform pseudocounting as an optimization. If
				 * the pseudocount is zero, then we know that the true
				 * count will be zero, and so skip counting entirely,
				 * in that case.
				 */
				if (Lmatch)
				{
					leftpcount = pseudocount(ctxt, lw, w, le->next, d->left->next, lnull_cnt);
					if (!leftpcount && le->multi)
						leftpcount =
							pseudocount(ctxt, lw, w, le, d->left->next, lnull_cnt);
					if (!leftpcount && d->left->multi)
						leftpcount =
							pseudocount(ctxt, lw, w, le->next, d->left, lnull_cnt);
					if (!leftpcount && le->multi && d->left->multi)
						leftpcount =
							pseudocount(ctxt, lw, w, le, d->left, lnull_cnt);
				}

				if (Rmatch)
				{
					rightpcount = pseudocount(ctxt, w, rw, d->right->next, re->next, rnull_cnt);
					if (!rightpcount && d->right->multi)
						rightpcount =
							pseudocount(ctxt, w,rw, d->right, re->next, rnull_cnt);
					if (!rightpcount && re->multi)
						rightpcount =
							pseudocount(ctxt, w, rw, d->right->next, re, rnull_cnt);
					if (!rightpcount && d->right->multi && re->multi)
						rightpcount =
							pseudocount(ctxt, w, rw, d->right, re, rnull_cnt);
				}

				/* Total number where links are used on both sides */
				pseudototal = leftpcount && rightpcount;

				if (!pseudototal && leftpcount) {
					/* Evaluate using the left match, but not the right. */
					pseudototal =
						pseudocount(ctxt, w, rw, d->right, re, rnull_cnt);
				}
				if (!pseudototal && (le == NULL) && rightpcount) {
					/* Evaluate using the right match, but not the left. */
					pseudototal =
						pseudocount(ctxt, lw, w, le, d->left, lnull_cnt);
				}

				/* If pseudototal is zero (false), that implies that
				 * we know that the true total is zero. So we don't
				 * bother counting at all, in that case. */
				if (pseudototal)
				{
					Count_bin leftcount = zero;
					Count_bin rightcount = zero;
					if (Lmatch) {
						leftcount = do_count(mchxt, ctxt, lw, w, le->next, d->left->next, lnull_cnt);
						if (le->multi)
							hist_accumv(&leftcount, d->cost,
								do_count(mchxt, ctxt, lw, w, le, d->left->next, lnull_cnt));
						if (d->left->multi)
							hist_accumv(&leftcount, d->cost,
								 do_count(mchxt, ctxt, lw, w, le->next, d->left, lnull_cnt));
						if (le->multi && d->left->multi)
							hist_accumv(&leftcount, d->cost,
								do_count(mchxt, ctxt, lw, w, le, d->left, lnull_cnt));
					}

					if (Rmatch) {
						rightcount = do_count(mchxt, ctxt, w, rw, d->right->next, re->next, rnull_cnt);
						if (d->right->multi)
							hist_accumv(&rightcount, d->cost,
								do_count(mchxt, ctxt, w, rw, d->right,re->next, rnull_cnt));
						if (re->multi)
							hist_accumv(&rightcount, d->cost,
								do_count(mchxt, ctxt, w, rw, d->right->next, re, rnull_cnt));
						if (d->right->multi && re->multi)
							hist_accumv(&rightcount, d->cost,
								do_count(mchxt, ctxt, w, rw, d->right, re, rnull_cnt));
					}

					/* Total number where links are used on both sides */
					hist_muladd(&total, &leftcount, 0.0, &rightcount);

					if (0 < hist_total(&leftcount))
					{
						/* Evaluate using the left match, but not the right */
						hist_muladdv(&total, &leftcount, d->cost,
							do_count(mchxt, ctxt, w, rw, d->right, re, rnull_cnt));
					}
					if ((le == NULL) && (0 < hist_total(&rightcount)))
					{
						/* Evaluate using the right match, but not the left */
						hist_muladdv(&total, &rightcount, d->cost,
							do_count(mchxt, ctxt, lw, w, le, d->left, lnull_cnt));
					}

					/* Sigh. Overflows can and do occur, esp for the ANY language. */
					if (INT_MAX < hist_total(&total))
					{
#ifdef PERFORM_COUNT_HISTOGRAMMING
						total.total = INT_MAX;
#else
						total = INT_MAX;
#endif /* PERFORM_COUNT_HISTOGRAMMING */
						t->count = total;
						put_match_list(mchxt, m1);
						return total;
					}
				}
			}
		}
		put_match_list(mchxt, m1);
	}
	t->count = total;
	return total;
}
Ejemplo n.º 14
0
static int h_del_timer_sync (struct kprobe *p, struct pt_regs *regs)
{
    return do_count (&count_del_timer_sync, "del_timer_sync");
}
Ejemplo n.º 15
0
static int h_mod_timer (struct kprobe *p, struct pt_regs *regs)
{
    return do_count (&count_mod_timer, "mod_timer");
}
Ejemplo n.º 16
0
int main(int argc, char *argv[])
{
    char *fname = NULL;
    /* operation flags */
    int is_breakevents = 0;
    int is_count = 0;
    int is_maxmin = 0;
    int is_average = 0;
    int is_digest = 0;
    int is_exp_ratio = 0;
    int is_exp = 0;
    uint64_t start_time = 0;
    uint64_t time_scale = 0;
    uint64_t end_time = 0;

    struct option  long_options [] = {
        /* short options are listed correspondingly */
        { "version", 0, NULL, 'v' },
        { "help", 0, NULL, 'h' },
        /* list Cx entires one by one */
        { "digest", 0, NULL, 'd' },
        /* ignored when digest is disabled */
        { "start", 1, NULL, 's' },
        { "end", 1, NULL, 'e' },
        { "scale", 1, NULL, 'l' },
        /* give summary about breakevents info */
        { "breakevents", 0, NULL, 'b' },
        { "count", 0, NULL, 'c' },
        { "average", 0, NULL, 'a' },
        /* list max/min residency for each Cx */
        { "maxmin", 0, NULL, 'm' },
        { "tsc2us", 1, NULL, 'u' },
        { "px", 0, NULL, 'p' },
        { "tsc2phase", 1, NULL, 'n' },
        { "exp-ratio", 0, NULL, 'z' },
        { "exp-pred", 0, NULL, 'x' },
        { NULL, 0, NULL, 0 },
    };

    while (1) {
        int ch, opt_idx;
        ch = getopt_long(argc, argv, "vhds:e:l:bcmaupnzx",
                         long_options, &opt_idx);
        if (ch == -1)
            break;
        switch (ch) {
        case 'v':
            show_version();
            exit(EXIT_SUCCESS);
        case 'h':
            show_help();
            exit(EXIT_SUCCESS);
        case 'p':
            is_px = 1;
            break;
        case 'x':
            is_exp = 1;
            break;
        case 'z':
            is_exp_ratio = 1;
            break;
        case 'n':
            tsc2phase = atoll(optarg);
            if (tsc2phase <= 0)
                tsc2phase = 55800000UL;
        case 'd':
            is_digest = 1;
            break;
        case 's':
            start_time = atoll(optarg);
            break;
        case 'e':
            end_time = atoll(optarg);
            break;
        case 'l':
            time_scale = atoll(optarg);
            break;
        case 'b':
            is_breakevents = 1;
            break;
        case 'c':
            is_count = 1;
            break;
        case 'm':
            is_maxmin = 1;
            break;
        case 'a':
            is_average = 1;
            break;
        case 'u':
            tsc2us = atoll(optarg);
            tsc2ms = tsc2us * 1000UL;
            break;
        case '?':
        default:
            show_help();
            exit(EXIT_FAILURE);
        }
    }

    if (argc - optind > 1) {
        printf("Multiple file specified?\n");
        show_help();
        exit(EXIT_FAILURE);
    }
    fname = argv[optind];

    if (load_file(fname))
        exit(EXIT_FAILURE);

    width = 10;
    if (is_digest) {
        /* if people not specify the time related number,
         * use the default one from the record.
         */
        if (!start_time)
            start_time = data[0].tsc;
        if (!end_time)
            end_time = data[data_cur-1].tsc;
        if (!time_scale)
            time_scale = 10UL * tsc2ms;	/* default: 10 ms */
        do_digest(start_time, end_time, time_scale);
    }

    if (is_breakevents)
        do_breakevents();

    if (is_count && !is_px)
        do_count();
    if (is_count && is_px)
        do_px_count();

    if (is_maxmin)
        do_maxmin();

    if (is_average)
        do_average();

    if (is_exp_ratio)
        do_exp_ratio();

    if (is_exp)
        do_exp_pred();

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 17
0
/*
 *	The function "mon()" is the dialog user interface, called
 *	from the simulation just after program start.
 */
void mon(void)
{
	register int eoj = 1;
	static char cmd[LENCMD];

	tcgetattr(0, &old_term);

	if (x_flag) {
		if (do_getfile(xfn) == 0)
			do_go();
	}
	while (eoj) {
		next:
		printf(">>> ");
		fflush(stdout);
		if (fgets(cmd, LENCMD, stdin) == NULL) {
			putchar('\n');
			goto next;
		}
		switch (*cmd) {
		case '\n':
			do_step();
			break;
		case 't':
			do_trace(cmd + 1);
			break;
		case 'g':
			do_go();
			break;
		case 'd':
			do_dump(cmd + 1);
			break;
		case 'l':
			do_list(cmd + 1);
			break;
		case 'm':
			do_modify(cmd +	1);
			break;
		case 'f':
			do_fill(cmd + 1);
			break;
		case 'v':
			do_move(cmd + 1);
			break;
		case 'x':
			do_reg(cmd + 1);
			break;
		case 'p':
			do_port(cmd + 1);
			break;
		case 'b':
			do_break(cmd + 1);
			break;
		case 'h':
			do_hist(cmd + 1);
			break;
		case 'z':
			do_count(cmd + 1);
			break;
		case 'c':
			do_clock();
			break;
		case 's':
			do_show();
			break;
		case '?':
			do_help();
			break;
		case 'r':
			do_getfile(cmd + 1);
			break;
		case '!':
			do_unix(cmd + 1);
			break;
		case 'q':
			eoj = 0;
			break;
		default:
			puts("what??");
			break;
		}
	}
}
Ejemplo n.º 18
0
static s64 do_count(Sentence sent, int lw, int rw,
                    Connector *le, Connector *re, int cost)
{
	Disjunct * d;
	s64 total, pseudototal;
	int start_word, end_word, w;
	s64 leftcount, rightcount;
	int lcost, rcost, Lmatch, Rmatch;

	Match_node * m, *m1;
	Table_connector *t;

	count_context_t *ctxt = sent->count_ctxt;

	if (cost < 0) return 0;  /* will we ever call it with cost<0 ? */

	t = find_table_pointer(ctxt, lw, rw, le, re, cost);

	if (t == NULL) {
		/* Create the table entry with a tentative cost of 0. 
	    * This cost must be updated before we return. */
		t = table_store(ctxt, lw, rw, le, re, cost, 0);
	} else {
		return t->count;
	}

	if (rw == 1+lw)
	{
		/* lw and rw are neighboring words */
		/* You can't have a linkage here with cost > 0 */
		if ((le == NULL) && (re == NULL) && (cost == 0))
		{
			t->count = 1;
		}
		else
		{
			t->count = 0;
		}
		return t->count;
	}

	if ((le == NULL) && (re == NULL))
	{
		if (!ctxt->islands_ok && (lw != -1))
		{
			/* If we don't allow islands (a set of words linked together
			 * but separate from the rest of the sentence) then the cost
			 * of skipping n words is just n */
			if (cost == ((rw-lw-1) + ctxt->null_block-1)/ctxt->null_block)
			{
				/* If null_block=4 then the cost of
				   1,2,3,4 nulls is 1; and 5,6,7,8 is 2 etc. */
				t->count = 1;
			}
			else
			{
				t->count = 0;
			}
			return t->count;
		}
		if (cost == 0)
		{
			/* There is no zero-cost solution in this case. There is
			 * a slight efficiency hack to separate this cost=0 case
			 * out, but not necessary for correctness */
			t->count = 0;
		}
		else
		{
			total = 0;
			w = lw+1;
			for (d = ctxt->local_sent[w].d; d != NULL; d = d->next)
			{
				if (d->left == NULL)
				{
					total += do_count(sent, w, rw, d->right, NULL, cost-1);
				}
			}
			total += do_count(sent, w, rw, NULL, NULL, cost-1);
			t->count = total;
		}
		return t->count;
	}

	if (le == NULL)
	{
		start_word = lw+1;
	}
	else
	{
		start_word = le->word;
	}

	if (re == NULL)
	{
		end_word = rw-1;
	}
	else
	{
		end_word = re->word;
	}

	total = 0;

	for (w = start_word; w < end_word+1; w++)
	{
		m1 = m = form_match_list(sent, w, le, lw, re, rw);
		for (; m!=NULL; m=m->next)
		{
			d = m->d;
			for (lcost = 0; lcost <= cost; lcost++)
			{
				rcost = cost-lcost;
				/* Now lcost and rcost are the costs we're assigning
				 * to those parts respectively */

				/* Now, we determine if (based on table only) we can see that
				   the current range is not parsable. */
				Lmatch = (le != NULL) && (d->left != NULL) && 
				         do_match(sent, le, d->left, lw, w);
				Rmatch = (d->right != NULL) && (re != NULL) && 
				         do_match(sent, d->right, re, w, rw);

				rightcount = leftcount = 0;
				if (Lmatch)
				{
					leftcount = pseudocount(sent, lw, w, le->next, d->left->next, lcost);
					if (le->multi) leftcount += pseudocount(sent, lw, w, le, d->left->next, lcost);
					if (d->left->multi) leftcount += pseudocount(sent, lw, w, le->next, d->left, lcost);
					if (le->multi && d->left->multi) leftcount += pseudocount(sent, lw, w, le, d->left, lcost);
				}

				if (Rmatch)
				{
					rightcount = pseudocount(sent, w, rw, d->right->next, re->next, rcost);
					if (d->right->multi) rightcount += pseudocount(sent, w,rw,d->right,re->next, rcost);
					if (re->multi) rightcount += pseudocount(sent, w, rw, d->right->next, re, rcost);
					if (d->right->multi && re->multi) rightcount += pseudocount(sent, w, rw, d->right, re, rcost);
				}

				/* total number where links are used on both sides */
				pseudototal = leftcount*rightcount;

				if (leftcount > 0) {
					/* evaluate using the left match, but not the right */
					pseudototal += leftcount * pseudocount(sent, w, rw, d->right, re, rcost);
				}
				if ((le == NULL) && (rightcount > 0)) {
					/* evaluate using the right match, but not the left */
					pseudototal += rightcount * pseudocount(sent, lw, w, le, d->left, lcost);
				}

				/* now pseudototal is 0 implies that we know that the true total is 0 */
				if (pseudototal != 0) {
					rightcount = leftcount = 0;
					if (Lmatch) {
						leftcount = do_count(sent, lw, w, le->next, d->left->next, lcost);
						if (le->multi) leftcount += do_count(sent, lw, w, le, d->left->next, lcost);
						if (d->left->multi) leftcount += do_count(sent, lw, w, le->next, d->left, lcost);
						if (le->multi && d->left->multi) leftcount += do_count(sent, lw, w, le, d->left, lcost);
					}

					if (Rmatch) {
						rightcount = do_count(sent, w, rw, d->right->next, re->next, rcost);
						if (d->right->multi) rightcount += do_count(sent, w,rw,d->right,re->next, rcost);
						if (re->multi) rightcount += do_count(sent, w, rw, d->right->next, re, rcost);
						if (d->right->multi && re->multi) rightcount += do_count(sent, w, rw, d->right, re, rcost);
					}

					total += leftcount*rightcount;  /* total number where links are used on both sides */

					if (leftcount > 0) {
						/* evaluate using the left match, but not the right */
						total += leftcount * do_count(sent, w, rw, d->right, re, rcost);
					}
					if ((le == NULL) && (rightcount > 0)) {
						/* evaluate using the right match, but not the left */
						total += rightcount * do_count(sent, lw, w, le, d->left, lcost);
					}
				}
			}
		}

		put_match_list(sent, m1);
	}
	t->count = total;
	return total;
}