Exemple #1
0
int _search(char *source_path, INPUT *keyword)
{
    int ret = 0;
    struct stat     statbuf;
    struct dirent   *dir = NULL;
    DIR     *file;
    char    *fullpath;

    if ((file=opendir(source_path))==NULL)
        return 0;
    fullpath = (char*) __ax_malloc(MAX_FILE_PATH * sizeof(char));
    while ((dir=readdir(file)))
    {
        if((strlen(source_path) + strlen(dir->d_name) + 2) > MAX_FILE_PATH) {
            FCGI_LOG("%s", "Error: path size too large");
            continue;
        }
        sprintf(fullpath, "%s/%s", source_path, dir->d_name);
        fullpath[strlen(fullpath)] = '\0';
        if (lstat(fullpath, &statbuf)<0)
        {
            ret = -1;
            break;
        }
        if (S_ISDIR(statbuf.st_mode)==0)
        {   // file or link
            if (is_match(dir->d_name, keyword)) {
                total_file++;
                file_list = (char (*)[MAX_FILE_PATH]) __ax_realloc((void*)file_list, total_file * MAX_FILE_PATH * sizeof(char));
                strcpy(file_list[total_file - 1], fullpath);
            }
            if (S_ISLNK(statbuf.st_mode))
            {   // do nothing
                continue;
            }
            else
            {
            }
        }
        else
        {   // dir
            //do not include "." and ".." and ".@__thumb"
            if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..") || !strcmp(dir->d_name, ".@__thumb"))
                continue;
            if (is_match(dir->d_name, keyword)) {
                //print_file_xml(fullpath);
                //sort_by_type(fullpath, &list);
                total_folder++;
                folder_list = (char (*)[MAX_FILE_PATH]) __ax_realloc((void*)folder_list, total_folder * MAX_FILE_PATH * sizeof(char));
                strcpy(folder_list[total_folder - 1], fullpath);
            }
            _search(fullpath, keyword);
        }
    }
    closedir(file);

    if (fullpath) __ax_free(fullpath);

    return ret;
}
Exemple #2
0
bool is_match(const char* str, const char* match_str, char prev, int i, int j)
{
    if(match_str[j] == '\0' || str[j] == '\0')
    {
        return match_str[j] == str[j] || match_str[j] == '*';
    }

    switch (match_str[j])
    {
        case '.':
            return is_match(str, match_str, '.', i + 1, j + 1);
        case '*':
            if( str[i] == prev && is_match(str,match_str,prev,i+1,j))
            {
               return true;
            }
            return is_match(str, match_str, '*', i, j+1);
        default:
            if(str[i] == match_str[j])
                return is_match(str, match_str, match_str[j], i+1, j+1);
            else if(match_str[j+1] == '*')
                return is_match(str, match_str, prev, i, j+2);
    }

    return false;
}
Exemple #3
0
static int ini_parse_handler(void* user, const char* section, const char* name,
                   const char* value)
{
    TunnelConfig *config = (TunnelConfig *)user;

    if (is_match(section, name, "main", "ssl_server_name")) {
        config->ssl_server_name = strdup(value);
    } else if (is_match(section, name, "main", "ssl_server_port")) {
        config->ssl_server_port = (uint16_t)atoi(value);
    } else if (is_match(section, name, "main", "destination_name")) {
        config->destination_name = strdup(value);
    } else if (is_match(section, name, "main", "destination_port")) {
        config->destination_port = strdup(value);
    } else if (is_match(section, name, "main", "thread_count")) {

        // We need at least one thread to run:
        config->thread_count = atoi(value);
        config->thread_count = MAX(config->thread_count, 1);

    } else if (is_match(section, name, "main", "buffer_size")) {
        config->buffer_size = (size_t)atol(value);
        // We need at least 1 byte of buffer space:
        config->buffer_size = MAX(config->buffer_size, 1);
    } else if (is_match(section, name, "ssl", "verify_locations")) {
        config->verify_locations = strdup(value);
    } else if (is_match(section, name, "ssl", "certificate_file")) {
        config->certificate_file = strdup(value);
    } else if (is_match(section, name, "ssl", "PrivateKey_file")) {
        config->PrivateKey_file = strdup(value);
    } else {
        return 0;  /* unknown section/name, error */
    }
    return 1;
}
Exemple #4
0
/* returns NULL on error or no exports available */
exports prune_export_list(exports list, char *spec)
{
	exports exl = NULL;
	exports prev = NULL;	/* keep this around for deletion */
	exports head = list;

	exl = list;
	prev = NULL;
	while (exl) {
		/* check it here, if we need to prune it: */
		if (!is_match(spec, exl->ex_dir)) {
			/* delete the entry from the list here: */
			if (prev == NULL) {
				/* only if we're deleting the head entry */
				prev = exl;
				head = exl = exl->ex_next;
				exports_free(prev);
				prev = NULL;
				continue;
			} else {
				exl = exl->ex_next;
				free(prev->ex_next);
				prev->ex_next = exl;
				continue;
			}
		}
		/* no deletion, iterate */
		prev = exl;
		exl = exl->ex_next;
	}
	return (head);
}
Exemple #5
0
int
main (int argc, char *argv[])
{
	int type;
	void *data;
	int num_nums = argc - 1;
	int i;
	long nums [num_nums];

	for (i = 0; i < num_nums; ++i)
		nums [i] = strtoul (argv [i + 1], NULL, 16);

	while ((type = read_entry (stdin, &data)) != SGEN_PROTOCOL_EOF) {
		gboolean match = FALSE;
		for (i = 0; i < num_nums; ++i) {
			if (is_match ((gpointer) nums [i], type, data)) {
				match = TRUE;
				break;
			}
		}
		if (match)
			print_entry (type, data);
		free (data);
	}

	return 0;
}
Exemple #6
0
static void get_find_palindromes_at(const char *x, int x_len,
	int i1, int i2, int max_loop_len1, int min_arm_len, int max_nmis,
	const int *lkup, int lkup_len)
{
	int arm_len, valid_indices;
	char c1, c2;

	arm_len = 0;
	while (((valid_indices = i1 >= 0 && i2 < x_len) &&
                i2 - i1 <= max_loop_len1) || arm_len != 0)
	{
		if (valid_indices) {
			c1 = x[i1];
			c2 = x[i2];
			if (is_match(c1, c2, lkup, lkup_len) ||
			    max_nmis-- > 0) {
				arm_len++;
				goto next;
			}
		}
		if (arm_len >= min_arm_len)
			_report_match(i1 + 2, i2 - i1 - 1);
		arm_len = 0;
	next:
		i1--;
		i2++;
	}
	return;
}
Exemple #7
0
void Events::wait_event(XEvent* event, long event_mask) {
  acquire_sem(lock_);
  std::list<XEvent*>::iterator i;
  for(i=list_.begin();i!=list_.end();++i) {
    if(is_match(event_mask, (*i)->type)) {
      *event = *(*i);
      list_.erase(i);
      acquire_sem(counter_);
      release_sem(lock_);
      return;
    }
  }
  release_sem(lock_);
  for(;;) {
    wait_for_coming();
    acquire_sem(lock_);
    if(list_.back()->type == event_mask) {
      *event = *(*i);
      list_.erase(i);
      acquire_sem(counter_);
      release_sem(lock_);
      return;    
    }
    release_sem(lock_);
  }
}
Exemple #8
0
/* This function searches the current directory for any filenames that begin with "slope.", parses the filename as input, and 
   uses it to compute the slope of the line.
*/
int get_input(char* in,char* out){
  /* If a quit command was given don't bother parsing anymore and return */
  if (is_match("quit",in)){
    strncpy(out,in,strlen(in));
    out[strlen(in)] = '\0';
    return 1;
  }

  int fn;
  int i = 1;
  DIR* dir = opendir(".");
  struct dirent* d = NULL;
  point* p1,*p2;
  char filename[256];

  /* Format from client 'slope in file 2' */
  char* slopep = strtok(in," ");
  char* inp = strtok(NULL," ");
  char* filep = strtok(NULL," ");
  char* nump = strtok(NULL," ");
  char* r = NULL;

  /* If nump is NULL we don't have the file number and cannot search the files. So report an error. */
  if (nump == NULL){
    return 0;
  }

  if (dir != NULL){
    while ((d = readdir(dir)) != NULL){ //STONESOUP:SOURCE_TAINT:FILE_NAME
      /* Zero out the array so we can reuse it */
      bzero(filename,256);      
      /* Build up the format for matching 'slope-#.x1.y1.x2.y2.dat' */
      r = strncat(filename,"slope-",6);
      r = strncat(filename,nump,strlen(nump));
      r = strncat(filename,".",1);
 
     if (strncmp(filename,d->d_name,strlen(filename)) == 0){
	/* Format slope.x1.y1.x2.y2.dat */
	char* slope = strtok(d->d_name,".");
	char* x1 = strtok(NULL,".");
	char* y1 = strtok(NULL,".");
	char* x2 = strtok(NULL,".");
	char* y2 = strtok(NULL,".");
	char* dat = strtok(NULL,".");
	
	if (snprintf(out,BUFFER_SIZE,"%s %s %s %s",x1,y1,x2,y2) < 0){
	  if (closedir(dir) == -1){
	    /*perror("closedir() failed");*/
	  }
	  return 0;
	}
	return 1;
      }
    }
  }
  if (closedir(dir) == -1){
    /*perror("closedir() failed");*/
  }
  return 0;
}
Exemple #9
0
static int is_visible(struct cgit_repo *repo)
{
	if (repo->hide || repo->ignore)
		return 0;
	if (!(is_match(repo) && is_in_url(repo)))
		return 0;
	return 1;
}
int main() {
    const char *regex = ".*/(.+)$";
    const char *str = "/isan/bin/fex.srs";

    if(is_match(regex, str)) {
        printf("Match");
    }
}
bool Regular_Expression::is_match(const std::string& string_to_check) const {

  for(const char& c : string_to_check) {
    if( !is_match(c) ) {
      return false;
    }
  }

  return true;

}
Exemple #12
0
static void
foreach_is_match(gpointer data, gpointer user_data)
{

	if(is_match(data,user_data))
	{
		printf("\n\t%s\t",  data);
		flag_found = TRUE;
	}


}
void process_mbx(char *pPath) {
	/* we'll read the mailbox line by line, skipping mail headers by virtue of them
	 * starting with a "From " line and the header block ending with a blank line
	 * */
	char buf[BUF_SIZE];
	FILE *fp;
	int nRead;
	int ret = 0;
	long depth = 0;
	int header = 0;

	fp = fopen(pPath, "r");

	if (fp == NULL) {
		return;
	}

	bzero(buf, BUF_SIZE);

	while (fgets(buf, BUF_SIZE, fp)) {
		nRead = strlen(buf);
		depth += nRead;
		if (!strncmp(buf, "From ", 5)) {
			header = 1;
		}
		if (buf[0] == '\n') {
			header = 0;
		}
		if (! header) {
			// scan
			if (is_match(buf, nRead)) {
				ret = 1;
				if (!LogTotalMatches) {
					send_match(hit,pPath);
					fclose(fp);
					return;
				}
			}
			if ((ScanDepth != 0) && (depth >= (ScanDepth * 1024))) {
				break;
			}
		}
		bzero(buf, BUF_SIZE);
	}

	if ((LogTotalMatches && TotalMatches) || ret) {
		send_match(hit, pPath);
	}

	fclose(fp);

	return;
}
Exemple #14
0
char *get_command(char *database,char *speech) {

  FILE *file;
  char buf[1024];
  char *ret = NULL; // The command to return.

  if(! file_exists(database)) {
    printf("The database \"%s\" doesn't exist!\n",database);
    exit(2);
  }

  file = fopen(database,"r");

  int i;
  if(LINE_IN_DATABASE != 0) {
    for(i = 0;i < LINE_IN_DATABASE;++i) {
      if(!(fgets(buf,1024,file))) {
      	return ret;
      }
    }
  }

  while( fgets(buf,1024,file)) {
    ++LINE_IN_DATABASE;
    if(is_match(speech,buf)) {
      // Yes the speech matches, now to get variables in it.
      STORE_VARIABLES = 1;
      store_special_variables(speech,buf);
      is_match(speech,buf); // Will now store variables in in a LL

      fgets(buf,1024,file);
      ++LINE_IN_DATABASE;
      ret = create_command(buf);
      break;
    }
  }
  fclose(file);
  return ret;
}
Exemple #15
0
int main(int argc, char** argv)
{
    if( argc < 3 )
    {
        printf("%s str match_pattern\n", argv[0]);
        return 1;
    }

    printf("Is Match:%d\n", is_match(argv[1], argv[2], '\0', 0, 0));

    return 0;
    

}
Exemple #16
0
int
main (int argc, char *argv[])
{
	int type;
	void *data;
	int num_args = argc - 1;
	int num_nums = 0;
	int num_vtables = 0;
	int i;
	long nums [num_args];
	long vtables [num_args];

	for (i = 0; i < num_args; ++i) {
		char *arg = argv [i + 1];
		char *next_arg = argv [i + 2];
		if (!strcmp (arg, "--all")) {
			dump_all = TRUE;
		} else if (!strcmp (arg, "-v") || !strcmp (arg, "--vtable")) {
			vtables [num_vtables++] = strtoul (next_arg, NULL, 16);
			++i;
		} else {
			nums [num_nums++] = strtoul (arg, NULL, 16);
		}
	}

	while ((type = read_entry (stdin, &data)) != SGEN_PROTOCOL_EOF) {
		gboolean match = FALSE;
		for (i = 0; i < num_nums; ++i) {
			if (is_match ((gpointer) nums [i], type, data)) {
				match = TRUE;
				break;
			}
		}
		if (!match) {
			for (i = 0; i < num_vtables; ++i) {
				if (is_vtable_match ((gpointer) vtables [i], type, data)) {
					match = TRUE;
					break;
				}
			}
		}
		if (dump_all)
			printf (match ? "* " : "  ");
		if (match || dump_all)
			print_entry (type, data);
		free (data);
	}

	return 0;
}
Exemple #17
0
/* This function parses the data from the client to make sure we got something we can 
   recognize. If we find points, we will populate them in p1 and p2.
*/
enum INPUT parse_input(char* buffer,point* p1,point* p2){
  /*printf("SERVER: parsing the data from the client\n");*/
  if (is_match("quit",buffer)){
    /*printf("SERVER: found the quit command, the server will be shutting down momentarily\n");*/
    return INPUT_QUIT;
  }else{ /* If we didn't find the quit command, let's assume we were given an enviornment variable
	    that holds the query string and try to parse it to obtain our two points */
    /*printf("SERVER: found points (%d,%d) and (%d,%d)\n",p1->x,p1->y,p2->x,p2->y);*/   
    char* queryenv = getenv(buffer); // STONESOUP:INTERACTION_POINT // STONESOUP:SOURCE_TAINT:ENVIRONMENT_VARIABLE
    
    if ( queryenv == NULL ){/* The environment variable could not be found return error */
      return INPUT_ERROR;
    }
    
    /* The query string should follow the format "x1=n1&y1=n2&x2=n3&y2=n4" where n1, n2, n3, and n4 are any integer value.*/
    assoc_t query = parse_query_string(queryenv);
    if(!query){ /* Failed ot parse the query string return error */
      return INPUT_ERROR;
    }else{
      assoc_t q = query;
      for(;q->key;q++){
	if(is_match("x1",q->key)){
	  p1->x = atoi(q->val);
	}else if(is_match("y1",q->key)){
	  p1->y = atoi(q->val);
	}else if(is_match("x2",q->key)){
	  p2->x = atoi(q->val);
	}else if(is_match("y2",q->key)){
	  p2->y = atoi(q->val);
	}
      }
      free(query);
      query = NULL;
    }
    return INPUT_POINTS;
  }
}
Exemple #18
0
std::vector<NatOrbOcc*> ParseNatOrbOcc(std::ifstream& mfile)
{
	std::cout.precision(7);
	std::vector<NatOrbOcc*> natorb;
	std::string line;
	if (mfile.is_open())
	{
		while (!mfile.eof())
		{
			getline(mfile,line);

			//Found ci root
			if(is_match(line,"Natural orbitals and occupation numbers for root "))
			{
				NatOrbOcc* noc = new NatOrbOcc();
				getline(mfile,line);
				//std::cout<<line<<std::endl;
				char delm =' ';
				std::vector<std::string> occ_line=split(line,delm);
				//std::cout<<occ_line.size()<<std::endl;
				getline(mfile,line);
				std::vector<std::string> occ_line2=split(line,delm);
				//std::cout<<occ_line.at(2)<<std::endl;
				int orbsize=occ_line.size()-2+occ_line2.size();
				//std::cout<<orbsize<<std::endl;
				noc->occ.resize(orbsize);
				natorb.push_back(noc);
				int q = 0;
				for(int i=2; i<occ_line.size(); i++)
				{
					noc->occ[i-2]=atof(occ_line.at(i).c_str());
					q+=1;
				}
				for(int i=0; i<occ_line2.size(); i++)
				{
					noc->occ[i+q]=atof(occ_line2.at(i).c_str());
				}

				//				for(int i=0; i<noc->occ.size(); i++)
				//					std::cout<<noc->occ.at(i)<< " ";
				//				std::cout<<std::endl;
			}

		}

	}
	return natorb;

}
Exemple #19
0
static int get_palindrome_arm_length(const char *x, int x_len, int max_nmis,
	const int *lkup, int lkup_len)
{
	int i1, i2;
	char c1, c2;

	for (i1 = 0, i2 = x_len - 1; i1 < i2; i1++, i2--) {
		c1 = x[i1];
		c2 = x[i2];
		if (!(is_match(c1, c2, lkup, lkup_len) ||
		      max_nmis-- > 0))
			break;
	}
	return i1;
}
Exemple #20
0
/* This function parses the data from the client to make sure we got something we can 
   recognize. If we find points, we will populate them in p1 and p2.
*/
enum INPUT parse_input(char* buffer,point* p1,point* p2){
  /*printf("SERVER: parsing the data from the client\n");*/
  
