Example #1
0
File: idtest.c Project: 1ack/Impala
int
main( int argc, char **argv )
{
#ifdef HAVE_PSAP_H
	PE	pe;
	PS	psin, psout, pserr;

	/* read the pe from standard in */
	if ( (psin = ps_alloc( std_open )) == NULLPS ) {
		perror( "ps_alloc" );
		exit( EXIT_FAILURE );
	}
	if ( std_setup( psin, stdin ) == NOTOK ) {
		perror( "std_setup" );
		exit( EXIT_FAILURE );
	}
	/* write the pe to standard out */
	if ( (psout = ps_alloc( std_open )) == NULLPS ) {
		perror( "ps_alloc" );
		exit( EXIT_FAILURE );
	}
	if ( std_setup( psout, stdout ) == NOTOK ) {
		perror( "std_setup" );
		exit( EXIT_FAILURE );
	}
	/* pretty print it to standard error */
	if ( (pserr = ps_alloc( std_open )) == NULLPS ) {
		perror( "ps_alloc" );
		exit( EXIT_FAILURE );
	}
	if ( std_setup( pserr, stderr ) == NOTOK ) {
		perror( "std_setup" );
		exit( EXIT_FAILURE );
	}

	while ( (pe = ps2pe( psin )) != NULLPE ) {
		pe2pl( pserr, pe );
		pe2ps( psout, pe );
	}

	exit( EXIT_SUCCESS );
#else
	fprintf(stderr, "requires ISODE X.500 distribution.\n");
	return( EXIT_FAILURE );
#endif
}
Example #2
0
static 
dased (int vecp, char **vec)
{
	int	    sd;
	struct TSAPstart tss;
	struct TSAPstart *ts = &tss;
	struct TSAPdisconnect   tds;
	struct TSAPdisconnect  *td = &tds;

	if (TInit (vecp, vec, ts, td) == NOTOK)
		ts_adios (td, "T-CONNECT.INDICATION failed");

	sd = ts -> ts_sd;
	advise (LLOG_NOTICE, NULLCP, "T-CONNECT.INDICATION: <%d, %s, %s, %d, %d>",
			ts -> ts_sd, taddr2str (&ts -> ts_calling),
			taddr2str (&ts -> ts_called), ts -> ts_expedited,
			ts -> ts_tsdusize);

	if (TConnResponse (sd, NULLTA, 0, NULLCP, 0, NULLQOS, td) == NOTOK)
		ts_adios (td, "T-CONNECT.RESPONSE failed");

	if ((ps = ps_alloc (dg_open)) == NULLPS)
		adios (NULLCP, "ps_alloc: out of memory");
	if (dg_setup (ps, sd, MAXDGRAM, ts_read, ts_write, NULLIFP) == NOTOK)
		adios (NULLCP, "dg_setup: %s", ps_error (ps -> ps_errno));

	for (;;) {
		struct type_DASE_Query__REQ *req;
		PE	pe;

		if ((pe = ps2pe (ps)) == NULLPE) {
			if (ps -> ps_errno == PS_ERR_NONE) {
				advise (LLOG_NOTICE, NULLCP, "T-DISCONNECT.INDICATION");
				break;
			} else
				adios (NULLCP, "ps2pe: %s", ps_error (ps -> ps_errno));
		}

		if (decode_DASE_Query__REQ (pe, 1, NULLIP, NULLVP, &req) == NOTOK)
			adios (NULLCP, "decode_DASE_Query__REQ: %s", PY_pepy);
		PLOGP (pgm_log,DASE_Message, pe, "message", 1);

		dase_aux (req);

		free_DASE_Query__REQ (req);
		pe_free (pe);
	}

	if (isbound) {
		if (debug)
			advise (LLOG_DEBUG, NULLCP, "unbound from directory");

		 ds_unbind ();
		isbound = 0;
	}

	exit (0);
}
Example #3
0
OPTION *root_prediction(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent) {

    //opt to predict shift
    STACK st; st.size = 0;
    STACK srl_st; srl_st.size = 0;
    OPTION *opt = create_option(SRL_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), 
            ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM);
    set_links(ap, mp, opt, sent);
    return opt;
}
Example #4
0
ps_array* ps_join(ps_array **l, ps_array **r) {
	ps_array *lr = ps_alloc((*l)->len + (*r)->len);

	memcpy(lr->ps, (*l)->ps, (*l)->len * (sizeof(char*)));
	memcpy(lr->ps + (*l)->len, (*r)->ps, (*r)->len * (sizeof(char*)));

	free(*l);
	free(*r);

	*l = lr;
	*r = 0;
	return *l;
}
Example #5
0
main()
{
	struct  passwd  *pw_entry ;
	struct  passwd  *getpwuid() ;
	struct	stat	buf ;

	int	i = 1 ;
	int     uid ;
	int	um ;
	char	pass1[LINESIZE] ;
	char	pass2[LINESIZE] ;
	char	Read_in_Stuff[LINESIZE] ;
	char	**vecptr ;
	char 	*tmpdraft ;
	char	home_dir[LINESIZE] ;
	char	*p, *part1, *part2 ;
	char	quipurc_file[100] ;
	char	tailor_file[100] ;
	char	user_name[9] ;
	char	*localptr = Local ;
	char	print_format = EDBOUT ;
	EntryInfo	*ptr ;
	static  CommonArgs ca = default_common_args;
	
	vecptr = (char **) malloc(100) ;
	vecptr[0] = malloc (LINESIZE) ;
	(void) strcpy(vecptr[0], "showentry") ;
	(void) strcpy(pass1, "x") ;
	(void) strcpy(pass2, "y") ;
	tmpdraft = malloc (LINESIZE) ;
	(void) strcpy(tmpdraft, "/tmp/dish-") ;

	if ((opt = ps_alloc (std_open)) == NULLPS)
		fatal (-62, "ps_alloc failed");
	if (std_setup (opt, stderr) == NOTOK)
		fatal (-63, "std_setup failed");
	if ((rps = ps_alloc (std_open)) == NULLPS)
		fatal (-64, "ps_alloc 2 failed");
	if (std_setup (rps, stdout) == NOTOK)
		fatal (-65, "std_setup 2 failed");
	(void) strcpy(filterstring, "userid=") ;

	/* Sort out files, userids etc. */
	uid=getuid() ;
	if ((pw_entry=getpwuid(uid)) == 0)
	{
		ps_printf(rps, "Who are you? (no name for your uid number)\n") ;
		exit(1) ;
	}
	(void) strcpy(user_name, pw_entry->pw_name) ;
	(void) strcat(tmpdraft, user_name) ;

	if (getenv("HOME") == 0) 
	{
		ps_printf(rps, "No home directory?!!") ;
		(void) strcpy(home_dir, pw_entry->pw_dir) ;
	}
	else
	{
		(void) strcpy(home_dir, getenv("HOME")) ;
	}

	(void) strcpy(quipurc_file, home_dir) ;
	(void) strcat(quipurc_file, "/.quipurc") ;

	(void) strcpy(tailor_file, isodefile ("dishinit", 1));

	Manager[0] = 0;
	Password[0] = 0;
	Local[0] = 0;

	(void) stat(tailor_file, &buf) ;
	(void) seteuid(buf.st_uid) ;	/* set effective to enable */
					/* us to read protected file */

	if ((fp_tailor = fopen(tailor_file, "r")) == 0)
	{
		ps_print(rps, "Can't open Tailor File. Abort.\n") ;
		exit(1) ;
	}

	while (fgets (Read_in_Stuff, LINESIZE, fp_tailor) != 0)
	{
		if (!strcmp(Read_in_Stuff, "##Anything after this line is copied into the users ~/.quipurc file\n"))
		{
			break ;
		}

		p = SkipSpace (Read_in_Stuff);
		if (( *p == '#') || (*p == '\0'))
			continue;  		/* ignore comments and blanks */

		part1 = p;
		if ((part2 = index (p,':')) == NULLCP) {
			ps_printf (opt,"Seperator missing '%s'. Ignoring..\n",p);
		}

		*part2++ = '\0';
		part2 = TidyString (part2);

		if (lexequ(part1, "manager") == 0)
		{
			(void) strcpy(Manager, part2) ;
		}
		else
		if (lexequ(part1, "password") == 0)
		{
			(void) strcpy(Password, part2) ;
		}
		else
		if (lexequ(part1, "local") == 0)
		{
			(void) strcpy(Local, part2) ;
		}
		else
		{
			ps_printf(rps, "Error in tailor. What's a %s?\n", part1) ;
		}

	}
	(void) setuid(uid) ;			/* Restore Userid to original user. */

/* create ~/.quipurc file. NB this does eradicate anything in there.
 * 			   (Theoretically nothing.) 
 */

	if (Manager[0] == 0) {
		ps_print(rps, "Can't find out the managers name\n") ;
		exit(1) ;
	}
	if (Password[0] == 0) {
		ps_print(rps, "Can't find out the managers password\n") ;
		exit(1) ;
	}
	if (Local[0] == 0) {
		ps_print(rps, "Can't find out where to search\n") ;
		exit(1) ;
	}

	um = umask(0177) ;
	if ((fp_quipurc = fopen(quipurc_file, "w")) == 0)
	{
		ps_printf(rps, "Can't open ~/.quipurc. Aborting..\n") ;
		exit(1) ;
	}
	(void) umask(um) ;	

	if ((fileps = ps_alloc(std_open)) == NULLPS)
	{
		fatal (-66, "ps_alloc 2 failed");
	}
	if (std_setup (fileps, fp_quipurc) == NOTOK)
	{
		fatal (-67, "std_setup 2 failed");
	}


	/* Sorting out the bind section */
	quipu_syntaxes() ;		/* set up the needed function pointers */
	dsap_init(&i, &vecptr) ;

	(void) strcpy(bindarg.dba_passwd, Password) ;
	bindarg.dba_version = DBA_VERSION_V1988;
	bindarg.dba_passwd_len = strlen(bindarg.dba_passwd) ;

	if ((bindarg.dba_dn = str2dn (Manager)) == NULLDN) 
	{
		ps_printf (opt,"Invalid Manager name %s (???!)\n",Manager) ;
		exit(1) ;
	}

	if (ds_bind (&bindarg, &binderr, &bindresult) != OK)
	{
		ps_printf(rps, "Can't bind as the manager.\n") ;
		exit(1);
	}
	/* Hopefully, should be successfully bound */

/*
 * We now call the search stuff with the right bits, to see if we can get a
 * match of uid='user_name'. Once there, we echo lots of information from
 * their entry out to the .quipurc file.
 * Hopefully there should only be one match. This assumes that ALL dir info
 * up to date, and that SG do not allow multiple users with the same login.
 */

/* set up the appropriate structures and defaults. */

	search_arg.sra_common = ca; /* struct copy */
	search_arg.sra_common.ca_servicecontrol.svc_sizelimit = 2 ;
	search_arg.sra_eis.eis_allattributes = FALSE ;
	search_arg.sra_searchaliases = FALSE;
	search_arg.sra_subset = SRA_ONELEVEL;
	search_arg.sra_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES ;
	search_arg.sra_eis.eis_select = NULLATTR ;
	search_arg.sra_eis.eis_allattributes = TRUE ;
	search_arg.sra_filter = filter_alloc() ;
		/* Default filter. */
		search_arg.sra_filter->flt_next = NULLFILTER;
		search_arg.sra_filter->flt_type = FILTER_ITEM;
		search_arg.sra_filter->FUFILT = NULLFILTER;
		

	if (*localptr == '@')
	{
		localptr++;
	}
	if ((search_arg.sra_baseobject = str2dn(localptr)) == NULLDN)
	{
		ps_printf (opt,"Invalid sequence in username %s.\n", localptr);
		exit(1) ;
	}

	(void) strcat(filterstring, user_name) ;

	search_arg.sra_filter->flt_un.flt_un_item.fi_type = FILTERITEM_EQUALITY ;

	if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type = AttrT_new ("userid")) == NULLAttrT)
	{
		ps_printf(rps, "Oops, userid is not a valid attr type. ABORT!!\n") ;
		exit(1) ;
	}
	if ((search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_value = str2AttrV (user_name, search_arg.sra_filter->flt_un.flt_un_item.fi_un.fi_un_ava.ava_type->oa_syntax)) == NULLAttrV)
	{
		ps_printf(rps, "%s is not a valid attribute value.\n", user_name) ;
	}

