// Load gene list from file.
int loadgene(vector<Case>& tlst, vector<Case>& blst, const string& n, const string& b)
{
	// Genes in the cluster: label = 1.
	ifstream hGen(n.data());
	if(!hGen)
	{
		cerr << "Can't open " << n << endl;
		return 1;
	}

	while(hGen.good())
	{
		string strLn;
		getline(hGen, strLn);
		if(strLn == "")
			continue;
		istringstream strmLn(strLn);
		string gene;
		strmLn >> gene;
		str2upper(gene);
		Case c;
		c.name = gene;
		c.label = 1;
		tlst.push_back(c);
	}
	hGen.close();

	// Genes in the background: label = 0.
	ifstream hBkg(b.data());
	if(!hBkg)
	{
		cerr << "Can't open " << b << endl;
		return 1;
	}

	while(hBkg.good())
	{
		string strLn;
		getline(hBkg, strLn);
		if(strLn == "")
			continue;
		istringstream strmLn(strLn);
		string gene;
		strmLn >> gene;
		str2upper(gene);
		Case c;
		c.name = gene;
		c.label = 0;
		blst.push_back(c);
	}
	hBkg.close();

	return 0;
}
// Load one motif's binding.
int loadone(GBMap& onebind, const string& motif, const set<string>& genset, const string& folder)
{
	string fBind = folder + "/" + motif + ".func";
	ifstream hBind(fBind.data());
	if(!hBind)
	{
		cerr << "Can't open " << fBind << endl;
		return 1;
	}
	while(hBind.good())
	{
		string strLn;
		getline(hBind, strLn);
		if(strLn == "")
			continue;
		istringstream gStrm(strLn);
		string gene;
		int nb;
		gStrm >> gene >> nb;
		str2upper(gene);
		if(genset.find(gene) == genset.end())
			continue;
		VGB vgb;
		for(int j = 0; j < nb; j++)
		{
			string site;
			gStrm >> site;
			vgb.e.push_back(extrbnd(site));
		}
		onebind.e[gene] = vgb;
	}
	return 0;
}
예제 #3
0
void enter_one_name(Game* game, short color) {
	char name[MAX_NAME];
	char line[MAX_LINE];
	
	/* While the user is not satisfied with the name */
	do {
		/* Label for asking the black player */
		ask_name:
		
		/* Asking for the name of the black player */
		printf("\nEnter the name of the %s player (maximumof %d characters - letters and digits only): ", (color==BLACK?"BLACK":"WHITE"), MAX_NAME-1);
		
		/* Retrieving the name in the name string */
		fgets(name, MAX_NAME, stdin);
		
		/* Ungetting the last character readed if the string entered is too long */
		ungetc(name[strlen(name)-1], stdin);
		
		/* Emptying the buffer (so that extra characters won't be used for the next name */
		empty_buffer();
		
		/* If the last character of the name is a new line (that fgets can put into a string), replacing it with a string terminating character */
		if(name[strlen(name)-1] == NL)
			name[strlen(name)-1] = '\0';
		
		/* If the name conatins other characters than letters and numbers, asking again */
		if(!contains_only_letters(name))
			goto ask_name;
			
		/* While the answer is not Yes of No, asking if the name suits the player */
		do {
			printf("\n%s, is that the name you want? (Y/N) : ", name);
			fgets(line, MAX_LINE, stdin);
			str2upper(line);
		}	 
		while(line[ZERO] != 'Y' && line[ZERO] != 'N');
	}
	while(line[ZERO] == 'N');
	
	/* If the name entered for the white player is the same as the one for te black player, asking again */
	if(color == WHITE && game->p1.player_type == HUMAN && strcmp(name, game->p1.player_name) == 0) {
		printf("\nThis name is already taken");
		goto ask_name;
	}
	
	/* Copying the string into the reserved space for it and updating the type of the player (here HUMAN) */
	if(color == BLACK) {
		strcpy(game->p1.player_name, name);
		game->p1.player_type = HUMAN;
	}
	
	else {
		strcpy(game->p2.player_name, name);
		game->p2.player_type = HUMAN;
	}
	
	
	printf("\n");
}
예제 #4
0
파일: JXM002_.C 프로젝트: ataylorkt/noxDB
/* ------------------------------------------------------------- */
void jx_sqlUpperCaseNames(PJXSQL pSQL)
{
   int i;
   for (i = 0; i < pSQL->nresultcols; i++) {
     PJXCOL pCol = &pSQL->cols[i];
     str2upper (pCol->colname , pCol->colname);
   }
}
예제 #5
0
// convert to uppercase if s is a DOS-name
void name2upper (char * s)
{
  int i, l;

    l = strlen (s);
    for (i=0; i < l; i++)
    {
      if (s[i] == '.')
        break;
    }
    if (i > 8 || l - i > 4)
      return;
    str2upper(s);
}
예제 #6
0
int searchpattern (char *pattern) {
	char *toprocess;
	int found=0;
	int size;
	char pline[MAX_LINE_SIZE];
	char unhex[MAX_LINE_SIZE];

	toprocess=pattern;
	size=strlen(toprocess);
	if (opt_ignorecase) {
		toprocess=str2upper(toprocess,pline);
	}
	if (opt_unhex) {
		size=hexstr2char(toprocess,unhex,MAX_LINE_SIZE);
		toprocess=unhex;
	}
	found=bloom_check(&bloom, toprocess, size);
	return (found);
}
예제 #7
0
/*
 * Given an interface name (e.g., eth0), return the MAC address in human
 * readable format (e.g., 00:11:52:12:D9:A0).  Return NULL for no match.
 */
