Exemplo n.º 1
0
int    my_options(t_options *option, char **av, int ac, char **env)
{
  int	i;
  int	j;

  i = 1;
  init_option(option);
  option->home = my_getpwd(env);
  while (i < ac)
    {
      j = 1;
      if (av[i][0] == '.')
	return (i);
      while (av[i][j] != '\0')
        {
          if (av[i][0] != '-')
	    return (i);
          my_check_option(av[i][j], option);
          ++j;
        }
      if (j == 1)
	my_error_report(4);
      ++i;
    }
  return (-1);
}
Exemplo n.º 2
0
int main(int argc, char **argv){
	int _counter = 0;
	int len = 0;
	FILE *IN;
	int is_open = 0;
	struct option options;
	init_option(&options);
	get_options(&options,1,argc,argv);
	if((options.count == 0)&&(options.ratio == 0)){
		options.ratio = 1;
	}
	if(strlen(options.file) > 0){
		if((IN = fopen(options.file,"r")) == NULL){
			perror(options.file);
			exit(1);
		}
		is_open = 1;
	}else{
		IN = stdin;
	}
	len = counter(IN,&_counter);
	if(options.count == 1){printf("%d/%d\n",_counter,len);}
	if(options.ratio == 1){printf("%f\n",(float)_counter * options.dom / len);}
	if(is_open == 1){
		fclose(IN);
	}
	/*
	printf("count:%d:\n",options.count);
	printf("ratio:%d:\n",options.ratio);
	printf("dom:%d:\n",options.dom);
	printf("file:%s:\n",options.file);
	*/
	return(0);
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
	init_option(&m_dict_option, argc, argv);

	convert_dict(&m_dict_option);

	return 0;
}
Exemplo n.º 4
0
int main(int argc, char **argv){
	struct option opt;
	FILE *IN;
	char *str;
	char cc;
	int len = 0;
	/* (* option setting */
	init_option(&opt);
	get_option(argc-1, argv+1, &opt);
	if(opt.help == 1){
		help();
	}
	if(opt.check == 1){
		print_option(opt);
	}
	if((opt.help == 1)||(opt.check == 1)||(strlen(opt.file) < 1)){
		exit(0);
	}
	/* *) */
	/* (* allocation */
	if((str = malloc(sizeof(char) * opt.total_size)) == NULL){
		fprintf(stderr,"failed: malloc() -- exit.\n");
		exit(1);
	}
	/* *) */
	IN = fopen(opt.file,"r");
	if(opt.fasta == 1){
		cc = getc(IN);
		if(cc == '>'){
			while((cc = getc(IN)) != '\n'){
			}
		}else{
			fprintf(stderr,"not FASTA format.\n");
			*(str+len) = cc;
			len++;
		}
	}
	if(opt.space == 0){
		while((cc = getc(IN)) != EOF){
			if((cc != '\n')&&(cc != ' ')&&(cc != '\t')){
				*(str+len) = cc;
				len++;
			}
		}
	}else if(opt.space == 1){
		while((cc = getc(IN)) != EOF){
				*(str+len) = cc;
				len++;
		}
	}
	fclose(IN);
	if(opt.header == 0){
		print_frg(opt.segment_size, opt.gap_size, opt.offset, str);
	}else if(opt.header == 1){
		print_frg_h(opt.segment_size, opt.gap_size, opt.offset, str, opt.head, opt.count_start, opt.format);
	}
	return(0);
}
Exemplo n.º 5
0
void		option(GtkWidget *but, gpointer data)
{
  t_wid		*wid;

  wid = (t_wid *)(data);
  if (wid->option->open == 0)
    {
      init_option(wid);
      gtk_widget_show(wid->option->win);
      wid->option->open = 1;
    }
}
Exemplo n.º 6
0
void		check_arg(int argc, char **argv) {
  t_option	option;
  int		i;
  
  init_option(&option);
  i = 0;
  while (i < argc) {
    if (argv[i][0] == '-') {
      if (!check_opt(argv[i], &option)) {
	my_putstr("Usage: my_ls [-lR1rdtaAL] [dir1 [...]]\n");
	return ;
      }
    }
    i++;
  }
  check_files(argc, argv, &option);
}
Exemplo n.º 7
0
Arquivo: uniq.c Projeto: lufb/code
int
main(int argc, char *argv[])
{
    int                 c;

    static struct option const long_options[] =
    {
        {"help", 0, NULL, 'h'},
        {"count", 0, NULL, 'c'},
        {"repeated", 0, NULL, 'd'},
        {"skip-fields", 1, NULL, 'f'},
        {"ignore-case", 0, NULL, 'i'},
        {"skip-chars", 1, NULL, 's'},
        {"separater", 1, NULL, 'p'},
        {NULL, 0, NULL, 0}
    };
    init_option(&g_option);
    exit_status = EXIT_SUCESS;
    program_name = argv[0];
    while((c = getopt_long(argc, argv,
                           "hHcdf:is:p:", long_options, NULL)) != -1)
    {
        switch(c)
        {
            case 'h':
            case 'H':
                uniq_usage_exit(EXIT_SUCESS);
                break;
            case 'c':
                g_option.c = 1;
                break;
            case 'd':
                g_option.d = 1;
                break;
            case 'f':
                if(optarg)
                    fill_f(optarg);
                break;
            case 'i':
                g_option.i = 1;
                break;
            case 's':
                if(optarg)
                    fill_s(optarg);
                break;
            case 'p':
                if(optarg)
                    fill_p(optarg);
                break;
            default:
                uniq_usage_exit(EXIT_FAILURE);
                break;
        }
    }

    if(argc - optind != 1)
        uniq_usage_exit(EXIT_FAILURE);

    adjust_option();
    if(uniq(argv[optind]) != 0)
        exit_status = EXIT_FAILURE;

    exit(exit_status);
}
Exemplo n.º 8
0
int main(int argc, char **argv){

	/* (* vars */
	struct option opt;
	FILE *IFP = NULL;
	int ie = 0;
	int c = 0;
	int i = 0;
	int j = 0;
	int k = 0;
	int x = 0;
	int line_start = -1;
	int num_lines = 0;
	int num_columns = 0;
	char *line = NULL;
	int line_ptr = 0;
	char *term = NULL;
	float *vec = NULL;
	//double sum = 0;
	int IN_FS = 0;
	float ftmp = 0;
	/* *) */

	/* (* option analysis */
	init_option(&opt);
	get_option(argc-1,argv+1,&opt);
	if(argc < 2){
		opt.print_help = 1;
		ie++;
	}
	if(opt.print_help == 1){
		print_help();
		ie++;
	}
	if(opt.check_opt == 1){
		print_option(opt);
		ie++;
	}
	if(ie > 0){
		exit(0);
	}
	/* *) */

	/* (* allocation */
	vec = calloc(opt.column_size,sizeof(float));
	if(vec == NULL){
		fprintf(stderr,"[ERROR] failed : calloc for vec.\n");
		exit(1);
	}
	line = calloc(opt.line_length,sizeof(char));
	if(line == NULL){
		fprintf(stderr,"[ERROR] failed : calloc for line.\n");
		exit(1);
	}
	term = calloc(opt.term_length,sizeof(char));
	if(term == NULL){
		fprintf(stderr,"[ERROR] failed : calloc for term.\n");
		exit(1);
	}
	/* *) */

	/* (* read file and print result */
	if((IFP = fopen(opt.input_file_name,"r")) == NULL){
		perror(opt.input_file_name);
		exit(1);
	}

	/* skip lines */
	while(num_lines < opt.rskip){
		while((c = fgetc(IFP)) != LF){
			//printf("%c",c);
		}
		//printf("%c",LF);
		num_lines++;
	}

	/* read lines */
	while((c = fgetc(IFP)) != EOF){
		if(c == LF){
			num_columns = 0;
			line_start = 0;
			//sum = 0;
			line[line_ptr] = '\0';

			/* Del last space */
			while(line[line_ptr-1] == FS){
				line[line_ptr-1] = '\0';
				line_ptr--;
			}

			/* Del multi space */
			x = 0;
			IN_FS = 0;
			for(i=0;i<line_ptr;i++){
				if((line[i] == FS)&&(IN_FS > 0)){
					IN_FS++;
				}else if((line[i] == FS)&&(IN_FS == 0)){
					IN_FS++;
					line[x] = line[i];
					x++;
				}else if((line[i] != FS)&&(IN_FS > 0)){
					IN_FS = 0;
					line[x] = line[i];
					x++;
				}else if((line[i] != FS)&&(IN_FS == 0)){
					line[x] = line[i];
					x++;
				}
			}
			line[x] = '\0';
			line_ptr = x;

			/* skip columns */
			while(num_columns < opt.cskip){
				//printf("%c",line[line_start]);
				if(line[line_start] == FS){
					num_columns++;
				}
				line_start++;
			}

			j = 0;
			k = 0;
			for(i=line_start;i<line_ptr;i++){
				if(line[i] == FS){
					term[j] = '\0';
					sscanf(term,"%f",&ftmp);
					vec[k] = vec[k] + ftmp;
					k++;
					j = 0;
					ftmp = 0;
				}else{
					term[j] = line[i];
					j++;
				}
			}
			term[j] = '\0';
			sscanf(term,"%f",&ftmp);
			vec[k] = vec[k] + ftmp;
			k++;
			j = 0;

			line_ptr = 0;
			num_lines++;

			/*
			for(x=0;x<k;x++){
				printf("%f ",vec[x]);
			}
			printf("\n");
			*/

		}
		else {
			line[line_ptr] = c;
			line_ptr++;
		}
	}

	fclose(IFP);
	/* *) */

	/* (* print result */
	for(x=0;x<k;x++){
		printf("%f ",vec[x]);
	}
	printf("\n");
	/* *) */

	/* (* exit main */
	return(0);
	/* *) */

}
Exemplo n.º 9
0
int main(int argc, char **argv){
	/* (* declaration */
	FILE *IN;
	struct option opt;
	int file_open = 0;
	char c;
	int count_position = 0;
	int count_char = 0;
	int count_word = 0;
	//int i = 0;
	/* *) */
	/* (* option operations */
	init_option(&opt);
	get_option(argc-1,argv+1,&opt);
	if(opt.help == 1){
		print_help();
	}
	if(opt.check == 1){
		print_option(opt);
	}
	if((opt.help == 1)||(opt.check == 1)){
		exit(0);
	}
	/* *) */
	/* (* test */
	/* *) */
	/* (* file open */
	if(strlen(opt.input_file_name) > 0){
		if((IN = fopen(opt.input_file_name,"r")) == NULL){
			perror(opt.input_file_name);
			exit(1);
		}else{
			file_open = 1;
		}
	}else{
		IN = stdin;
	}
	/* *) */
	/* (* read file */
	if(opt.input_with_head == 0){
		if((c = getc(IN)) == '>'){
			fprintf(stderr,"[W]annotation line found.\n");
			count_position++;
			if((opt.ALL_char == 1)||(opt.exact_ALL_char == 1)){
				printf("%c",c);
			}
		}
	}else{
		while((c = getc(IN)) != '>');
		while((c = getc(IN)) != '\n');
	}
	if(opt.alph_only == 1){
		if(opt.start > 0){
			if(opt.output_with_head == 1){
				printf(">");
				printf(opt.output_head,count_word);
				printf("\n");
			}
			while(opt.start > count_position){
				c = getc(IN);
				if(((65<=(int)c)&&((int)c<=90))||((97<=(int)c)&&((int)c<=122))){
					count_position++;
					printf("%c",c);
				}
			}
			printf("\n");
			count_word++;
		}
		if(opt.output_with_head == 1){
			printf(">");
			printf(opt.output_head,count_word);
			printf("\n");
		}
		while((c = getc(IN)) != EOF){
			if(((65<=(int)c)&&((int)c<=90))||((97<=(int)c)&&((int)c<=122))){
				if(count_char == opt.size){
					count_word++;
					printf("\n");
					if(opt.output_with_head == 1){
						printf(">");
						printf(opt.output_head,count_word);
						printf("\n");
					}
					count_char = 0;
				}
				printf("%c",c);
				count_char++;
			}
		}
		printf("\n");
	}else if(opt.ALL_char == 1){
		if(opt.start > 0){
			if(opt.output_with_head == 1){
				printf(">");
				printf(opt.output_head,count_word);
				printf("\n");
			}
			while(opt.start > count_position){
				c = getc(IN);
				if((c==IGNORE_CHAR[1])&&(c==IGNORE_CHAR[2])&&(IGNORE_CHAR[3])){
					count_position++;
					printf("%c",c);
				}
			}
			printf("\n");
			count_word++;
		}
		if(opt.output_with_head == 1){
			printf(">");
			printf(opt.output_head,count_word);
			printf("\n");
		}
		while((c = getc(IN)) != EOF){
			if((c==IGNORE_CHAR[1])&&(c==IGNORE_CHAR[2])&&(IGNORE_CHAR[3])){
				if(count_char == opt.size){
					count_word++;
					printf("\n");
					if(opt.output_with_head == 1){
						printf(">");
						printf(opt.output_head,count_word);
						printf("\n");
					}
					count_char = 0;
				}
				printf("%c",c);
				count_char++;
			}
		}
		printf("\n");
	}else if(opt.exact_ALL_char == 1){
		if(opt.start > 0){
			if(opt.output_with_head == 1){
				printf(">");
				printf(opt.output_head,count_word);
				printf("\n");
			}
			while(opt.start > count_position){
				c = getc(IN);
				//if((c==IGNORE_CHAR[1])&&(c==IGNORE_CHAR[2])&&(IGNORE_CHAR[3])){
					count_position++;
					printf("%c",c);
				//}
			}
			printf("\n");
			count_word++;
		}
		if(opt.output_with_head == 1){
			printf(">");
			printf(opt.output_head,count_word);
			printf("\n");
		}
		while((c = getc(IN)) != EOF){
			//if((c==IGNORE_CHAR[1])&&(c==IGNORE_CHAR[2])&&(IGNORE_CHAR[3])){
				if(count_char == opt.size){
					count_word++;
					printf("\n");
					if(opt.output_with_head == 1){
						printf(">");
						printf(opt.output_head,count_word);
						printf("\n");
					}
					count_char = 0;
				}
				printf("%c",c);
				count_char++;
			//}
		}
		printf("\n");
	}
	/* *) */
	/* (* file close */
	if(file_open == 1){
		fclose(IN);
	}
	/* *) */
	return(0);
}
Exemplo n.º 10
0
//main
int main(int argc, char **argv){
	struct option *opt;
	FILE *IN;
	int is_open = 0;
	int c = 0;
	int in_BRK = 0;

	//option analysis
	opt = alloc_option();
	init_option(opt);
	get_option(opt, argc-1, argv+1);

	//put status
	if((*opt).stat == 1){
		stat();
		exit(1);
	}

	//put help
	if((*opt).help == 1){
		help();
		exit(0);
	}

	//open file
	if(strlen((*opt).fname) == 0){
		IN = stdin;
		is_open = 0;
	}else{
		if((IN = fopen((*opt).fname,"r")) == NULL){
			perror((*opt).fname);
			exit(1);
		}
	}

	//read from file
	while((c=fgetc(IN)) != EOF){
		if(c == BRK_S){
			in_BRK++;
		}
		if(c == BRK_E){
			in_BRK--;
		}
		//printf("%d",in_BRK);
		if(c == split_DLM){
			if(in_BRK == 0){
				putchar(out_DLM);
			}else{
				putchar(c);
			}
		}else{
				putchar(c);
		}
	}
	
	//close file
	if(is_open == 1){
		fclose(IN);
	}

	//return
	return(0);
}
Exemplo n.º 11
0
int main(int argc, char **argv){
	/* vars */
	FILE *IN = NULL;
	struct option opt;
	int i = 0;
	int c = 0;
	int lines = 0;
	int max_fs = 0;
	int min_fs = 0;
	int count_fs = 0;
	int ie = 0;
	int is_open = 0;

	/* init/get options */
	init_option(&opt);
	get_option(argc-1,argv+1,&opt);

	/* check args */
	if(opt.help > 0){
		help();
		ie++;
	}
	if(ie > 0){
		exit(0);
	}
	if(opt.check > 0){
		print_option(opt);
		ie++;
	}
	if(ie > 0){
		exit(0);
	}

	/* open file */
	if((strlen(opt.input_file) > 0)&&(opt.help == 0)&&(opt.check == 0)){
		if((IN = fopen(opt.input_file,"r")) == NULL){
			perror(opt.input_file);
			exit(1);
		}
		is_open++;
	}else{
		IN = stdin;
	}

	/* skip */
	for(i=0;i<opt.lskip;i++){
		while((c = fgetc(IN)) != opt.linefeed);
	}
	/* first read */
	while((c = fgetc(IN)) != opt.linefeed){
		if(c == opt.fsep){
			count_fs++;
		}
	}
	max_fs = count_fs;
	min_fs = count_fs;
	count_fs = 0;
	lines++;
	/* long raed */
	while((c = fgetc(IN)) != EOF){
		if(c == opt.linefeed){
			max_fs = max(max_fs,count_fs);
			min_fs = min(min_fs,count_fs);
			count_fs = 0;
			lines++;
		}else if(c == opt.fsep){
			count_fs++;
		}
	}

	/* close file */
	if(is_open > 0){
		fclose(IN);
	}

	/* report */
	printf("LINES:%d:\n",lines);
	printf("MAX:%d:\n",max_fs);
	printf("MIN:%d:\n",min_fs);

	/* exit */
	return(0);
}
Exemplo n.º 12
0
int
main (int argc, char **argv)
{
	int ret;

	sky_pref_t* pref = get_skyeye_pref();
	assert(pref != NULL);	
	/* initialization of options from command line */
	ret = init_option(argc, argv, pref);
	/* set the current preference for skyeye */
	//update_skyeye_pref(pref);
	/* return non-zero represent not run skyeye */
	if(ret != 0)
		exit(0);
	else
		SIM_init();
	/* Do anything you want to do , or just deadloop here. */
	while(1)
	;
#if 0
	if(ret < 0)
		goto exit_skyeye;

	/* set some environment for running */
	init_env();

	/* initialization of all the data structure of simulation */
	if((ret = init ()) < 0)
		goto exit_skyeye;
#endif

#if 0
	/* load elf file when running elf image */
	if (exec_file) {
		if (tea_load_exec (exec_file, 0)) {
			fprintf (stderr, "load \"%s\" error\n", exec_file);
			goto exit_skyeye;
		}
#if !defined(__MINGW32__)
		/* get its symbol to debug */
		init_symbol_table(exec_file);
#endif
	}
#endif
	/* set the start address for pc */
#if 0
	if (skyeye_config.start_address != 0){
		unsigned long addr = (skyeye_config.start_address & load_mask)|load_base;
		arch_instance->set_pc (addr);
		printf ("start addr is set to 0x%08x by exec file.\n",
                        (unsigned int) addr);

	}
#endif
	/* never return */
	//SIM_start();
	//fflush(stdout);
    
#if 0
	/* running simulaion */ 
	if (remote_debugmode == 0)
		sim_resume (0);
	else{	
		printf ("remote_debugmode= %d, filename = %s, server TCP port is 12345\n",
			remote_debugmode, skyeye_config_filename);
		sim_debug ();
	}
#endif
exit_skyeye:
	return ret;
}