  if (is_match("quit",buffer)){
    /*printf("SERVER: found the quit command, the server will be shutting down momentarily\n");*/
    return INPUT_QUIT;
  }else{ /* If we didn't find the quit command, let's try to parse it as if we have our two points */
    if (sscanf(buffer,"%lu %lu %lu %lu",&(p1->x),&(p1->y),&(p2->x),&(p2->y)) == EOF){ //STONESOUP:DATA_TYPE:UNSIGNED_LONG
      /*perror("SERVER: sscanf() failed");*/
      return INPUT_ERROR;
    }
    /*printf("SERVER: found points (%d,%d) and (%d,%d)\n",p1->x,p1->y,p2->x,p2->y);*/
    return INPUT_POINTS;
  }
}
void StaticExclusionList::filter_by_list(std::vector<BasicPeak> &peaks,double current_time) {

	auto itr_entry = entries.begin();
	auto itr_peak = peaks.begin();

	for (; itr_entry != entries.end() && itr_peak != peaks.end();) {
		StaticExclusionMatchQuery q = StaticExclusionMatchQuery(itr_peak->mz, mz_tolerance, current_time);
		if (itr_entry->is_match(q)) {
			itr_peak = peaks.erase(itr_peak);
		} else if (itr_entry->mz < itr_peak->mz) {
			++itr_entry;
		} else {
			++itr_peak;
		}
	}

}
Exemple #22
0
void handle_rules(xcb_window_t win, bool *floating, bool *transient, bool *fullscreen, bool *takes_focus)
{
    xcb_ewmh_get_atoms_reply_t win_type;

    if (xcb_ewmh_get_wm_window_type_reply(ewmh, xcb_ewmh_get_wm_window_type(ewmh, win), &win_type, NULL) == 1) {
        for (unsigned int i = 0; i < win_type.atoms_len; i++) {
            xcb_atom_t a = win_type.atoms[i];
            if (a == ewmh->_NET_WM_WINDOW_TYPE_TOOLBAR
                    || a == ewmh->_NET_WM_WINDOW_TYPE_UTILITY) {
                *takes_focus = false;
            } else if (a == ewmh->_NET_WM_WINDOW_TYPE_DIALOG) {
                *floating = true;
            }
        }
        xcb_ewmh_get_atoms_reply_wipe(&win_type);
    }

    xcb_ewmh_get_atoms_reply_t win_state;

    if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &win_state, NULL) == 1) {
        for (unsigned int i = 0; i < win_state.atoms_len; i++) {
            xcb_atom_t a = win_state.atoms[i];
            if (a == ewmh->_NET_WM_STATE_FULLSCREEN) {
                *fullscreen = true;
            }
        }
        xcb_ewmh_get_atoms_reply_wipe(&win_state);
    }

    xcb_window_t transient_for = XCB_NONE;
    xcb_icccm_get_wm_transient_for_reply(dpy, xcb_icccm_get_wm_transient_for(dpy, win), &transient_for, NULL);
    *transient = (transient_for == XCB_NONE ? false : true);
    if (*transient)
        *floating = true;

    rule_t *rule = rule_head;

    while (rule != NULL) {
        if (is_match(rule, win)) {
            if (rule->effect.floating)
                *floating = true;
        }
        rule = rule->next;
    }
}
Exemple #23
0
  bool isValid(string s) {
    stack<char> stk;

    for (auto& chr : s) {
      if (chr == '(' or chr == '[' or chr == '{') {
        stk.push(chr);
      } else if (stk.size()) {
        if (is_match(stk.top(), chr)) {
          stk.pop();
        } else {
          return false;
        }
      } else {
        return false;
      }
    }
    return stk.empty();
  }