/* call search */
/* We now ought to be in the right place, and with the search stuff set,
 * ready to call search, and receive one (or no) entry back, which then 
 * gets processed accordingly.
 */

	if (ds_search (&search_arg, &search_error, &search_result) != DS_OK)
	{
		ps_printf(rps, "Search failed...\n") ;
		exit (1) ;
		/* This is not the same as coming back with */
		/* message "search failed to find anything. */
	}

/* If the user does not exist in the DIT, print out the limited .quipurc
 * and the warning message, and allow the user to play DISH.
 */

	if (search_result.CSR_entries == NULLENTRYINFO)
	{
		ps_printf(opt, "Unfortunately, you seem to have no entry in\n") ;
		ps_printf(opt, "the directory. Contact '%s' who should be able to help.\n", Manager) ;
		ps_printf(opt, "In the mean time, you can read, but not write.\n") ;
	}
	else
	{
		ptr = search_result.CSR_entries ;
		dn = dn_cpy(ptr->ent_dn) ;	/* Essence of move user_name. */

		/* collect the info and put it into current_entry */

		/* Set up the desired attribute type to be read*/
		/* from read.c */
		if ((at = AttrT_new ("userPassword")) != NULLAttrT) 
		{
			as_flag = as_merge (as_flag, as_comp_new (AttrT_cpy (at), NULLAV, NULLACL_INFO));
		}
		else
		{
			ps_printf(rps, "Oops, Serious error. unknown attribute type 'userPassword'.\n") ;
			exit(1) ;
		}

		if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY)
		{	
			read_arg.rda_common = ca; /* struct copy */
			read_arg.rda_object = dn;
			read_arg.rda_eis.eis_infotypes = EIS_ATTRIBUTESANDVALUES;
			read_arg.rda_eis.eis_allattributes = TRUE ;
			read_arg.rda_eis.eis_select = NULLATTR ;

			if (ds_read (&read_arg, &read_error, &read_result) != DS_OK)
			{
				ps_printf(rps, "We even seem to be having problems reading\n" ) ;
				ps_printf(rps, "an entry we searched and found!! HELP!!\n") ;
				exit(1) ;
			}
			if (read_result.rdr_entry.ent_attr == NULLATTR)
			{
				ps_printf(rps, "No attributes present. Even though\n") ;
				ps_printf(rps, "we found you by userid attribute!!! HELP!!\n") ;
				exit (1) ;
			}
			cache_entry (&(read_result.rdr_entry), read_arg.rda_eis.eis_allattributes, TRUE) ;
		}

		if ((current_entry = local_find_entry (dn, FALSE)) == NULLENTRY)
		{
			ps_printf(rps, "We still have nothing.Even after reading? Abort.\n") ;
			exit(1) ;
		}

		ps_printf(fileps, "username: "******"\n") ;

		ps_printf(fileps, "me: ") ;
		dn_print(fileps, dn, EDBOUT) ;
		ps_printf(fileps, "\n") ;

		/* now showattribute -nokey to display it. */

		ps_printf(fileps, "password: "******"You need a password...\n") ;
				(void) strcpy(pass1, getpassword("Enter Password: "******"Re-enter password: "******"\nMismatch - Try again.\n") ;
				}
			}
			ps_printf(fileps, "%s\n", pass1) ;

			um = umask(0177) ;
			if ((fp_draft = fopen(tmpdraft, "w")) == 0)
			{
				ps_print(rps, "Can't open draft file... Abort.\n") ;
				exit(1) ;
			}
			(void) umask(um) ;

			(void) fprintf(fp_draft, "UserPassword = %s\n", pass1) ;
		 	(void) fprintf(fp_draft, "acl = self # write # attributes # acl $ userPassword\n") ;
			(void) fprintf(fp_draft, "acl = others # compare # attributes # acl $ userPassword\n\n") ;
			(void) fclose(fp_draft) ;

			if ((fp_draft = fopen (tmpdraft, "r")) == NULL) {
				ps_printf (opt, "Can't open draft entry %s\n", tmpdraft);
				exit(1) ;
			}

			entry_ptr = get_default_entry (NULLENTRY);
