int main(int argc, char * argv[]){
    FILE * input = stdin;

    setlocale(LC_ALL, "");

    GError * error = NULL;
    GOptionContext * context;

    context = g_option_context_new("- import k mixture model");
    g_option_context_add_main_entries(context, entries, NULL);
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
        g_print("option parsing failed:%s\n", error->message);
        exit(EINVAL);
    }

    SystemTableInfo2 system_table_info;

    bool retval = system_table_info.load(SYSTEM_TABLE_INFO);
    if (!retval) {
        fprintf(stderr, "load table.conf failed.\n");
        exit(ENOENT);
    }

    PhraseLargeTable3 phrase_table;
    phrase_table.attach(SYSTEM_PHRASE_INDEX, ATTACH_READONLY);

    FacadePhraseIndex phrase_index;

    const pinyin_table_info_t * phrase_files =
        system_table_info.get_default_tables();

    if (!load_phrase_index(phrase_files, &phrase_index))
        exit(ENOENT);

    KMixtureModelBigram bigram(K_MIXTURE_MODEL_MAGIC_NUMBER);
    bigram.attach(k_mixture_model_filename, ATTACH_READWRITE|ATTACH_CREATE);

    taglib_init();

    /* prepare to read n-gram model */
    values = g_ptr_array_new();
    required = g_hash_table_new(g_str_hash, g_str_equal);

    ssize_t result = my_getline(input);
    if ( result == -1 ) {
        fprintf(stderr, "empty file input.\n");
        exit(ENODATA);
    }

    if (!parse_headline(&bigram))
        exit(ENODATA);

    result = my_getline(input);
    if ( result != -1 )
        parse_body(input, &phrase_table, &phrase_index, &bigram);

    taglib_fini();

    return 0;
}
bool parse_body(FILE * input, PhraseLargeTable3 * phrase_table,
                FacadePhraseIndex * phrase_index,
                KMixtureModelBigram * bigram){
    taglib_push_state();

    assert(taglib_add_tag(END_LINE, "\\end", 0, "", ""));
    assert(taglib_add_tag(GRAM_1_LINE, "\\1-gram", 0, "", ""));
    assert(taglib_add_tag(GRAM_2_LINE, "\\2-gram", 0, "", ""));

    do {
    retry:
        assert(taglib_read(linebuf, line_type, values, required));
        switch(line_type) {
        case END_LINE:
            goto end;
        case GRAM_1_LINE:
            my_getline(input);
            parse_unigram(input, phrase_table, phrase_index, bigram);
            goto retry;
        case GRAM_2_LINE:
            my_getline(input);
            parse_bigram(input, phrase_table, phrase_index, bigram);
            goto retry;
        default:
            assert(false);
        }
    } while (my_getline(input) != -1) ;

 end:
    taglib_pop_state();
    return true;
}
int main(int argc, char * argv[]){
    FILE * input = stdin;
    FILE * output = stdout;

    taglib_init();

    values = g_ptr_array_new();
    required = g_hash_table_new(g_str_hash, g_str_equal);

    ssize_t result = my_getline(input);
    if ( result == -1 ) {
        fprintf(stderr, "empty file input.\n");
        exit(ENODATA);
    }

    if (!parse_headline(input, output))
        exit(ENODATA);

    result = my_getline(input);
    if ( result != -1 )
        parse_body(input, output);

    taglib_fini();

    return 0;
}
bool parse_body(FILE * input, FILE * output){
    taglib_push_state();

    assert(taglib_add_tag(END_LINE, "\\end", 0, "", ""));
    assert(taglib_add_tag(GRAM_1_LINE, "\\1-gram", 0, "", ""));
    assert(taglib_add_tag(GRAM_2_LINE, "\\2-gram", 0, "", ""));

    do {
    retry:
        assert(taglib_read(linebuf, line_type, values, required));
        switch(line_type) {
        case END_LINE:
            fprintf(output, "\\end\n");
            goto end;
        case GRAM_1_LINE:
            fprintf(output, "\\1-gram\n");
            my_getline(input);
            parse_unigram(input, output);
            goto retry;
        case GRAM_2_LINE:
            fprintf(output, "\\2-gram\n");
            my_getline(input);
            parse_bigram(input, output);
            goto retry;
        default:
            assert(false);
        }
    } while (my_getline(input) != -1);

 end:
    taglib_pop_state();
    return true;
}
Exemple #5
0
/*==*/
int ParseRatesFile(FILE *rates_FP, double **Raten, int nstates, int max)
{
  char *cp=NULL, *raten_line=NULL;
  //char *suffix = "rates.out";
  double rate, *tmp_rates=NULL;

  // valid rate file?
  if (rates_FP==NULL) {
    fprintf(stderr, "ERROR: Rate file is NULL!\n");
    exit(EXIT_FAILURE);
  }

  // actual reading:
  int my_dim = 0;
    // get length of line
  char *tmp_line = my_getline(rates_FP);
  raten_line = (char*) calloc(strlen(tmp_line)+1, sizeof(char));
  strcpy(raten_line, tmp_line);

  char *p = strtok(tmp_line, " \t\n");
  while (p && sscanf(p, "%lf", &rate)==1) {
    //fprintf(stderr, "%d-%lf-\n", my_dim, rate);
    my_dim++;
    p = strtok(NULL, " \t\n");
  }
  free(tmp_line);

  // allocate space
  tmp_rates = (double *)calloc(my_dim*my_dim,sizeof(double));
  assert(tmp_rates != NULL);

  // read!
  int i=0, j=0, read=0;
  while(raten_line != NULL && i<my_dim) {
    cp = raten_line;
    while(cp != NULL && sscanf(cp,"%lf%n", &rate,&read) == 1 && j<my_dim) {
      tmp_rates[my_dim*j+i] = rate;
      cp+=read;
      j++;
    }
    j=0;
    i++;
    free(raten_line);
    raten_line = my_getline(rates_FP);
  }

  // check dimensions:
  if (j==0) { j=my_dim-1; i--; } // if last line empty
  if (i!=my_dim-1 || j!=my_dim-1) {
    if (!opt.quiet) fprintf(stderr, "WARNING: dimensions are corrupted lines: %d(%d); rows: %d(%d)\n", j, my_dim-1, i, my_dim-1);
  }

  // shorten the matrix from dimension my_dim to nstates:
  *Raten = tmp_rates;
  my_dim = MxShorten(Raten, nstates, my_dim, max);

  fclose(rates_FP);
  return my_dim;
}
void cadastra_pessoa(pessoa* p){
    printf("Nome: ");
    my_getline(p->nome,30);
    printf("CPF: ");
    my_getline(p->cpf,20);
    printf("Idade: ");
    scanf("%d%*c",&p->idade);
}
Exemple #7
0
/********************************************************************
*  Function set_display options
*
*  Parameters none.
*
*  Prints a strings information using the more interface
*  the output is sized to the screen and is displayed with
*  row and col labels.
*
*********************************************************************/
void set_display_options(void)
{
  FILE *newfpout;

  while (1) {
    printf("\nOptions (1 - redirect output to file, 2 - reset to screen,\n");
    printf("         3 - turn stats %s, 0 - Exit)\n",
           (stats_flag ? "off" : "on"));
    printf("Enter Selection: ");

    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;
    switch (choice[0]) {
    case '0':
      return;

    case '1':
      choice[0] = '\0';
      while (choice != NULL && choice[0] == '\0') {
        printf("\nEnter file name (Ctl-D to cancel): ");
        choice = my_getline(stdin, &ch_len);
      }
      if (choice == NULL) {
        printf("\n\n");
        continue;
      }

      printf("\nRedirecting output to %s...", choice);
      if ((newfpout = fopen(choice, "w")) == NULL)
        fprintf(stderr,"\nError:  could not open file %s for output.\n\n",
                choice);
      else {
        if (fpout != stdout)
          fclose(fpout);
        fpout = newfpout;
        printf("done.\n\n");
      }
      break;

    case '2':
      if (fpout != stdout) {
        fclose(fpout);
        fpout = stdout;
      }
      putchar('\n');
      break;

    case '3':
      stats_flag = (stats_flag ? OFF : ON);
      putchar('\n');
      break;

    default:
      printf("\nThat is not a choice.\n");
    }
  }
}
Exemple #8
0
void Alphabet::readObject(ifstream &inf) 
{
	int tmp;
	::readObject(inf, tmp);
	m_isGrowthStopped = tmp == 0 ? false : true;
	::readObject(inf, m_numEntries);
	int i = 0;
	for (; i < m_numEntries; ++i) {
		string strFeat;
		my_getline(inf, strFeat);
		string strIdx;
		my_getline(inf, strIdx);
		m_map[strFeat] = atoi(strIdx.c_str());
	}
}
Exemple #9
0
int read_lines(char * plines[], int max_nlines)
{
	int nlines;
	char line[MAX_LINE_LEN];
	char line_len; /* Includes \0 character at the end */

	nlines = 0;
	while(line_len = my_getline(line, MAX_LINE_LEN))
	{
		/* line_len is when when line is empty - line will contain only \0 */
		if (line_len > 1)
		{
			if (nlines == max_nlines)
				return -1;

			plines[nlines] = (char *) malloc(sizeof(char) * line_len);
			if (plines[nlines] == NULL)
				return -1;

			strcpy(plines[nlines], line);
			++nlines;
		}
	}

	return nlines;
}
main()
{
    int i_idx, o_idx;       /* index of input and output */
    int blank_holder;       /* the position of spaces and tabs  in input */
    char line[MAXLINE];     /* current input line */
    int len;                /* length of current input line */
    
    while ((len = my_getline(line, MAXLINE)) > 0 ) {
        o_idx = blank_holder = 0;
        for (i_idx = 0; i_idx < len; i_idx++) {
            if (line[i_idx] == ' ' || line[i_idx] == '\t')
                blank_holder = i_idx;
            if (o_idx == FOLDLENGTH) {
                if (blank_holder > 0)
                    line[blank_holder] = '\n';
                o_idx = 0;
            }
            o_idx++;
        }

        printf("%s", line);
    }

    return 0;
}
Exemple #11
0
bool run_script(FILE *script)
{
    bool eof = false;
    rt = rt_make();
    unexpected_fails = 0;
    tests_performed = tests_failed = 0;
    last_expression = NULL;
    while (!eof) {
        char *line = my_getline(script, &eof);
        is_empty(line) ||
            is_comment(line) ||
            run_command(line) ||
            parse_line(line);
        mem_free(line);
    }
    mem_free(last_expression);
    mem_free(current_test_name);
    rt_free(rt);
    printf(
        "Summary:\n"
        "* %d/%d tests succeeded,\n"
        "* %d pending unexpected failures.\n",
        tests_performed - tests_failed,
        tests_performed,
        unexpected_fails);
    return true;
}
Exemple #12
0
int main(int argc, char *argv[]) {
	int total_lines = TAILDEF, n;
	char **lines, line[MAXLINE];
	int first = 0, len, i;
	
	/* Argument parsing */
	if (argc == 2 && argv[1][0] == '-' && isdigit((unsigned char) argv[1][1])) {
		n = atoi(argv[1]+1);
		if (n > 0)
			total_lines = n;
		else
			printf("Invalid numerical value, falling back to default...\n");
	}
	
	lines = calloc(total_lines, sizeof(char *));
	
	while ((len = my_getline(line, MAXLINE)) > 0) {
		if (lines[first])
			free(lines[first]);
		lines[first] = malloc(len+1);
		strcpy(lines[first], line);
		first = (first+1)%total_lines;
	}
	
	for (i = 0; i < total_lines; i++, first = (first+1)%total_lines)
		if (lines[first])
			printf("%s", lines[first]);

	return 0;
}
Exemple #13
0
int main()
{
    my_getline(now);
    char s[100];
    double r=cacul(s);
    printf("%lf\n", r);
}
Exemple #14
0
Fichier : 1-17.c Projet : DAMSAS/ex
main()
{       int len;
        len=my_getline();
        if (len>MAX)
           printf("line entered:%s",line);
        
}
Exemple #15
0
int main(int argc, char *argv[]) {
    char *line, *pattern, *module;
    char *pos1, *pos2;

    if(argc != 3) {
        fprintf(stderr, "usage: resolve-modalias <alias file> <modalias>\n");
        return 1;
    }

    FILE *f=fopen(argv[1], "r");
    if(!f) {
        perror("error opening alias file");
        return 1;
    }

    while((line=my_getline(f))!=NULL) {
        if(!strncmp(line, "alias", strlen("alias"))) {
            pos1 = index(line, ' ');
            pos2 = index(pos1+1, ' ');
            pattern = pos1+1;
            *pos2 = '\0';
            module = pos2+1;

            if(!fnmatch(pattern, argv[2], 0))
                printf("%s\n", module);
        }
    }
    return 0;
}
bool parse_unigram(FILE * input, PhraseLargeTable * phrases,
                   FacadePhraseIndex * phrase_index){
    taglib_push_state();

    assert(taglib_add_tag(GRAM_1_ITEM_LINE, "\\item", 1, "count", ""));

    do {
        assert(taglib_read(linebuf, line_type, values, required));
        switch (line_type) {
        case GRAM_1_ITEM_LINE:{
            /* handle \item in \1-gram */
            const char * string = (const char *) g_ptr_array_index(values, 0);
            phrase_token_t token = taglib_string_to_token(phrases, string);
            gpointer value = NULL;
            assert(g_hash_table_lookup_extended(required, "count", NULL, &value));
            glong count = atol((const char *)value);
            phrase_index->add_unigram_frequency(token, count);
            break;
        }
        case END_LINE:
        case GRAM_1_LINE:
        case GRAM_2_LINE:
            goto end;
        default:
            assert(false);
        }
    } while (my_getline(input) != -1);

 end:
    taglib_pop_state();
    return true;
}
Exemple #17
0
int main() {
	int len;
	char line[MAXLINE];
	while ((len = my_getline(line, MAXLINE)) > 0)
		if (len > LINETHRES)
			printf("%s", line);
	return 0;
}
Exemple #18
0
int main(int argc, char const *argv[])
{
	char original[MAX_LINE];
	char entabbed[MAX_LINE];
	int len;
	int c, spaces_in_a_row, real_spaces;
	int i, j;
	while ((len = my_getline(original, MAX_LINE)) > 0)
	{
		spaces_in_a_row = real_spaces = j = 0;
		for (i = 0; i < len; ++i)
		{
			c = original[i];

			if (c == SPACE_SYMBOL)
			{
				++real_spaces;
				++spaces_in_a_row;

				if ((real_spaces % MAX_TAB_STOP) == 0) /* is a tab stop */
				{
					entabbed[j++] = TAB_SYMBOL;
					spaces_in_a_row = 0;
				}
			}
			else if (c == TAB_SYMBOL)
			{
				real_spaces += (MAX_TAB_STOP - spaces_in_a_row);

				entabbed[j++] = TAB_SYMBOL;
				spaces_in_a_row = 0;
			}
			else /* is a character */
			{
				++real_spaces;

				/* fill in the white spaces */
				while (spaces_in_a_row > 0)
				{
					entabbed[j++] = SPACE_SYMBOL;
					--spaces_in_a_row;
				}

				entabbed[j++] = original[i];
			}
		}
		entabbed[j] = '\0';
		
		printf("Original: %s\n", original);
		printf("Entabbed: %s\n", entabbed);

		/* reset strings */
		entabbed[0] = '\0';
		original[0] = '\0';
	}
	
	return 0;
}
Exemple #19
0
/**********************************************************************
 *  Function main()                                              
 *                                                                   
 *  Parameter:                                                       
 * 
 *  This is the main function.  It allocates space for the initial data
 *  structures and displays the main menu. You can choose an algorithm
 *  sub-menu, or the String Utilities Menu.
 *                                                                   
 **********************************************************************/
