Esempio n. 1
0
u_ocor(char *pre, char *pos)
{

 char *q, *get_rand();
 int i, u, n, j, max, seq, nseq;
 OSET r, x, *p = &set_aux; 
 
 seq = 0;
 troca = OP_1_CAST;
 por = OP_1_CAST;

 Operador = U_OCOR;
 if (g_tab_operador[Operador].percent==0) return;

  set_new_inic(&r,"char\0unsigned char\0int\0float\0unsigned\0unsigned int\0short\0short int\0long\0long int\0unsigned long\0unsigned long int\0double\0long float\0");

   set_new_inic(&x, "char\0unsigned char\0int\0float\0unsigned\0short\0long\0unsigned long\0double\0");

 
 u = sym.no;
 max = g_tab_operador[Operador].maximum; 
 if (max ==0) max--;
 

   if (expre_pos.topo >= 0)
     {
       ex_aux = expre_pos;

       for (i = 0; i <= ex_aux.topo; i++)
         {		/* procura operador do tipo desejado */
	   if (ex_aux.no[i].tipo != troca ||
		 set_inn(&r, NOME((&ex_aux), i)) < 0) 
			continue;

 
           set_dup(&x, p);
           nseq = set_card(p);
           

           for (n = max, q = get_rand(p, Operador); 
		q != NULL && n != 0;	q = get_rand(p, Operador),n--)
            {	/* troca pelos outros operadores */

               	if (expre_pos.no[i].tipo == por && 
                    strcmp(NOME((&expre_pos), i), q) == 0)
		{
			n++;
		 	continue;
		}
		seq = set_inn(&x, q);

		expre_pos.no[i].tipo = por;
		expre_pos.no[i].nome = expre_pos.livre;
		strcpy(&(expre_pos.buf[expre_pos.livre]), q);
		expre_pos.livre += strlen(q)+1;
 
		if (expre_valida(&expre_pos))
		{
		  monta_in_expre(&expre_pos, 0, expre_pos.topo); /* monta infixa */
		  strcpy(bufmen, pre);
		  strcat(bufmen, expre_pos.buf);
                  sprintf(bufmen, "%s %s ",pre, expre_pos.buf);
		  strcat(bufmen, pos);
		  add_descritor(sym.inicio, sym.comprimento, u, bufmen);
  		  sorteia_grupoU(Operador, Seq[Operador] + seq);
	         }
		 else
		   n++;
		 expre_pos = ex_aux;
            }
	    set_free(p); 
            Seq[Operador] += nseq;
           }
	set_free(&r); set_free(&x);

      }
}
Esempio n. 2
0
/* Join two sets according to operator op and flags op_flags.
 * op can be:
 *	'|' (or):	the union between the two sets is returned,
 *		 	eliminating duplicates
 *	'&' (and):	the intersection between the two sets
 *			is returned
 *	'+' (add):	the inner product of the two sets is returned,
 *			namely a set containing the concatenation of
 *			all combinations of the two sets members,
 *			except for duplicates.
 * The two sets are disposed of according to the flags as described
 * for slap_set_dispose().
 */