Exemple #24
0
int main() {
	int N, M, i, j;

	scanf("%d", &N);

	struct Option possible_pw[N];

	for (i = 0; i < N; i++) {
		scanf("%s", possible_pw[i].password);
		possible_pw[i].matches = 0;
	}

	scanf("%d", &M);

	char hint[M][50];

	for (i = 0; i < M; i++) {
		scanf("%s", hint[i]);
	}

	for (i = 0; i < N; i++) {
		for (j = 0; j < M; j++) {
			if (is_match(possible_pw[i].password, hint[j]))
				possible_pw[i].matches++;
		}
	}

	char chosen_pw[50];
	int highest_matches = 0;

	for (i = 0; i < N; i++) {
		if (possible_pw[i].matches > highest_matches) {
			highest_matches = possible_pw[i].matches;
			strcpy(chosen_pw, possible_pw[i].password);
		}
		else if (possible_pw[i].matches == highest_matches && strcmp(possible_pw[i].password, chosen_pw) < 0) {
			strcpy(chosen_pw, possible_pw[i].password);
		}
	}

	printf("%s", chosen_pw);

    return 0;
}
Exemple #25
0
char		*ft_strnstr(char *big, char *little, size_t len)
{
	size_t	cnt;

	if (little[0] == '\0')
		return (big);
	cnt = 0;
	while (big[cnt] != '\0' && cnt < len)
	{
		if (big[cnt] == little[0])
		{
			if (is_match(&big[cnt], little, cnt) == 1)
			{
				return (&big[cnt]);
			}
		}
		cnt++;
	}
	return (NULL);
}
void process_bzip2(char *pPath) {
#ifdef HAVE_LIBBZ2
	BZFILE *bzfile;
	char buf[BUF_SIZE];	
	int nRead;
	long depth = 0;
	int ret = 0;

	bzfile = BZ2_bzopen(pPath, "rb");

	if (bzfile == NULL) {
		// don't care why
		return;
	}

	while ((nRead = BZ2_bzread(bzfile, &buf, BUF_SIZE)) > 0) {
		depth += nRead;
		if (is_match(buf,nRead)) {
			ret = 1;
			if (!LogTotalMatches) {
				send_match(hit,pPath);
				(void)BZ2_bzclose(bzfile);
				return;
			}
		}
		bzero(buf, sizeof(buf));
		if ((ScanDepth != 0) && (depth >= (ScanDepth * 1024))) {
			break;
		}
	}

	if ((LogTotalMatches && TotalMatches) || ret) {
		send_match(hit, pPath);
	}

	(void)BZ2_bzclose(bzfile);
#endif
	return;
}
Exemple #27
0
int main()
{
    int n;

    while(scanf("%d ", &n), n > 0)
    {
        memset(is_on, 0, sizeof(is_on));
        
        for(int i = 0; i < n; i++)
        {
            fgets(led[i], 10, stdin);

            for(int j = 0; j < 7; j++)
                is_on[i][j] = led[i][j] == 'Y';
        }

        if(is_match(n))
            puts("MATCH");
        else
            puts("MISMATCH");
    }
    return 0;
}
Exemple #28
0
int main(void) {
	struct entry entries[6];
	int i;
	printf("input id and nature.\n");
	for (i = 0; i < 6; i ++) {
		scanf("%d %d", &entries[i].id, &entries[i].nature);
	}
	int ns[] = {0, 4, 5};
	for (i = 0; i < 3; i ++) {
		int n = ns[i];
		int row;
		for (row = 0; row < 65536; row ++) {
			uint seed = (uint)entries[n].id << 16 | row;
			if (is_match(entries, seed)) {
				printf("0x%.8x", seed);
				printf(" (");
				print_order(entries, seed);
				printf(")\n");
			}
		}
	}
	printf("finish\n");
	return 0;
}
Exemple #29
0
void solver::do_solve()
{
	//DrtPred question("--");
	/// erase the question !!!
	string solver_options= wi_->getSolverOptions();

	vector<Level> solved;

	vector<DrtVect> question_vect;
	question_vect.push_back(question_);
	vector<vector<clause_vector> > new_feet_clauses = get_relevant_clauses(question_vect);
	if(solver_options.find("simple") != string::npos) {
		new_feet_clauses= filter_simple_inference(new_feet_clauses);
	}
	if (new_feet_clauses.size() == 0
		|| (new_feet_clauses.size() != 0 && new_feet_clauses.at(0).size() == 0)
	) {
		if (debug)
			puts("Empty Clauses!!");
		return;
	}

	// cycles through the inferences steps
	int i;
	solved.clear();
	vector<Level> lastData, data_list;

	if (debug)
		puts("Solving...");
	path_memory mem;
	int n = 0;
	//set_clauses_unival(&new_feet_clauses, n+2);
	if (debug)
		print_vector(question_);
	lastData = launch_inference_threads(new_feet_clauses, question_vect, mem, k_, 1, 10, 1, n + 2);
	if (lastData.size() == 0) {
		if (debug)
			puts("Empty!!");
		return;
	}

	DrtMgu upg;
	vector<path_memory> mem_vect;
	data_list.insert(data_list.end(), lastData.begin(), lastData.end());

	sort_data(&data_list);

	Level current_layer;
	double last_layer_weight = 1;

	/// The following is necessary so that the clauses order in the first layer does not count!!!
	for (int m = 0; m < data_list.size(); ++m) {
		current_layer = data_list.at(m);
		vector<DrtVect> qvect = this->updateCurrentLayer(current_layer, question_);
		path_memory mem_tmp = current_layer.getMemory();
		upg.clear();
		vector<drt> tmp_drts;

		clock_t start;
		double w = is_match(qvect, &upg, &tmp_drts, mem_tmp);
		if(wi_->getTimeout() < 0 )
			break;

		if (debug)
			cout << "SOLVER22:::" << w << endl;
		if (w != 0) {
			mem_tmp.last_upg(upg);
			mem_tmp.last_weigth(w);
			mem_tmp.setDrt(tmp_drts);
			mem_tmp.close();
			if (this->areValidRules(mem_tmp))
				mem_vect.push_back(mem_tmp);
		}
	}


	/// MULTIPLE LEVELS IN THE NEXT VERSION!!! (NOW IT IS TOO SLOW TO DEPLOY)
	// vector<Level> tmp_vect;
	// while ( data_list.size() && n < 3 ) {
	// 	  current_layer= data_list.front();
	// 	  upg.clear();
	// 	  vector<drt> tmp_drts;
	//      vector<DrtVect> qvect= this->updateCurrentLayer(current_layer,question_);
	//      //vector<DrtVect> qvect= current_layer.getData();
	//      path_memory mem_tmp = current_layer.getMemory();
	//      double w=0;
	//      if(mem_tmp.getDepth() > 0)
	//           w = is_match(qvect, &upg, &tmp_drts, mem_tmp);
	//      //bool add_new_clauses= true;
	// 	  if( w != 0 ) {
	// 	       mem_tmp.last_upg(upg);
	// 	       mem_tmp.last_weigth(w);
	// 	       mem_tmp.setDrt(tmp_drts);
	// 	       mem_tmp.close();
	//           //if (this->areValidRules(mem_tmp)) {
	//                //if(true)
	//           //add_new_clauses = false;
	//           mem_vect.push_back(mem_tmp);
	//           //}
	//      }
	// 	  //else {
	//      ///if(add_new_clauses) {
	//      new_feet_clauses = get_relevant_clauses(qvect);
	//      //new_feet_clauses= clauses_;
	//      //}
	//      ++n;
	// 	  set_clauses_unival(&new_feet_clauses, n+2);
	// 	  tmp_vect= launch_inference_threads(new_feet_clauses, qvect, current_layer.getMemory(), k_, 1, 10, 1, n+2);
	// 	  if( tmp_vect.size() ) {
	// 	       data_list.erase( data_list.begin() );
	// 	       tmp_vect.erase(tmp_vect.begin()+1, tmp_vect.end());
	// 	       data_list.insert(data_list.begin(), tmp_vect.begin(), tmp_vect.end() );
	// 	       sort_data(&data_list);
	// 	  }
	// 	  else {
	// 	       data_list.erase( data_list.begin() );
	// 	  }
	// }
	////// NEXT VERSION!!!

	solved_.clear();

	if (mem_vect.size()) {
		int n;
		for (n = 0; n < mem_vect.size(); ++n) {
			DrtMgu upg_tmp = mem_vect.at(n).get_first_upg();
			vector<DrtPred> solved_tmp(question_);
			solved_tmp / upg_tmp;
			double w = mem_vect.at(n).get_total_weigth();
			path_memory mem_tmp = mem_vect.at(n);
			KnowledgeAnswer ka;
			ka.setPreds(solved_tmp);
			ka.setWeigth(w);
			ka.setLink("");
			ka.setText("");
			ka.setMemory(mem_tmp);

			// Update the Question list
			QuestionList tmp_qlist(qlist_);
			tmp_qlist / upg_tmp;
			ka.setQuestionList(tmp_qlist);

			solved_.push_back(ka);
		}
	}
	//sort_data(&solved_);
}
Exemple #30
0
void cgit_print_repolist(void)
{
	int i, columns = 3, hits = 0, header = 0;
	char *last_section = NULL;
	char *section;
	int sorted = 0;

	if (ctx.cfg.enable_index_links)
		++columns;
	if (ctx.cfg.enable_index_owner)
		++columns;

	ctx.page.title = ctx.cfg.root_title;
	cgit_print_http_headers();
	cgit_print_docstart();
	cgit_print_pageheader();

	if (ctx.cfg.index_header)
		html_include(ctx.cfg.index_header);

	if (ctx.qry.sort)
		sorted = sort_repolist(ctx.qry.sort);
	else if (ctx.cfg.section_sort)
		sort_repolist("section");

	html("<table summary='repository list' class='list nowrap'>");
	for (i = 0; i < cgit_repolist.count; i++) {
		ctx.repo = &cgit_repolist.repos[i];
		if (ctx.repo->hide || ctx.repo->ignore)
			continue;
		if (!(is_match(ctx.repo) && is_in_url(ctx.repo)))
			continue;
		hits++;
		if (hits <= ctx.qry.ofs)
			continue;
		if (hits > ctx.qry.ofs + ctx.cfg.max_repo_count)
			continue;
		if (!header++)
			print_header();
		section = ctx.repo->section;
		if (section && !strcmp(section, ""))
			section = NULL;
		if (!sorted &&
		    ((last_section == NULL && section != NULL) ||
		    (last_section != NULL && section == NULL) ||
		    (last_section != NULL && section != NULL &&
		     strcmp(section, last_section)))) {
			htmlf("<tr class='nohover'><td colspan='%d' class='reposection'>",
			      columns);
			html_txt(section);
			html("</td></tr>");
			last_section = section;
		}
		htmlf("<tr><td class='%s'>",
		      !sorted && section ? "sublevel-repo" : "toplevel-repo");
		cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL);
		html("</td><td>");
		html_link_open(cgit_repourl(ctx.repo->url), NULL, NULL);
		html_ntxt(ctx.cfg.max_repodesc_len, ctx.repo->desc);
		html_link_close();
		html("</td><td>");
		if (ctx.cfg.enable_index_owner) {
			if (ctx.repo->owner_filter) {
				cgit_open_filter(ctx.repo->owner_filter);
				html_txt(ctx.repo->owner);
				cgit_close_filter(ctx.repo->owner_filter);
			} else {
				html("<a href='");
				html_attr(cgit_currenturl());
				html("?q=");
				html_url_arg(ctx.repo->owner);
				html("'>");
				html_txt(ctx.repo->owner);
				html("</a>");
			}
			html("</td><td>");
		}
		print_modtime(ctx.repo);
		html("</td>");
		if (ctx.cfg.enable_index_links) {
			html("<td>");
			cgit_summary_link("summary", NULL, "button", NULL);
			cgit_log_link("log", NULL, "button", NULL, NULL, NULL,
				      0, NULL, NULL, ctx.qry.showmsg);
			cgit_tree_link("tree", NULL, "button", NULL, NULL, NULL);
			html("</td>");
		}
		html("</tr>\n");
	}
	html("</table>");
	if (!hits)
		cgit_print_error("No repositories found");
	else if (hits > ctx.cfg.max_repo_count)
		print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort);
	cgit_print_docend();
}