コード例 #1
0
ファイル: xparse.c プロジェクト: feifei1987720/3535
static int validate_tag(tag_t *tag)
{
	int start_len, end_len;
	char *str;
	char start_name[128];
	char end_name[128];
	//int i,j;
	//char *ch,*ch1;

	//fprintf(stderr,"\r\nInside validate_tag with tag->start_len:%d & tag->start_name\n",tag->start_len);
	//ch = tag->start_name;
	//for (i=0;i<tag->start_len;i++ )
	//{
	// fprintf(stderr,"%c",*ch++);
	//}

	start_len = tag->start_len-2; // ignore open and closing braces

	if(tag->attr_len) // ignore space + attributes
		start_len = start_len - (tag->attr_len+1);
	strncpy(start_name, tag->start_name + 1, start_len);
	start_name[start_len] = 0x00;
	/* start tag must be valid here */
	if(validate_start_tag(tag->start_name, tag->start_len))
		return -1;

	//fprintf(stderr,"\r\nInside validate_tag with tag->end_len:%d & tag->end_name\n",tag->end_len);
	//ch1 = tag->end_name;
	//for (j=0;j<tag->end_len;j++ )
	//{
	//  fprintf(stderr,"%c",*ch1++);
	//}

	if(!tag->empty) {
		end_len = tag->end_len-3; // ignore braces and /
		strncpy(end_name, tag->end_name+2, end_len);
		end_name[end_len] = 0x00;

		if(tag->end_name[1] != '/') {
			if(tag->value_len == 0)
				return 1;	/* no match, treat as a child */
			return -6;		/* value with no end tag is incorrect */
		}
		if(strcmp(start_name, end_name))
			return -5;   /* start an end tag don't match */
	}

	if(validate_attributes(tag->attr_name, tag->attr_len))
		return -2;

	if(validate_value(tag->value_name, tag->value_len))
		return -3;

	if(validate_end_tag(tag->end_name, tag->end_len))
		return -4;

	if(start_len) {
		str = malloc(start_len+1);
		if(!str) return -5;
		memcpy(str, start_name, start_len);
		str[start_len] = 0x00;
		tag->name = str;
	}

	if(tag->value_len) {
		str = malloc(tag->value_len+1);
		if(!str) return -6;
		memcpy(str, tag->value_name, tag->value_len);
		str[tag->value_len] = 0x00;
		tag->value = str;
	}

	if(tag->attr_len) {
		str = malloc(tag->attr_len+1);
		if(!str) return -7;
		memcpy(str, tag->attr_name, tag->attr_len);
		str[tag->attr_len] = 0x00;
		tag->attr = str;
	}

	return 0;  /* match */
}
コード例 #2
0
ファイル: fd_attribs.c プロジェクト: OrangeTide/xforms
int
change_object( FL_OBJECT * obj,
               int         all )
{
    FL_OBJECT *retobj;
    FD_generic_attrib *ui = fd_generic_attrib;
    FL_FORM * spec_form = NULL;

    attrib_init( ui );

    /* Save current attributes for later restore */

    curobj = obj;
    save_edited_object( obj );

    /* Show only required parts */

    if ( all )
    {
        fl_show_object( ui->labelobj  );
        fl_show_object( ui->scobj     );
        fl_show_object( ui->nameobj   );
        fl_show_object( ui->cbnameobj );
        fl_show_object( ui->argobj    );

        if ( ( spec_form = create_spec_form( curobj ) ) )
        {
            FL_OBJECT *t;

            t = fl_addto_tabfolder( fd_attrib->attrib_folder,
                                    "Spec", spec_form );
            fl_set_object_shortcut( t, "#S", 1 );
        }
    }
    else
    {
        fl_hide_object( ui->labelobj  );
        fl_hide_object( ui->scobj     );
        fl_hide_object( ui->nameobj   );
        fl_hide_object( ui->cbnameobj );
        fl_hide_object( ui->argobj    );
    }

    /* Show attributes of the current object */

    show_attributes( obj );

    /* Do interaction */

    fl_deactivate_all_forms( );

    /* Disable selection */

    no_selection = 1;

    fl_show_form( fd_attrib->attrib, FL_PLACE_GEOMETRY, FL_FULLBORDER,
                  "Attributes" );
    fl_set_app_mainform( fd_attrib->attrib );

    /* Both cancel and readyobj should have their own callbacks, so we don't
       need to call fl_do_forms(), but since attribute editing can't be
       invoked for more than one item at a time we need to block the
       process_xevent. TODO */

    do
    {
        XEvent xev;

        retobj = fl_do_forms( );
        if ( retobj == FL_EVENT )
            fl_XNextEvent( &xev );
    } while ( ! (    (    retobj == fd_attrib->readyobj
                       && validate_attributes( curobj ) )
                  || retobj == fd_attrib->cancelobj ) );

    if ( retobj == fd_attrib->cancelobj )
    {
        restore_edited_object( obj );
        redraw_the_form( 0 );
    }
    else
    {
        reread_spec_form( obj );
        readback_attributes( obj );
        spec_to_superspec( obj );
    }

    cleanup_saved_object( );

    fl_set_app_mainform( fd_control->control );
    fl_set_folder_bynumber( fd_attrib->attrib_folder, 1 );
    if ( spec_form )
        fl_delete_folder( fd_attrib->attrib_folder, spec_form );
    fl_hide_form( fd_attrib->attrib );
    fl_activate_all_forms( );

    no_selection = 0;

    return retobj == fd_attrib->readyobj;
}