BerVarray
slap_set_join(
	SetCookie	*cp,
	BerVarray	lset,
	unsigned	op_flags,
	BerVarray	rset )
{
	BerVarray	set;
	long		i, j, last, rlast;
	unsigned	op = ( op_flags & SLAP_SET_OPMASK );

	set = NULL;
	switch ( op ) {
	case '|':	/* union */
		if ( lset == NULL || BER_BVISNULL( &lset[ 0 ] ) ) {
			if ( rset == NULL ) {
				if ( lset == NULL ) {
					set = cp->set_op->o_tmpcalloc( 1,
							sizeof( struct berval ),
							cp->set_op->o_tmpmemctx );
					BER_BVZERO( &set[ 0 ] );
					goto done2;
				}
				set = set_dup( cp, lset, SLAP_SET_LREF2REF( op_flags ) );
				goto done2;
			}
			slap_set_dispose( cp, lset, SLAP_SET_LREF2REF( op_flags ) );
			set = set_dup( cp, rset, SLAP_SET_RREF2REF( op_flags ) );
			goto done2;
		}
		if ( rset == NULL || BER_BVISNULL( &rset[ 0 ] ) ) {
			slap_set_dispose( cp, rset, SLAP_SET_RREF2REF( op_flags ) );
			set = set_dup( cp, lset, SLAP_SET_LREF2REF( op_flags ) );
			goto done2;
		}

		/* worst scenario: no duplicates */
		rlast = slap_set_size( rset );
		i = slap_set_size( lset ) + rlast + 1;
		set = cp->set_op->o_tmpcalloc( i, sizeof( struct berval ), cp->set_op->o_tmpmemctx );
		if ( set != NULL ) {
			/* set_chase() depends on this routine to
			 * keep the first elements of the result
			 * set the same (and in the same order)
			 * as the left-set.
			 */
			for ( i = 0; !BER_BVISNULL( &lset[ i ] ); i++ ) {
				if ( op_flags & SLAP_SET_LREFVAL ) {
					ber_dupbv_x( &set[ i ], &lset[ i ], cp->set_op->o_tmpmemctx );

				} else {
					set[ i ] = lset[ i ];
				}
			}

			/* pointers to values have been used in set - don't free twice */
			op_flags |= SLAP_SET_LREFVAL;

			last = i;

			for ( i = 0; !BER_BVISNULL( &rset[ i ] ); i++ ) {
				int	exists = 0;

				for ( j = 0; !BER_BVISNULL( &set[ j ] ); j++ ) {
					if ( bvmatch( &rset[ i ], &set[ j ] ) )
					{
						if ( !( op_flags & SLAP_SET_RREFVAL ) ) {
							cp->set_op->o_tmpfree( rset[ i ].bv_val, cp->set_op->o_tmpmemctx );
							rset[ i ] = rset[ --rlast ];
							BER_BVZERO( &rset[ rlast ] );
							i--;
						}
						exists = 1;
						break;
					}
				}

				if ( !exists ) {
					if ( op_flags & SLAP_SET_RREFVAL ) {
						ber_dupbv_x( &set[ last ], &rset[ i ], cp->set_op->o_tmpmemctx );

					} else {
						set[ last ] = rset[ i ];
					}
					last++;
				}
			}

			/* pointers to values have been used in set - don't free twice */
			op_flags |= SLAP_SET_RREFVAL;

			BER_BVZERO( &set[ last ] );
		}
		break;

	case '&':	/* intersection */
		if ( lset == NULL || BER_BVISNULL( &lset[ 0 ] )
			|| rset == NULL || BER_BVISNULL( &rset[ 0 ] ) )
		{
			set = cp->set_op->o_tmpcalloc( 1, sizeof( struct berval ),
					cp->set_op->o_tmpmemctx );
			BER_BVZERO( &set[ 0 ] );
			break;

		} else {
			long llen, rlen;
			BerVarray sset;

			llen = slap_set_size( lset );
			rlen = slap_set_size( rset );

			/* dup the shortest */
			if ( llen < rlen ) {
				last = llen;
				set = set_dup( cp, lset, SLAP_SET_LREF2REF( op_flags ) );
				lset = NULL;
				sset = rset;

			} else {
				last = rlen;
				set = set_dup( cp, rset, SLAP_SET_RREF2REF( op_flags ) );
				rset = NULL;
				sset = lset;
			}

			if ( set == NULL ) {
				break;
			}

			for ( i = 0; !BER_BVISNULL( &set[ i ] ); i++ ) {
				for ( j = 0; !BER_BVISNULL( &sset[ j ] ); j++ ) {
					if ( bvmatch( &set[ i ], &sset[ j ] ) ) {
						break;
					}
				}

				if ( BER_BVISNULL( &sset[ j ] ) ) {
					cp->set_op->o_tmpfree( set[ i ].bv_val, cp->set_op->o_tmpmemctx );
					set[ i ] = set[ --last ];
					BER_BVZERO( &set[ last ] );
					i--;
				}
			}
		}
		break;

	case '+':	/* string concatenation */
		i = slap_set_size( rset );
		j = slap_set_size( lset );

		/* handle empty set cases */
		if ( i == 0 || j == 0 ) {
			set = cp->set_op->o_tmpcalloc( 1, sizeof( struct berval ),
					cp->set_op->o_tmpmemctx );
			if ( set == NULL ) {
				break;
			}
			BER_BVZERO( &set[ 0 ] );
			break;
		}

		set = cp->set_op->o_tmpcalloc( i * j + 1, sizeof( struct berval ),
				cp->set_op->o_tmpmemctx );
		if ( set == NULL ) {
			break;
		}

		for ( last = 0, i = 0; !BER_BVISNULL( &lset[ i ] ); i++ ) {
			for ( j = 0; !BER_BVISNULL( &rset[ j ] ); j++ ) {
				struct berval	bv;
				long		k;

				/* don't concatenate with the empty string */
				if ( BER_BVISEMPTY( &lset[ i ] ) ) {
					ber_dupbv_x( &bv, &rset[ j ], cp->set_op->o_tmpmemctx );
					if ( bv.bv_val == NULL ) {
						ber_bvarray_free_x( set, cp->set_op->o_tmpmemctx );
						set = NULL;
						goto done;
					}

				} else if ( BER_BVISEMPTY( &rset[ j ] ) ) {
					ber_dupbv_x( &bv, &lset[ i ], cp->set_op->o_tmpmemctx );
					if ( bv.bv_val == NULL ) {
						ber_bvarray_free_x( set, cp->set_op->o_tmpmemctx );
						set = NULL;
						goto done;
					}

				} else {
					bv.bv_len = lset[ i ].bv_len + rset[ j ].bv_len;
					bv.bv_val = cp->set_op->o_tmpalloc( bv.bv_len + 1,
							cp->set_op->o_tmpmemctx );
					if ( bv.bv_val == NULL ) {
						ber_bvarray_free_x( set, cp->set_op->o_tmpmemctx );
						set = NULL;
						goto done;
					}
					AC_MEMCPY( bv.bv_val, lset[ i ].bv_val, lset[ i ].bv_len );
					AC_MEMCPY( &bv.bv_val[ lset[ i ].bv_len ], rset[ j ].bv_val, rset[ j ].bv_len );
					bv.bv_val[ bv.bv_len ] = '\0';
				}

				for ( k = 0; k < last; k++ ) {
					if ( bvmatch( &set[ k ], &bv ) ) {
						cp->set_op->o_tmpfree( bv.bv_val, cp->set_op->o_tmpmemctx );
						break;
					}
				}

				if ( k == last ) {
					set[ last++ ] = bv;
				}
			}
		}
		BER_BVZERO( &set[ last ] );
		break;

	default:
		break;
	}

done:;
	if ( lset ) slap_set_dispose( cp, lset, SLAP_SET_LREF2REF( op_flags ) );
	if ( rset ) slap_set_dispose( cp, rset, SLAP_SET_RREF2REF( op_flags ) );

done2:;
	if ( LogTest( LDAP_DEBUG_ACL ) ) {
		if ( BER_BVISNULL( set ) ) {
			Debug( LDAP_DEBUG_ACL, "  ACL set: empty\n", 0, 0, 0 );

		} else {
			for ( i = 0; !BER_BVISNULL( &set[ i ] ); i++ ) {
				Debug( LDAP_DEBUG_ACL, "  ACL set[%ld]=%s\n", i, set[i].bv_val, 0 );
			}
		}
	}

	return set;
}
Esempio n. 3
0
expr()
#endif
{
	zzRULE;
	zzBLOCK(zztasp1);
	zzMake0;
	{
	zzaRet.l = new_nfa_node(); zzaRet.r = new_nfa_node();   
	if ( (LA(1)==L_BRACK) ) {
		zzmatch(L_BRACK); zzCONSUME;
		atom_list();
		zzmatch(R_BRACK);
		
		(zzaRet.l)->trans[0] = zzaRet.r;
		(zzaRet.l)->label = set_dup(zzaArg(zztasp1,2 ).label);
		set_orin(&used_chars,(zzaRet.l)->label);
 zzCONSUME;

	}
	else {
		if ( (LA(1)==NOT) ) {
			zzmatch(NOT); zzCONSUME;
			zzmatch(L_BRACK); zzCONSUME;
			atom_list();
			zzmatch(R_BRACK);
			
			(zzaRet.l)->trans[0] = zzaRet.r;
			(zzaRet.l)->label = set_dif(normal_chars,zzaArg(zztasp1,3 ).label);
			set_orin(&used_chars,(zzaRet.l)->label);
 zzCONSUME;

		}
		else {
			if ( (LA(1)==L_PAR) ) {
				zzmatch(L_PAR); zzCONSUME;
				reg_expr();
				zzmatch(R_PAR);
				
				(zzaRet.l)->trans[0] = zzaArg(zztasp1,2 ).l;
				(zzaArg(zztasp1,2 ).r)->trans[1] = zzaRet.r;
 zzCONSUME;

			}
			else {
				if ( (LA(1)==L_BRACE) ) {
					zzmatch(L_BRACE); zzCONSUME;
					reg_expr();
					zzmatch(R_BRACE);
					
					(zzaRet.l)->trans[0] = zzaArg(zztasp1,2 ).l;
					(zzaRet.l)->trans[1] = zzaRet.r;
					(zzaArg(zztasp1,2 ).r)->trans[1] = zzaRet.r;
 zzCONSUME;

				}
				else {
					if ( (setwd2[LA(1)]&0x40) ) {
						atom();
						
						(zzaRet.l)->trans[0] = zzaRet.r;
						(zzaRet.l)->label = set_dup(zzaArg(zztasp1,1 ).label);
						set_orin(&used_chars,(zzaRet.l)->label);
					}
					else {zzFAIL(1,zzerr5,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
				}
			}
		}
	}
	zzEXIT(zztasp1);
	return;
fail:
	zzEXIT(zztasp1);
	zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
	zzresynch(setwd2, 0x80);
	}
}
Esempio n. 4
0
u_cccr(char *pre, char *pos)
{
char    *q, *get_rand();
int     i, j, n, max, seq, nseq;
int     u, k, t;
OSET    *r, *p = &set_aux, *get_const_set();

   Operador = U_CCCR;
   if (g_tab_operador[Operador].percent == 0)
        return;

   u = sym.no;
   max = g_tab_operador[Operador].maximum;
   if (max == 0)
        max--;

   if (expre_pos.topo >= 0)
   {

       expre_completa(&expre_pos);     /* completa expressao */
       ex_aux = expre_pos;

       for (i = 0; i <= expre_pos.topo; i++)
       {            /* procura referencia do tipo desejado */

           if (! EH_CONST(expre_pos.no[i].tipo) || 
		expre_pos.no[i].tipo == STRING)    /* compatibility to 1.4 */
               continue;

           expre_exec_tipo(&expre_pos, expre_pos.no[i].final, i, tipo, ptar);

           r = get_const_set(tipo, ptar, &t);
	   t = expre_pos.no[i].tipo;

           set_dup(r, p);
           nseq = set_card(p);
           for (n = max,q = get_rand(p, Operador);
                     q != NULL && n != 0; q = get_rand(p, Operador), n--)
           {
                seq = set_inn(r, q);
                expre_substitui(&expre_pos, i, q, t);
                if (! expre_valida(&expre_pos))
                {
                   nseq = 0;
                   expre_pos = ex_aux;
                   break;
                }
                if (compara_expre(&expre_pos, &ex_aux))
                {
                   n++;
                   expre_pos = ex_aux;
                   continue;
                }

                monta_in_expre(&expre_pos, 0, expre_pos.topo);
                sprintf(bufmen, "%s %s ", pre, expre_pos.buf);
                strcat(bufmen, pos);
                add_descritor(sym.inicio, sym.comprimento, u, bufmen);
                sorteia_grupoU(Operador, Seq[Operador]+seq);

                expre_pos = ex_aux;

           }
           set_free(p);
           Seq[Operador] += nseq;
        }
   }