示例#1
0
static html_valid_status_t
html_valid_set_option (html_valid_t * htv, SV * option, SV * value)
{
    TidyOption to;
    TidyOptionType tot;
    TidyOptionId ti;
    const char * coption;
    STRLEN coption_length;
    CHECK_INIT (htv);
    coption = SvPV (option, coption_length);
    to = tidyGetOptionByName(htv->tdoc, coption);
    if (to == 0) {
	warn ("unknown option %s", coption);
	return html_valid_unknown_option;
    }
    ti = tidyOptGetId (to);
    tot = tidyOptGetType (to);
    switch (tot) {
    case TidyString:
	CALL (set_string_option (htv, coption, ti, value));
	break;
    case TidyInteger:
	CALL (set_number_option (htv, coption, ti, value));
	break;
    case TidyBoolean:
	tidyOptSetBool (htv->tdoc, ti, SvTRUE (value));
	break;
    default:
	fprintf (stderr, "%s:%d: bad option type %d from tidy library.\n",
		 __FILE__, __LINE__, tot);
	return html_valid_bad_option_type;
    }
    return html_valid_ok;
}
示例#2
0
文件: tidy.c 项目: CooCoooo/php-src
static void *php_tidy_get_opt_val(PHPTidyDoc *ptdoc, TidyOption opt, TidyOptionType *type)
{
	*type = tidyOptGetType(opt);

	switch (*type) {
		case TidyString: {
			char *val = (char *) tidyOptGetValue(ptdoc->doc, tidyOptGetId(opt));
			if (val) {
				return (void *) zend_string_init(val, strlen(val), 0);
			} else {
				return (void *) ZSTR_EMPTY_ALLOC();
			}
		}
			break;

		case TidyInteger:
			return (void *) (uintptr_t) tidyOptGetInt(ptdoc->doc, tidyOptGetId(opt));
			break;

		case TidyBoolean:
			return (void *) tidyOptGetBool(ptdoc->doc, tidyOptGetId(opt));
			break;
	}

	/* should not happen */
	return NULL;
}
示例#3
0
static Bool isAutoBool( TidyOption topt )
{
    TidyIterator pos;
    ctmbstr def;

    if ( tidyOptGetType( topt ) != TidyInteger)
        return no;

    pos = tidyOptGetPickList( topt );
    while ( pos )
    {
        def = tidyOptGetNextPick( topt, &pos );
        if (0==strcmp(def,"yes"))
           return yes;
    }
    return no;
}
示例#4
0
文件: tidy.c 项目: CooCoooo/php-src
static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value)
{
	TidyOption opt = tidyGetOptionByName(doc, optname);
	zval conv;

	ZVAL_COPY_VALUE(&conv, value);

	if (!opt) {
		php_error_docref(NULL, E_NOTICE, "Unknown Tidy Configuration Option '%s'", optname);
		return FAILURE;
	}

	if (tidyOptIsReadOnly(opt)) {
		php_error_docref(NULL, E_NOTICE, "Attempting to set read-only option '%s'", optname);
		return FAILURE;
	}

	switch(tidyOptGetType(opt)) {
		case TidyString:
			if (Z_TYPE(conv) != IS_STRING) {
				zval_copy_ctor(&conv);
				convert_to_string(&conv);
			}
			if (tidyOptSetValue(doc, tidyOptGetId(opt), Z_STRVAL(conv))) {
				if (Z_TYPE(conv) != Z_TYPE_P(value)) {
					zval_dtor(&conv);
				}
				return SUCCESS;
			}
			if (Z_TYPE(conv) != Z_TYPE_P(value)) {
				zval_dtor(&conv);
			}
			break;

		case TidyInteger:
			if (Z_TYPE(conv) != IS_LONG) {
				zval_copy_ctor(&conv);
				convert_to_long(&conv);
			}
			if (tidyOptSetInt(doc, tidyOptGetId(opt), Z_LVAL(conv))) {
				return SUCCESS;
			}
			break;

		case TidyBoolean:
			if (Z_TYPE(conv) != IS_LONG) {
				zval_copy_ctor(&conv);
				convert_to_long(&conv);
			}
			if (tidyOptSetBool(doc, tidyOptGetId(opt), Z_LVAL(conv))) {
				return SUCCESS;
			}
			break;

		default:
			php_error_docref(NULL, E_WARNING, "Unable to determine type of configuration option");
			break;
	}

	return FAILURE;
}
示例#5
0
int main (int argc, char **argv)
{
    TidyIterator pos;
    TidyDoc tdoc;
    int count;
    count = 0;

    tdoc = tidyCreate();    
    pos = tidyGetOptionList( tdoc );
    test (pos != 0, & count, "got a tdoc");
    while (1) {
        TidyOption to;
        TidyOptionType tot;
        const char * name;
        const char * option_default;
        int option_default_int;
        Bool option_default_bool;
        to = tidyGetNextOption(tdoc, &pos);
        if (to == 0) {
            break;
        }
        name = tidyOptGetName(to);
        test(name != 0, &count, "name is not null");
        tot = tidyOptGetType(to);
        if (name) {
            test(is_short_ascii_no_ws(name), &count, "name looks OK");
            printf("# %s %d\n", name, tot);
        }
        switch (tot) {
        case TidyString:
            test(1, &count, "got a good opt type");
            option_default = tidyOptGetDefault(to);
            //null seems to be allowed.
            //test (option_default != 0, & count, "string default is not null");
            if (option_default) {
                test(is_short_ascii_no_ws(option_default), &count,
                    "looks like a reasonable default string");
                printf("# %s default value is '%s'.\n", name, option_default);
            }
            break;
        case TidyInteger:
            test(1, &count, "got a good opt type");
            option_default_int = tidyOptGetDefaultInt(to);
            test(abs(option_default_int) < crazy_number, &count,
                "default number doesn't look strange");
            printf("# Integer type default value %d\n", option_default_int);
            break;
        case TidyBoolean:
            test(1, &count, "got a good opt type");
            option_default_bool = tidyOptGetDefaultInt(to);
            test(option_default_bool == 0 || option_default_bool == 1,
                &count, "boolean default is 0 or 1");
            printf("# boolean = %d\n", option_default_bool);
            break;
        default:
            test(0, &count, "got a good opt type");
            printf("# Unknown value for option type %d.\n", tot);
        }
    }
    // TAP plan
    printf ("1..%d\n", count);
    printf("\nTest used libtidy version %s, dated %s\n", tidyLibraryVersion(), tidyReleaseDate());
    if (argc > 1) {
        printf("\n Note this `test-get-options` app v.%s, date %s, does not take any commands!\n", TT_VERSION, TT_DATE);
        show_help();
        return 1;
    }

    return 0;
}
示例#6
0
static PyObject *parseString(PyObject *self, PyObject *args)
{
    char *cp;
    int i, len, list_size;
    TidyDoc tdoc;
    TidyOption option = TidyUnknownOption;
    PyObject *res = NULL, *arglist = NULL;
    PyObject *key_list = NULL, *item = NULL, *value = NULL;
    TidyBuffer output = {0};
    TidyBuffer errbuf = {0};

    if (!PyArg_ParseTuple(args, "s#|O", &cp, &len, &arglist))
        return NULL;

    if (arglist && !PyDict_Check(arglist))
    {
        PyErr_SetString(PyExc_TypeError, "Second argument must be a dictionary!");
        return NULL;
    }

    tdoc = tidyCreate();
    tidySetErrorBuffer(tdoc, &errbuf);

    if (!arglist) goto im_so_lazy; /* no args provided */

    key_list = PyDict_Keys(arglist);
    list_size = PyList_Size(key_list);

    for (i = 0; i < list_size; i++)
    {
        item = PyList_GetItem(key_list, i);
        value = PyDict_GetItem(arglist, item);
        Py_INCREF(item);
        Py_INCREF(value);

        option = tidyGetOptionByName(tdoc, PyString_AsString(item));

        if (option == TidyUnknownOption)
        {
            PyErr_Format(PyExc_KeyError, "Unknown tidy option '%s'", PyString_AsString(item));
            TDOC_RETURN();
        }

        switch (tidyOptGetType(option))
        {
            case TidyString:
                PY_TO_TIDY(String_Check, Value, String_AsString, "a String");
                break;
            case TidyInteger:
                PY_TO_TIDY(Int_Check, Int, Int_AsLong, "an Integer");
                break;
            case TidyBoolean:
                PY_TO_TIDY(Int_Check, Bool, Int_AsLong, "a Boolean or an Integer");
                break;
            default:
            {
                PyErr_Format(PyExc_RuntimeError,
                             "Something strange happened, there is no option type %d",
                             tidyOptGetType(option));
                TDOC_RETURN();
            }
        }
        Py_DECREF(item);
        Py_DECREF(value);
    }

 im_so_lazy:
    tidyParseString(tdoc, cp);
    tidyCleanAndRepair(tdoc);
    tidySaveBuffer(tdoc, &output);

    res = Py_BuildValue("s#", output.bp, output.size);
    tidyBufFree(&output);
    tidyBufFree(&errbuf);
    tidyRelease(tdoc);
    return res;
}
示例#7
0
/* Create description "d" related to "opt" */
static
void GetOption( TidyDoc tdoc, TidyOption topt, OptionDesc *d )
{
    TidyOptionId optId = tidyOptGetId( topt );
    TidyOptionType optTyp = tidyOptGetType( topt );

    d->name = tidyOptGetName( topt );
    d->cat = ConfigCategoryName( tidyOptGetCategory( topt ) );
    d->vals = NULL;
    d->def = NULL;
    d->haveVals = yes;

    /* Handle special cases first.
     */
    switch ( optId )
    {
    case TidyDuplicateAttrs:
    case TidySortAttributes:
    case TidyNewline:
    case TidyAccessibilityCheckLevel:
        d->type = "enum";
        d->vals = NULL;
        d->def =
            optId==TidyNewline ?
            "<em>Platform dependent</em>"
            :tidyOptGetCurrPick( tdoc, optId );
        break;

    case TidyDoctype:
        d->type = "DocType";
        d->vals = NULL;
        {
            ctmbstr sdef = NULL;
            sdef = tidyOptGetCurrPick( tdoc, TidyDoctypeMode );
            if ( !sdef || *sdef == '*' )
                sdef = tidyOptGetValue( tdoc, TidyDoctype );
            d->def = sdef;
        }
        break;

    case TidyInlineTags:
    case TidyBlockTags:
    case TidyEmptyTags:
    case TidyPreTags:
        d->type = "Tag names";
        d->vals = "tagX, tagY, ...";
        d->def = NULL;
        break;

    case TidyCharEncoding:
    case TidyInCharEncoding:
    case TidyOutCharEncoding:
        d->type = "Encoding";
        d->def = tidyOptGetEncName( tdoc, optId );
        if (!d->def)
            d->def = "?";
        d->vals = NULL;
        break;

        /* General case will handle remaining */
    default:
        switch ( optTyp )
        {
        case TidyBoolean:
            d->type = "Boolean";
            d->vals = "y/n, yes/no, t/f, true/false, 1/0";
            d->def = tidyOptGetCurrPick( tdoc, optId );
            break;

        case TidyInteger:
            if (isAutoBool(topt))
            {
                d->type = "AutoBool";
                d->vals = "auto, y/n, yes/no, t/f, true/false, 1/0";
                d->def = tidyOptGetCurrPick( tdoc, optId );
            }
            else
            {
                uint idef;
                d->type = "Integer";
                if ( optId == TidyWrapLen )
                    d->vals = "0 (no wrapping), 1, 2, ...";
                else
                    d->vals = "0, 1, 2, ...";

                idef = tidyOptGetInt( tdoc, optId );
                sprintf(d->tempdefs, "%u", idef);
                d->def = d->tempdefs;
            }
            break;

        case TidyString:
            d->type = "String";
            d->vals = NULL;
            d->haveVals = no;
            d->def = tidyOptGetValue( tdoc, optId );
            break;
        }
    }
}