Esempio n. 1
0
static int query_token(struct yaz_pqf_parser *li)
{
    int sep_char = ' ';
    const char *sep_match;
    const char **qptr = &li->query_ptr;

    while (**qptr == ' ')
        (*qptr)++;
    if (**qptr == '\0')
        return 0;
    li->lex_len = 0;
    if ((sep_match = strchr (li->left_sep, **qptr)))
    {
        sep_char = li->right_sep[sep_match - li->left_sep];
        ++(*qptr);
    }
    li->lex_buf = *qptr;
   
    if (**qptr == li->escape_char && isdigit (((const unsigned char *) *qptr)[1]))
    {
        ++(li->lex_len);
        ++(*qptr);
        return 'l';
    }
    while (**qptr && **qptr != sep_char)
    {
        if (**qptr == '\\')
        {
            ++(li->lex_len);
            ++(*qptr);
        }
        ++(li->lex_len);
        ++(*qptr);
    }
    if (**qptr)
        ++(*qptr);
    if (sep_char == ' ' &&
        li->lex_len >= 1 && li->lex_buf[0] == li->escape_char)
    {
        if (compare_term (li, "and", 1))
            return 'a';
        if (compare_term (li, "or", 1))
            return 'o';
        if (compare_term (li, "not", 1))
            return 'n';
        if (compare_term (li, "attr", 1))
            return 'l';
        if (compare_term (li, "set", 1))
            return 's';
        if (compare_term (li, "attrset", 1))
            return 'r';
        if (compare_term (li, "prox", 1))
            return 'p';
        if (compare_term (li, "term", 1))
            return 'y';
    }
    return 't';
}
Esempio n. 2
0
static void rpn_term_type(struct yaz_pqf_parser *li, ODR o)
{
    if (!li->query_look)
        return ;
    if (compare_term (li, "general", 0))
        li->term_type = Z_Term_general;
    else if (compare_term (li, "numeric", 0))
        li->term_type = Z_Term_numeric;
    else if (compare_term (li, "string", 0))
        li->term_type = Z_Term_characterString;
    else if (compare_term (li, "oid", 0))
        li->term_type = Z_Term_oid;
    else if (compare_term (li, "datetime", 0))
        li->term_type = Z_Term_dateTime;
    else if (compare_term (li, "null", 0))
        li->term_type = Z_Term_null;
#if 0
    else if (compare_term(li, "range", 0))
    {
        /* prepare for external: range search .. */
        li->term_type = Z_Term_external;
        li->external_type = VAL_MULTISRCH2;
    }
#endif
    lex (li);
}
Esempio n. 3
0
int main(int argc, char * argv[])
{
	if(argc !=2 && argc !=3 && argc != 4 && argc !=5) //They are not the only possible permutations
	{
		fprintf(stderr, "Could not open input file %s\n",argv[1]);
	}
	if(argc == 2)
	{	
		if (strcmp(argv[1],"-f") != 0 && strcmp(argv[1], "-l") != 0)
		{	
      			char* term = argv[1];                // get the term
			compare_term(term);
		}
		else 
		{
      			fprintf(stderr, "Could not open input file haha\n");
      			exit(1);      
   		}
  	}
	else if (argc == 3)
	{	
		FILE* listfile;
		if((strcmp(argv[1],"-l") == 0))
		{  	
			listfile = fopen(argv[2],"r");
			compare_term_list(listfile);
		}
	}
	else if (argc == 4)
	{
		FILE* file;
		char* term;
		if(strcmp(argv[1],"-f")==0)
		{
			file=fopen(argv[2],"r");
			term = argv[3];
		}
		else if (strcmp(argv[2],"-f")==0)
		{
			file=fopen(argv[3],"r");
			term = argv[1];
		}
		compare_term_file(term,file);
	}
	else if (argc == 5)
	{
		FILE* file;
		FILE* listfile;
		if (strcmp(argv[1],"-f") == 0)
		{
			file = fopen(argv[2],"r");
			listfile = fopen(argv[4],"r");
		}
		else if (strcmp(argv[1],"-l") == 0)
		{
			listfile = fopen(argv[2],"r");
			file = fopen(argv[4],"r");
		}
		compare_term_file_list(file,listfile);
	}
	return 0;
}
Esempio n. 4
0
int main(int argc, char* argv[])
{
	int m = 0;
	int getoption =0;
	FILE* file =NULL;
	int container = text_ini;
	FILE* checklist =NULL;
	char* term =NULL;
	char* target = NULL;
	int radius = -10;
	char*textlist;
	textlist = malloc(container*sizeof(char));
	assert(textlist);
	memset(textlist,0,container+1);
	char ch;
	long i = 0;
	FILE* text;
	for (m=0; m<argc; m++)
	{
		if(argv[m][0] == '-')
		{
			if (len(argv[m])==2)
			{
				getoption =1;
				switch(argv[m][1])
				{
					case 'f':
						text = fopen(argv[m+1],"r");
					case 'l':
						list = fopen(argv[m+1],"r");
					case 'b':
						target = (argv[m+1]);
					case 't':
						radius = atoi(argv[m+1]);
					case 'c':
						radius = atoi(argv[m+1]);
					case NULL:
						getoption = 0;
				}
			}
			else if (len((argv[m]))>2)
			{	
				switch(argv[m][1])
				{
					case 'f':
						text = fopen(argv[m]+2,"r");
					case 'l':
						list = fopen(argv[m]+2,"r");
					case 'b':
						target = (argv[m]+2);
					case 't':
						radius = atoi(argv[m]+2);
					case 'c':
						radius = atoi(argv[m]+2);
					case NULL:
						term = argv[m];
				}
			}
		}
		else
		{
			if(getoption == 0)
			{
				term = argv[m];
			}
			else if (getoption == 1)
			{
				getoption = 0;
			}
		}
	}
	if (file == NULL)
	{
		text = stdin;
	}
	if (file != NULL)
	{
		text = file;
	}
	long totalchar;
	int afterlen;
	while ((ch = fgetc(text))!=EOF)
	{	
		textlist[i] = lower_case(ch);
		i++;
		if (i == container-1)
		{
			container = container * 2;
			textlist = realloc(textlist, container*sizeof(char));
			assert(textlist);
			afterlen = container/2+1;
			memset(textlist+afterlen-2,0,afterlen);
		}
	}
	totalchar = i;
	if (checklist == NULL && target == NULL)
	{
		compare_term(term,totalchar,textlist);
	}
	if (checklist == NULL && target != NULL)
	{
		compare_term_target(term,target);
	}
	if (checklist != NULL && target == NULL)
	{
		compare_term_list(checklist,totalchar,textlist);
	}
	if (checklist != NULL && target != NULL)
	{	
		if (radius < 0)
		{
			radius = 5;
			compare_term_target_list_default(term,target,checklist);
		}
		if (radius >= 0)
		{
			compare_term_target_radius(term,target,checklist,radius);
		}
	}
	if (text!= NULL)
	{
		fclose (text);
	}
	if (checklist != NULL)
	{
		fclose (checklist);
	}
	return 0;
}