int main(void)
{
  /*
   * Initialize the array of sequences.
   */
  create_seq_array();

  /*
   * The main loop.
   */
  while (1) {
    printf("\n**          Main Menu        **\n");
    printf("\n");
    printf("1)  Basic Search Algorithms\n");
    printf("2)  Z-value Algorithms\n");
    printf("3)  Suffix Tree Algorithms\n");
    printf("4)  Suffix Array Algorithms\n");
    printf("5)  Repeat Algorithms\n");
    printf("*)  String Utilities\n");
    printf("0)  Exit Program\n");
    printf("\nEnter Selection: ");

    while ((choice = my_getline(stdin, &ch_len)) == NULL) ;
    switch (choice[0]) {
    case '0':
      return 0;

    case '1':
      basic_alg_menu(); 
      break;

    case '2':
      z_alg_menu();
      break;

    case '3':
      suf_tree_menu();
      break;
      
    case '4':
      suf_ary_menu();
      break;

    case '5':
      repeats_menu();
      break;

    case '*':
      util_menu();
      break;

    default:
      printf("\nThat is not a choice.\n");
      break;
    }
  }
} /* main() */
Exemple #20
0
void get_next_family(int item_num, int *pcur_fam_cutoff, 
		     char **pcur_fam_name)
{
  do {
    my_getline(fam_rec, 80, fam_fp) ;
    *pcur_fam_cutoff = atoi(fam_rec) ;
  } while (item_num > *pcur_fam_cutoff) ;
  *pcur_fam_name = strchr(fam_rec, ' ')+1 ;
}
Exemple #21
0
/**
 * Draw basic blocks graphicaly
 * This function does same as print_blocks but, produces DOT based 
 * output file.
 * @see print_blocks()
 */