#ifdef TURBO_DISK
			entry_ptr->e_attributes = fget_attributes (fp_draft);
#else
			entry_ptr->e_attributes = get_attributes (fp_draft);
#endif

			(void) fclose (fp_draft);

			mod_arg.mea_common = ca; /* struct copy */
			mod_arg.mea_object = dn;
			for (moddn = dn ; moddn->dn_parent != NULLDN; moddn=moddn->dn_parent)
				;
			entry_ptr->e_name = rdn_cpy (moddn->dn_rdn);
	
			/* add rdn as attribute */
			avst = avs_comp_new (AttrV_cpy (&entry_ptr->e_name->rdn_av));
			temp = as_comp_new (AttrT_cpy (entry_ptr->e_name->rdn_at), avst, NULLACL_INFO);
			entry_ptr->e_attributes = as_merge (entry_ptr->e_attributes, temp);

			for (as = entry_ptr->e_attributes; as != NULLATTR; as = as->attr_link)
			{
				emnew = NULLMOD;
				trail = as->attr_link;
				as->attr_link = NULLATTR;
				temp = current_entry->e_attributes;
				for (; temp != NULLATTR; temp = temp->attr_link) 
					if (AttrT_cmp (as->attr_type, temp->attr_type) == 0)
					{
						/* found it - does it need changing ? */
						if (avs_cmp (as->attr_value, temp->attr_value) != 0) 
							emnew = modify_avs (as->attr_value, temp->attr_value,as->attr_type);
						break;
					}

				if (temp == NULLATTR) 
				{
					emnew = em_alloc ();
					emnew->em_type = EM_ADDATTRIBUTE;
					emnew->em_what = as_cpy(as);
					emnew->em_next = NULLMOD;
				}
				if (emnew != NULLMOD)
				{
					mod_arg.mea_changes = ems_append (mod_arg.mea_changes,emnew);
				}
				as->attr_link = trail;
			}

			while (ds_modifyentry (&mod_arg, &mod_error) != DS_OK)
			{
				if (dish_error (opt, &mod_error) == 0)
				{
					ps_printf(rps,"We have a dish error. Bye.\n") ;
					entry_free (entry_ptr);
					exit(1) ;
				}
				mod_arg.mea_object = mod_error.ERR_REFERRAL.DSE_ref_candidates->cr_name;
			}
			ps_print (rps, "Modified ");
			dn_print (rps, dn, EDBOUT);
			ps_print (rps, "\n");
			delete_cache (dn);	/* re-cache when next read */

			entry_free (entry_ptr);
			ems_part_free (mod_arg.mea_changes);
		}
	}

	while(fgets(Read_in_Stuff, LINESIZE, fp_tailor) != 0)
	{
		fputs(Read_in_Stuff, fp_quipurc) ;
	}
		
	(void) fclose(fp_quipurc) ;	
	(void) fclose(fp_tailor) ;

