예제 #1
0
//FIXME: n_max_chars is not handled the same way as in GNU findutils.
//FIXME: quoting is not implemented.
static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg UNUSED_PARAM, char *buf)
{
	int i;
	char *end, *p;

	/* Free strings from last invocation, if any */
	for (i = 0; G.args && G.args[i]; i++)
		if (G.args[i] != G.argv[i])
			free(G.args[i]);

	end = buf + n_max_chars;
	p = buf;

	while (1) {
		int c = getchar();
		if (c == EOF || c == G.eol_ch) {
			if (p == buf)
				goto ret; /* empty line */
			c = '\0';
		}
		*p++ = c;
		if (c == '\0') {   /* EOL or EOF detected */
			i = 0;
			while (G.argv[i]) {
				char *arg = G.argv[i];
				int count = count_strstr(arg, G.repl_str);
				if (count != 0)
					arg = xmalloc_substitute_string(arg, count, G.repl_str, buf);
				store_param(arg);
				dbg_msg("args[]:'%s'", arg);
				i++;
			}
			p = buf;
			goto ret;
		}
		if (p == end) {
			goto ret;
		}
	}
 ret:
	*p = '\0';
	/* store_param(NULL) - caller will do it */
	dbg_msg("return:'%s'", buf);
	return buf;
}
예제 #2
0
파일: contains.c 프로젝트: loiluu/smc
/*
Build GF for strstr(S, pattern) = position
 */
void count_strstr(CONFIGURE *conf, MLINK lp, char* pattern, int position, bounds* results){
   if (position < 0){
      // printf("%d %s\n", position, pattern);
      count_contains(conf, lp, pattern, results);      
      return;
   }
   int n = strlen(pattern), i, j;
   int ctable[n];
   compute_correlation_table(pattern, ctable, n);
   
   bounds F0;
   char* E;
   count_not_contains(conf, lp, pattern, &F0);
   get_coef(conf, lp, F0.upperBound, position, &E);
   
   for (i = 1; i < n; i++){
      if (i > position) break;
      if (ctable[i] == 1){
            bounds fi;
            char* tmp;
            count_strstr(conf, lp, pattern, position-i, &fi);
            get_coef(conf, lp, fi.upperBound, n+position-i, &tmp);
            char* tmp2 = malloc(strlen(tmp) + strlen(E) + 5);
            sprintf(tmp2, "%s - %s", E, tmp);
            send_to_mathematica(lp, tmp2, &E);
            
            free(tmp);
            free(tmp2);
         }
   }
   char* query =  malloc(strlen(E) + 30);
   sprintf(query, "(%s)X^%d*X^%d/(1-%dX)", E, position, n, conf->alphabet_size);
   char* sresult;
   send_to_mathematica(lp, query, &sresult);
   
   if (DEBUG)
      printf("Result = %s\n", sresult);
   copy_bounds_concrete(sresult, sresult, results);

   free(query);
   free(sresult);
   free(E);
}