void draw_blocks()
{
   FILE *outp;
   int i;
   struct block *b = first_block;
   
   outp = fopen("basic-block.dot", "w+");
   if(outp == NULL) {
      fprintf(stderr, "Cannot open output file to draw basic blocks!\n");
      exit(EXIT_FAILURE);
   }
   
   fprintf(outp, "/* output from optimizer over mesi 3 address code */\n");
   fprintf(outp, "digraph \"Basic Blocks\" { \n");
   fprintf(outp, "\tnode[/*style=filled, color=gray92,*/ shape=box];\n");
   
   while(b) {
      fprintf(outp, "\t%d[shape=record,label=\"{%s| gen: ", b->index, b->id);
      
      for(i = 0; i < b->defin.geni; i++)
	 fprintf(outp, "%s(%d) ", b->defin.genp[i]->var, b->defin.genl[i]);
      
      fprintf(outp, "| kill: ");
      
      for(i = 0; i < b->defin.killi; i++)
	 fprintf(outp, "%s(%d) ", b->defin.killp[i]->var, b->defin.killl[i]);
      
      fprintf(outp, "| in: ");
      
      for(i = 0; i < b->defin.ini; i++)
	 fprintf(outp, "%s(%d) ", b->defin.inp[i]->var, b->defin.inl[i]);
      
      fprintf(outp, "| ");
      
      for(i = b->begin; i <= (b->end == LINE_END ? linenum - 1: b->end); i++)
	 fprintf(outp, "%d: %s \\l", i, my_getline(i));
      
      fprintf(outp, "| out: ");
      
      for(i = 0; i < b->defin.outi; i++)
	 fprintf(outp, "%s(%d) ", b->defin.outp[i]->var, b->defin.outl[i]);
      
      fprintf(outp, "}\"];\n");
      
      if(b->to != BLOCK_NONE)
	 fprintf(outp, "\t%d->%d;\n", b->index, b->to);
      
      if(b->to2 != BLOCK_NONE)
	 fprintf(outp, "\t%d->%d;\n", b->index, b->to2);
      
      b = b->next;
   }

   fprintf(outp, "}\n");
   fclose(outp);
}
Exemple #22
0
int main()
{
  char buf[10];
  my_fputs(my_fgets(buf, 10, stdin), stdout);
  
  my_getline(buf, 10);
  printf("%s", buf);
  
  return 0;
}
/* print lines longer than MINCHAR */
main()
{
    int len; /* current line length */
    char line[MAXLINE]; /* current input line */

    while ((len = my_getline(line, MAXLINE)) > 0)
        if (len > MINCHAR)
            printf("%s", line);
    return 0;
}
Exemple #24
0
/* find all lines matching pattern */
int main(void)
{
    char line[MAXLINE];
    int found = 0;
    while (my_getline(line, MAXLINE) > 0)
        if (strindex(line, pattern) >= 0) {
            printf("%s", line);
            found++;
        }
    return found;
}
Exemple #25
0
Fichier : ex1_19.c Projet : yufw/kr
int main()
{
    char line[MAXLINE];
    int len;
    
    while ((len=my_getline(line, MAXLINE)) > 0) {
        reverse(line, len);
        printf("%s", line);
    }
    return 0;
}
Exemple #26
0
int main(int argc, char **argv)
{
  size_t m = 0;
  size_t n = TABSTOP_DEFAULT;
  while (--argc > 0)
  {
    ++argv;
    if (**argv == '-' && sscanf(*argv + 1, "%zu", &m) != 1)
    {
      fprintf(stderr, "detab: illegal option -%s\n", *argv);
      return EXIT_FAILURE;
    }
    if (**argv == '+' && sscanf(*argv + 1, "%zu", &n) != 1)
    {
      fprintf(stderr, "detab: illegal option %s\n", *argv);
      return EXIT_FAILURE;
    }
  }

  char line[MAXLINE];
  size_t len;

  while ((len = my_getline(line, MAXLINE)) > 0)
  {
    bool first_tabstop = true;
    size_t col = 0;
    for (size_t i = 0; i < len; ++i)
    {
      if (line[i] == '\t')
      {
        size_t tabstop;
        if (*argv || sscanf(*argv++, "%zu", &tabstop) != 1)
        {
          tabstop = n;
        }
        if (first_tabstop)
        {
          tabstop += m;
          first_tabstop = false;
        }
        for (size_t rem = tabstop - ((col - m) % tabstop); rem > 0; --rem)
        {
          ++col;
          putchar(' ');
        }
      }
      else
      {
        ++col;
        putchar(line[i]);
      }
    }
  }
}
int main() 
{
    int len;
    char line[MAXLINE];

    while ((len = my_getline(line, MAXLINE)) > 0) {
        printf("origin: %s", line);
        my_reverse(line);
        printf("%s", line);
    }
    return 0;
}
int main(int argc, char* argv[]) {
  const int BUFSIZE = 1024;

  char buf[BUFSIZE];
  char line[BUFSIZE];
  while (my_getline(line, BUFSIZE) > 0) {
    expand(line, buf);
    printf("After expand: %s\n", buf);
  }

  return 0;
}
Exemple #29
0
Fichier : grep.c Projet : ccooder/C
int main(int argc, char const* argv[])
{
    char s[MAXLINE];
    char t[] = "ould";
    int len, found;
    found = 0;
    while ((len = my_getline(s, MAXLINE)) > 0)
        if (rstrindex(s, t) != -1) {
            printf("%s\n", s);
            ++found;
        }
    return 0;
}
int main(int argc, char* argv[])
{
    const int MAXLINE = 1024;
    
    int len = 0;
    char line[MAXLINE];
    while ((len = my_getline(line, MAXLINE)) > 0) {
        reverse(line, len - 1);	
        printf("%s", line);
    }

    return 0;
}