char *iface_mac2str(char *ifname) {
    int buflen = 20;
    char *buf = NULL;
    struct nl_handle *handle = NULL;
    struct nl_cache *cache = NULL;
    struct rtnl_link *link = NULL;
    struct nl_addr *addr = NULL;

    if (ifname == NULL) {
        return NULL;
    }

    if ((cache = _iface_get_link_cache(&handle)) == NULL) {
        return NULL;
    }

    if ((link = rtnl_link_get_by_name(cache, ifname)) == NULL) {
        goto mac2str_error2;
    }

    if ((addr = rtnl_link_get_addr(link)) == NULL) {
        goto mac2str_error3;
    }

    if ((buf = calloc(sizeof(char *), buflen)) == NULL) {
        goto mac2str_error4;
    }

    if ((buf = nl_addr2str(addr, buf, buflen)) != NULL) {
        buf = str2upper(buf);
    }

mac2str_error4:
    nl_addr_destroy(addr);
mac2str_error3:
    rtnl_link_put(link);
mac2str_error2:
    nl_close(handle);
    nl_handle_destroy(handle);

    return buf;
}
예제 #8
0
int main (int argc, char *argv[]) {
	int count;
	unsigned long maxitems=0;
	int c;
	int index;
	FILE *fp;
	unsigned long items;
	char line[MAX_LINE_SIZE];
	char pline[MAX_LINE_SIZE];
	char unhex[MAX_LINE_SIZE];
	char *toprocess;
	int size;
	int found=0;	

	/* safe defaults */
	opt_errorrate=0.01;
	opt_bloomfile=NULL;

	/* load config */
	loadconfig();

  while ((c = getopt (argc, argv, "huicp:svde:b:f:")) != -1)
    switch (c)
      {
      case 'h':
	displayhelp();
	exit(0);
	break;
      case 'u':
	opt_unhex = 1;
	break;
      case 'i':
	opt_ignorecase = 1;
	break;
      case 'c':
        opt_init = 1;
        break;
      case 'p':
	opt_progressitems = atoi(optarg);
	break;
      case 'e':
	opt_errorrate = atof(optarg);
	break;
      case 'b':
        opt_bloomfile = optarg;
        break;
      case 'f':
	opt_readfromfile = optarg;
	break;
      case 's':
        opt_search = 1;
        break;
		case 'v':
		opt_verbose++;
		break;

		case 'd':
		opt_debug++;
		break;
      case '?':
        if (optopt == 'b')
          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
        else if (isprint (optopt))
          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
        else
          fprintf (stderr,
                   "Unknown option character `\\x%x'.\n",
                   optopt);
        return 1;
      default:
        abort ();
      }

	if (opt_debug) {
	  printf ("opt_init = %d, opt_search = %d, opt_bloomfile = %s\n",
		  opt_init, opt_search, opt_bloomfile);

	for (count = 1; count < argc; count++) {
		printf("argv[%d] = %s\n", count, argv[count]);
	}

		for (index = optind; index < argc; index++)
		  printf ("Non-option argument %s\n", argv[index]);
	}

	if (opt_init) {
		for (index = optind; index < argc; index++) {
			if (opt_verbose) fprintf(stderr,"[i] Counting lines for %s\n", argv[index]);
			fp=fopen(argv[index],"r");
			if (fp==NULL) {
				fprintf(stderr,"Error opening %s\n",argv[index]);
				break;	
			}
			items=getlinecount(fp);
			if (opt_verbose) fprintf(stderr,"[i] %s have %lu lines/items\n",argv[index],items);
			maxitems=maxitems+items;
			fclose(fp);
		}
		if (opt_verbose) fprintf(stderr,"[i] Maximum number of items: %lu\n",maxitems);
		bloom_init(&bloom, maxitems, opt_errorrate);

		items=0;
		for (index = optind; index < argc; index++) {
			if (opt_verbose) fprintf(stderr,"[i] Processing %s\n", argv[index]);
			fp=fopen(argv[index],"r");
			if (fp==NULL) {
				fprintf(stderr,"Error opening %s\n",argv[index]);
				break;	
			}
			/* read line by line */
			while (fgets (line, sizeof(line), fp)) {
				toprocess=line;
				size=strlen(line);
				if (line[size-1]=='\n') line[--size]='\0';
				if (line[size-1]=='\r') line[--size]='\0';
				if (opt_debug) fprintf(stderr,"Line (%d): %s \n",size,line);
				if (opt_verbose && (items++ % opt_progressitems==0)) fprintf(stderr,"\r[i] Line %lu of %lu", items, maxitems);

				if (opt_ignorecase) {
					toprocess=str2upper(toprocess,pline);
				}
				if (opt_unhex) {
					size=hexstr2char(toprocess,unhex,MAX_LINE_SIZE);
					toprocess=unhex;
				} 
				bloom_add(&bloom, toprocess, size);
			}
			if (opt_verbose) fprintf(stderr,"\n[i] Done for %s!\n",argv[index]);
			fclose(fp);
		}

		if (opt_bloomfile==NULL) {
			fprintf(stderr,"No bloom file specified for init. Not saving.\n");
		} else {
			if (opt_verbose) fprintf(stderr,"[i] Saving to %s\n",opt_bloomfile);
			bloom_save(&bloom,opt_bloomfile);
			/* if (opt_verbose) bloom_print(&bloom); */
		}
	}

	if (opt_search || (!opt_init)) {
		if (opt_bloomfile==NULL) {
			fprintf(stderr,"No bloom file specified.\n");
		} else {
			if (opt_verbose) fprintf(stderr,"[i] Opening bloom file: %s\n", opt_bloomfile);
			if (bloom_load(&bloom, opt_bloomfile)) {
				fprintf(stderr,"[i] Error loading bloom file: %s\n", opt_bloomfile);
				return (1);
			}
		}

		if (opt_verbose) fprintf(stderr,"[i] Searching patterns\n");

		for (index = optind; index < argc; index++) {
			toprocess=argv[index];
			if (opt_verbose) fprintf(stderr,"[i] Processing %s\n", toprocess);
			if (searchpattern(toprocess)) {
				fprintf(stdout,"%s found\n", argv[index]);
			} else {
				fprintf(stdout,"%s not found\n", argv[index]);
			}
		}

		if (opt_readfromfile!=NULL) {
			if (opt_verbose) fprintf(stderr,"[v] Reading from file %s\n",opt_readfromfile);
			if (strcmp(opt_readfromfile,"-")==0) {
				fprintf (stderr,"[i] Reading from standard input. Specify pattern separated by new line.\n");
				fp=stdin;
			} else {
				fp=fopen(opt_readfromfile,"r");
			}
			if (fp==NULL) {
				fprintf(stderr,"[!] Error opening file: %s\n",opt_readfromfile);
				exit(1);
			}
			while (fgets (line, sizeof(line), fp)) {
				toprocess=line;
				size=strlen(line);
				if (line[size-1]=='\n') line[--size]='\0';
				if (line[size-1]=='\r') line[--size]='\0';
				if (opt_debug) fprintf(stderr,"[d] Line in pattern (%d): %s \n",size,line);
				if (opt_verbose) fprintf(stderr,"[v] Processing from file %s\n", toprocess);
				if (searchpattern(toprocess)) {
					fprintf(stdout,"%s found\n", toprocess);
				} else {
					fprintf(stdout,"%s not found\n", toprocess);
				}
			}
			if (fp!=stdin) fclose (fp);
		}
	}
}