/*	(void) fprintf(fp_quipurc, "dsap: local_dit \"%s\"\n", Local) ;
	(void) fprintf(fp_quipurc, "notype: acl\n") ;
	(void) fprintf(fp_quipurc, "notype: treestructure\n") ;
	(void) fprintf(fp_quipurc, "notype: masterdsa\n") ;
	(void) fprintf(fp_quipurc, "notype: slavedsa\n") ;
	(void) fprintf(fp_quipurc, "notype: objectclass\n") ;
	(void) fprintf(fp_quipurc, "cache_time: 30\n") ;
	(void) fprintf(fp_quipurc, "connect_time: 2\n") ;
 */
	(void) ds_unbind() ;
	(void) unlink(tmpdraft) ;
}
Example #6
0
//processes sentence and creates derivations
//returns tail of the derivation
OPTION *get_derivation(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent, int do_free_partials) {

	/*    if (ap->intern_synt_deproj == DEPROJ_EXHAUSTIVE && !ap->is_synt_early_reduce) {
        fprintf(stderr, "Error: exhaustive internal syntactic projectivization with late reduce strategy is not supported\n");
        exit(EXIT_FAILURE);
    }
    if (ap->intern_srl_deproj == DEPROJ_EXHAUSTIVE && !ap->is_srl_early_reduce) {
        fprintf(stderr, "Error: exhaustive internal SRL projectivization with late reduce strategy is not supported\n");
        exit(EXIT_FAILURE);
    } */

	//Debug
	//    printf("Next sentence ============\n");

	ASSERT(ap->input_offset == 0 || ap->input_offset == 1);

	STACK st; st.size = 0;
	STACK srl_st; srl_st.size = 0;
	//OPTION *head = create_option(SYNT_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM);
	OPTION *head = create_option(SRL_STEP, 1, -1, -1, NULL, 1, &st, &srl_st, 1, pt_alloc(sent->len), ps_alloc(sent->len), &mp->out_link_act, ACTION_NUM);
	///st_push(&head->srl_stack, 0); //JH allow 0 as an SRL argument
	set_links(ap, mp, head, sent);

	///printf("new sentence\n");///
	OPTION *opt = head;
	while (opt->queue != sent->len + 1) {
		//get next possible actions
		ACTION_SET as = get_next_actions(ap, mp, opt, sent);

		set_mask(mp, opt, &as);

		//=====================  SYNTAX ======================================================
		if (ap->is_synt_early_reduce && as.acts[RED]) {
			int s = st_peek(&opt->stack);
			if (everything_complete(opt->pt, sent, s)) {
				if (ap->parsing_mode != 3 || sent->head[s] != 0 || sent->deprel[s] != ROOT_DEPREL) {
					opt = _action_synt_red(ap, mp, sent, do_free_partials, opt);
					//DEBUG
					//printf("RED\n");

					continue;
				}
			}
		}


		//check LA
		if (as.acts[LA]) {
			int d = st_peek(&opt->stack);
			int h = opt->queue;
			if (sent->head[d] == h) {
				//create sequence of LA operations
				//update queue and stack
				opt = create_option(SYNT_STEP, 0, opt->previous_act, LA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
						&mp->out_link_la_label, mp->deprel_num);
				TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
				//opt->previous_option->pt = NULL;
				set_links(ap, mp, opt, sent);

				opt = create_option(SYNT_STEP, 1, LA, sent->deprel[d], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
						&mp->out_link_act, ACTION_NUM);
				TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
				//opt->previous_option->pt = NULL;
				pt_add_link(opt->pt, h, d, sent->deprel[d]);
				opt->pt->right_connections_num[d]++;
				if (ap->intern_synt_deproj == DEPROJ_NO) {
					st_pop(&opt->stack);
				} else {
					// Do Nothing!!!
				}
				set_links(ap, mp, opt, sent);


				//DEBUG
				//printf("LA\n");

				continue;
			}
		}

		//check RA
		if (as.acts[RA]) {
			int d = opt->queue;
			int h = st_peek(&opt->stack);
			//when agrees
			if (sent->head[d] == h) {
				//means if stack is not empty or  we can make RA with empty stack
				if (h != 0 ||
						(ap->parsing_mode >= 3 && sent->deprel[d] != ROOT_DEPREL
								// can do only once
								&& opt->pt->nodes[d].deprel == ROOT_DEPREL))
				{
					//create sequence of RA operations
					//update queue and stack
					opt = create_option(SYNT_STEP, 0, opt->previous_act, RA, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt),  ps_clone(opt->ps),
							&mp->out_link_ra_label, mp->deprel_num);
					TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
					set_links(ap, mp, opt, sent);


					opt = create_option(SYNT_STEP, 1, RA, sent->deprel[d], opt, opt->period, &opt->stack,  &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
							&mp->out_link_act, ACTION_NUM);
					TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
					pt_add_link(opt->pt, h, d, sent->deprel[d]);
					if (h != 0) {
						opt->pt->right_connections_num[h]++;
					}
					set_links(ap, mp, opt, sent);

					//DEBUG
					//printf("RA\n");

					continue;
				}
			}
		}
		// check FLIP
		if (as.acts[FLIP] && ap->intern_synt_deproj == DEPROJ_EXHAUSTIVE) {
			int s = st_peek(&opt->stack);
			int s_already_conns =  opt->pt->right_connections_num[s];
			int s_under = st_look(&opt->stack, 1);
			int s_under_already_conns = opt->pt->right_connections_num[s_under];

			int top_is_usl = (sent->synt_right_degree[s] == s_already_conns);
			int under_top_is_usl = (sent->synt_right_degree[s_under] == s_under_already_conns);

			if (ap->is_synt_early_reduce || (!top_is_usl && !under_top_is_usl)  )  {
				// s_under will be active earlier than s
				if (lexicograph_ignore_double_entries_comp(
						sent->synt_right_indices[s_under] + s_under_already_conns,
						sent->synt_right_degree[s_under] - s_under_already_conns,
						sent->synt_right_indices[s] + s_already_conns,
						sent->synt_right_degree[s] - s_already_conns) < 0) {
					//create sequence of reduce operation
					//update queue and stack
					opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt);
					//DEBUG
					printf("(SYNT) FLIP\n");
					continue;
				}

			} else {
				// if a top word can be reduce from the top
				if (top_is_usl) {
					int first_usf = get_useful(&opt->stack, 1, opt->pt->right_connections_num, sent->synt_right_degree);
					if (first_usf > 0) {
						// first 'useful' word in the stack should be attached to front of queue -- start remioving useless words
						// next words will be removed on the next rounds
						int next_connection = sent->synt_right_indices[first_usf][opt->pt->right_connections_num[first_usf]];
						if (next_connection  == opt->queue) {
							ASSERT(as.acts[RED]);
							opt = _action_synt_red(ap, mp, sent, do_free_partials, opt);
							//DEBUG
							//printf("RED\n");
							continue;
						}
					}
				}  else {
					// if
					int second_usf = get_useful(&opt->stack, 1, opt->pt->right_connections_num, sent->synt_right_degree);

					ASSERT(second_usf != s_under);
					if (second_usf > 0) {
						int second_usf_already_conns = opt->pt->right_connections_num[second_usf];

						if (lexicograph_ignore_double_entries_comp(
								sent->synt_right_indices[second_usf] + second_usf_already_conns,
								sent->synt_right_degree[second_usf] - second_usf_already_conns,
								sent->synt_right_indices[s] + s_already_conns,
								sent->synt_right_degree[s] - s_already_conns) < 0) {

							opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt);
							as = get_next_actions(ap, mp, opt, sent);
							set_mask(mp, opt, &as);
							ASSERT(as.acts[RED]);
							opt = _action_synt_red(ap, mp, sent, do_free_partials, opt);
							// DEBUG
							printf("FLIP, followed by RED\n");
							//printf("RED, preceded by FLIP\n");
							continue;
						}
					}

				}   // !top_is_usl
			} // !ap->is_synt_early_reduce
		}  // FLIP


		//check SWITCH
		if (as.acts[SWITCH]) {
			int q = opt->queue;
			if (left_part_complete(opt->pt, sent, q)) {
				//if atached to root with not ROOT_DEPREL and parsing_mode >= 3 then RA, not SHIFT should be peformed
				//option sent->deprel[q] == opt->pt->nodes[q]->deprel - relates to RA- + SHIFT sequence  and means that RA- is actually preformed
				//and q is already attached
				if (sent->head[q] != 0 || ap->parsing_mode < 3 ||
						(ap->parsing_mode >= 3 && (sent->deprel[q] == ROOT_DEPREL || sent->deprel[q] == opt->pt->nodes[q].deprel))) {

					opt = create_option(SRL_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue,
							pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM);
					/*                    opt = create_option(SYNT_STEP, 1, SWITCH, SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue,
                            pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM); */
					TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
					set_links(ap, mp, opt, sent);

					//DEBUG
					//printf("SWITCH\n");
					continue;
				}
			}
		}

		//check RED
		if (!ap->is_synt_early_reduce && as.acts[RED]) {
			int s = st_peek(&opt->stack);
			if (everything_complete(opt->pt, sent, s)) {
				if (ap->parsing_mode != 3 || sent->head[s] != 0 || sent->deprel[s] != ROOT_DEPREL) {

					opt = _action_synt_red(ap, mp, sent, do_free_partials, opt);

					//DEBUG
					//printf("RED\n");

					continue;
				}
			}
		}

		// check FLIP
		if (as.acts[FLIP] && ap->intern_synt_deproj != DEPROJ_EXHAUSTIVE) {
			opt = _action_synt_flip(ap, mp, sent, do_free_partials, opt);

			//DEBUG
			printf("(SYNT) FLIP\n");

			continue;
		}

		//=====================  WORD PREDICTION =============================================
		if (as.acts[SHIFT]) {
			//create sequence of shift operation
			//update queue and stack
			opt = create_option(SYNT_STEP, 0, opt->previous_act, SHIFT, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
					&mp->out_link_pos,  get_pos_out_num());
			TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
			set_links(ap, mp, opt, sent);

			opt = create_word_prediction_seq(ap, mp, sent, opt, do_free_partials);

			//DEBUG
			//printf("SHIFT\n");
			continue;
		}




		//=====================  SRL  ======================================================

		if (ap->is_srl_early_reduce && as.acts[SRL_RED]) {
			int srl_s = st_peek(&opt->srl_stack);
			if (srl_everything_complete(opt->ps, sent, srl_s)) {

				opt = _action_srl_red(ap, mp, sent, do_free_partials, opt);

				//DEBUG
				//                    printf("SRL_RED\n");

				continue;
			}
		}

		//check SRL_LA
		int q_bank = sent->bank[opt->queue];
		///if (q_bank >= 0)///
		///  printf("srl_la 0: %d %d; %d %d\n", q_bank, as.acts[SRL_LA[q_bank]], st_peek(&opt->srl_stack), opt->queue);///
		if (q_bank >= 0 && as.acts[SRL_LA[q_bank]]) {
			int d = st_peek(&opt->srl_stack);
			int h = opt->queue;
			int role = next_srl_role(0, sent, h, d);
			///printf("srl_la 1: %d %d %d\n", d, h, role);///
			if (role >= 0) {
				int i = 0;
				for (; role >= 0; role = next_srl_role(i, sent, h, d)) {
					i++;
					//create sequence of SRL_LA operations
					//update queue and stack
					opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_LA[q_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
							&mp->out_link_sem_la_label[q_bank], mp->role_num[q_bank]);
					TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
					set_links(ap, mp, opt, sent);

					opt = create_option(SRL_STEP, 1, SRL_LA[q_bank], role, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
							&mp->out_link_act, ACTION_NUM);
					TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
					ps_add_link(opt->ps, h, d, role);
					opt->ps->right_connections_num[d]++;
					set_links(ap, mp, opt, sent);

					//DEBUG
					//printf("SRL_LA[%d]\n", q_bank);
				}

				continue;
			}
		}
		q_bank = -1;

		//check SRL_RA
		int s_bank = sent->bank[st_peek(&opt->srl_stack)];
		if (s_bank >= 0 && as.acts[SRL_RA[s_bank]]) {
			int d = opt->queue;
			int h = st_peek(&opt->srl_stack);
			int role =  next_srl_role(0, sent, h, d);
			///printf("srl_ra: %d %d %d\n", d, h, role);///
			//when agrees
			if (role >= 0) {
				int i = 0;
				for (; role >= 0; role = next_srl_role(i, sent, h, d)) {
					ASSERT(i == 0);
					i++;
					//create sequence of RA operations
					//update queue and stack
					opt = create_option(SRL_STEP, 0, opt->previous_act, SRL_RA[s_bank], opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt),  ps_clone(opt->ps),
							&mp->out_link_sem_ra_label[s_bank], mp->role_num[s_bank]);
					TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
					set_links(ap, mp, opt, sent);


					opt = create_option(SRL_STEP, 1, SRL_RA[s_bank], role, opt, opt->period, &opt->stack,  &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
							&mp->out_link_act, ACTION_NUM);
					TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
					ps_add_link(opt->ps, h, d, role);
					opt->ps->right_connections_num[h]++;
					set_links(ap, mp, opt, sent);

					//DEBUG
					//printf("SRL-RA[%d]\n", s_bank);
				}  // role

				continue;
			}
		}

		if (as.acts[SRL_FLIP] && ap->intern_srl_deproj == DEPROJ_EXHAUSTIVE) {
			int srl_s = st_peek(&opt->srl_stack);
			int srl_s_already_conns = opt->ps->right_connections_num[srl_s];

			int srl_s_under = st_look(&opt->srl_stack, 1);
			int srl_s_under_already_conns = opt->ps->right_connections_num[srl_s_under];


			int top_is_usl = (sent->srl_right_degree[srl_s] == srl_s_already_conns);
			int under_top_is_usl = (sent->srl_right_degree[srl_s_under] == srl_s_under_already_conns);

			if (ap->is_srl_early_reduce || (!top_is_usl && !under_top_is_usl)  )  {
				// srl_s_under will be active earlier than srl_s
				if (lexicograph_ignore_double_entries_comp(
						sent->srl_right_indices[srl_s_under] + srl_s_under_already_conns,
						sent->srl_right_degree[srl_s_under] - srl_s_under_already_conns,
						sent->srl_right_indices[srl_s] + srl_s_already_conns,
						sent->srl_right_degree[srl_s] - srl_s_already_conns) < 0) {

					opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt);

					//DEBUG
					//TMP printf("SRL_FLIP\n");
					continue;
				}
			} else {
				// if a top word can be reduce from the top
				if (top_is_usl) {
					int first_usf = get_useful(&opt->srl_stack, 1, opt->ps->right_connections_num, sent->srl_right_degree);
					if (first_usf > 0) {
						// first 'useful' word in the stack should be attached to front of queue -- start remioving useless words
						// next words will be removed on the next rounds
						int next_connection = sent->srl_right_indices[first_usf][opt->ps->right_connections_num[first_usf]];
						if (next_connection  == opt->queue) {
							ASSERT(as.acts[SRL_RED]);
							opt = _action_srl_red(ap, mp, sent, do_free_partials, opt);
							continue;
							//DEBUG
							//printf("SRL_RED, useless reduction\n");
						}
					}
				}  else {
					// if
					int second_usf = get_useful(&opt->srl_stack, 1, opt->ps->right_connections_num, sent->srl_right_degree);

					ASSERT(second_usf != srl_s_under);

					if (second_usf > 0) {
						int second_usf_already_conns = opt->ps->right_connections_num[second_usf];

						if (lexicograph_ignore_double_entries_comp(
								sent->srl_right_indices[second_usf] + second_usf_already_conns,
								sent->srl_right_degree[second_usf] - second_usf_already_conns,
								sent->srl_right_indices[srl_s] + srl_s_already_conns,
								sent->srl_right_degree[srl_s] - srl_s_already_conns) < 0) {

							opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt);
							as = get_next_actions(ap, mp, opt, sent);
							set_mask(mp, opt, &as);
							ASSERT(as.acts[SRL_RED]);
							opt = _action_srl_red(ap, mp, sent, do_free_partials, opt);
							// DEBUG
							printf("SRL_FLIP, followed by SRL_RED\n");
							//printf("SRL_RED, preceded by SRL_FLIP\n");

							continue;
						}
					}
				}   // !top_is_usl
			} // !ap->is_synt_early_reduce
		}  // FLIP

		//check SRL_SWITCH
		if (as.acts[SRL_SWITCH]) {
			int q = opt->queue;
			if (srl_left_part_complete(opt->ps, sent, q)) {

				opt = create_option(SYNT_STEP, 1, SRL_SWITCH, SRL_SWITCH, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue,
						pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM);
				TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
				set_links(ap, mp, opt, sent);

				//DEBUG
				//printf("SRL_SWITCH\n");
				continue;
			}
		}

		//check SRL_RED
		if (!ap->is_srl_early_reduce  && as.acts[SRL_RED]) {
			int srl_s = st_peek(&opt->srl_stack);
			if (srl_everything_complete(opt->ps, sent, srl_s)) {
				opt = _action_srl_red(ap, mp, sent, do_free_partials, opt);
				//DEBUG
				//printf("SRL_RED\n");

				continue;
			}
		}

		if (as.acts[PREDIC_NO]) {
			int q = opt->queue;
			if (sent->sense[q] < 0) {
				opt = create_option(SRL_STEP, 1, PREDIC_NO, PREDIC_NO, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue,
						pt_clone(opt->pt), ps_clone(opt->ps), &mp->out_link_act, ACTION_NUM);
				TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));

				set_links(ap, mp, opt, sent);

				//DEBUG
				//printf("PREDIC_NO\n");
				continue;
			}
		}
		if (as.acts[PREDIC_YES]) {
			int q = opt->queue;
			int q_sense = sent->sense[q];
			if (q_sense >= 0) {

				int q_bank = sent->bank[q];
				int q_lemma = sent->lemma[q];

				//create sequence of predicate prediction operations
				opt = create_option(SRL_STEP, 0, opt->previous_act, PREDIC_YES, opt, opt->period, &opt->stack, &opt->srl_stack, opt->queue, pt_clone(opt->pt),  ps_clone(opt->ps),
						&mp->out_link_sense[q_bank][q_lemma][0], mp->sense_num[q_bank][q_lemma]);
				TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
				set_links(ap, mp, opt, sent);


				opt = create_option(SRL_STEP, 1, PREDIC_YES, q_sense, opt, opt->period, &opt->stack,  &opt->srl_stack, opt->queue, pt_clone(opt->pt), ps_clone(opt->ps),
						&mp->out_link_act, ACTION_NUM);
				TRY_FREE_PARTIALS(&(opt->previous_option->pt), &(opt->previous_option->ps));
				ps_set_sense(opt->ps, q, q_sense);
				set_links(ap, mp, opt, sent);

				//DEBUG
				//printf("PREDIC_YES\n");
				continue;
			}
		}
		if (as.acts[SRL_FLIP] && ap->intern_srl_deproj != DEPROJ_EXHAUSTIVE) {
			opt = _action_srl_flip(ap, mp, sent, do_free_partials, opt);
			//DEBUG
			//printf("SRL_FLIP\n");

			continue;
		}

		// if stalled in syntactic part
		if (IS_NOW_SYNTAX(opt->previous_act)) {
			//DEBUG
			printf("STALLED IN SYNTAX\n");

		} else {
			//DEBUG
			printf("STALLED IN SRL\n");
		}

		ASSERT(0);
		if (IS_NOW_SYNTAX(opt->previous_act)) {
			fprintf(stderr, "(Syntax) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n");
			printf("(Syntax) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n");
		} else {
			//TMP fprintf(stderr, "(SRL) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n");
			//TMP printf("(SRL) Problem: wrong parsing order or in input file (e.g. NON-PROJECTIVITY): can't make an action\n");
		}
		fprintf(stderr, "Try changing PARSING_ORDER in the configuration file to a larger value\n");
		//        printf("%s\n", print_sent(sent, 1));
		//TODO this should be a fatal error
		fprintf(stderr, "Warning: returning partial derivation\n");
		DEF_ALLOC(as_final, ACTION_SET);
		bzero(as_final, sizeof(ACTION_SET));
		set_mask(mp, opt, as_final);
		free(as_final);

		TRY_FREE_PARTIALS(&(opt->pt), &(opt->ps));
		return opt;
		//TODO restore!
		//exit(1);
	}

	//DEBUG
	//TMP printf("==== SENT FINISHED ===== \n");

	if (!check_pt_t_equality(opt->pt, sent)) {
		fprintf(stderr, "Presumably: bug in parsing or in input file (e.g. NON-PROJECTIVITY): resulting syntactic trees do not match\n");
		exit(1);
	}
	if (!check_ps_t_equality(opt->ps, sent)) {
		fprintf(stderr, "Presumably: bug in SRL parsing or in input file (e.g. NON-PROJECTIVITY): resulting predicate argument structures do not match\n");

	}


	DEF_ALLOC(as, ACTION_SET);
	bzero(as, sizeof(ACTION_SET));
	set_mask(mp, opt, as);
	free(as);

	TRY_FREE_PARTIALS(&(opt->pt), &(opt->ps));



	return opt;
}
Example #7
0
static 
arginit (char **vec)
{
	int	    argp;
	char   *ap;
	char  **argptr,
		  *args[4];
	struct TSAPaddr *ta = NULL;

	if (pgmname = rindex (*vec, '/'))
		pgmname++;
	if (pgmname == NULL || *pgmname == NULL)
		pgmname = *vec;

	isodetailor (pgmname, 0);
	ll_hdinit (pgm_log, pgmname);

	quipu_syntaxes ();

	argp = 0;
	args[argp++] = pgmname;
	for (argptr = vec, argptr++; ap = *argptr; argptr++) {
		if (*ap == '-')
			switch (*++ap) {
			case 'a':
			case 'u':
			case 'p':
				if ((ap = *++argptr) == NULL || *ap == '-')
					break;
				continue;

			case 'c':
				if ((ap = *++argptr) == NULL || *ap == '-')
					break;
				args[argp++] = "-c";
				args[argp++] = ap;
				break;

			default:
				continue;
			}

		break;
	}
	args[argp] = NULLCP;

	dsap_init (&argp, (argptr = args, &argptr));

	userdn = NULLDN, passwd[0] = NULL;
	for (vec++; ap = *vec; vec++) {
		if (*ap == '-')
			switch (*++ap) {
			case 'a':
				if ((ap = *++vec) == NULL || *ap == '-')
					adios (NULLCP, "usage: %s -a address", pgmname);
				if ((ta = str2taddr (ap)) == NULLTA)
					adios (NULLCP, "bad address \"%s\"", ap);
				continue;

			case 'b':
				prebind++;
				continue;

			case 'd':
				debug++;
				continue;

			case 'c':
				if ((ap = *++vec) == NULL || *ap == '-')
					adios (NULLCP, "usage: %s -c DSA-name-or-address",
						   pgmname);
				continue;

			case 'u':
				if ((ap = *++vec) == NULL || *ap == '-')
					adios (NULLCP, "usage: %s -u username", pgmname);
				if ((userdn = str2dn (*ap != '@' ? ap : ap + 1)) == NULLDN)
					adios (NULLCP, "invalid DN for username: %s", ap);
				bzero ((char *) ap, strlen (ap));
				continue;

			case 'p':
				if ((ap = *++vec) == NULL || *ap == '-')
					adios (NULLCP, "usage: %s -p passwd", pgmname);
				 strcpy (passwd, ap);
				bzero ((char *) ap, strlen (ap));
				continue;

			default:
				adios (NULLCP, "unknown switch -%s", ap);
			}

		adios (NULLCP, "usage: %s [switches]", pgmname);
	}

	if (ta == NULL && (ta = str2taddr (ns_address)) == NULLTA)
		adios (NULLCP, "bad default address \"%s\"", ns_address);
	tas = *ta;		/* struct copy */

	if ((nps = ps_alloc (str_open)) == NULLPS)
		adios (NULLCP, "ps_alloc: out of memory");
	if (str_setup (nps, NULLCP, 0, 0) == NOTOK)
		adios (NULLCP, "str_setup: %s", ps_error (ps -> ps_errno));
}