コード例 #1
0
ファイル: pyunit.c プロジェクト: g2p/pyparted
PyObject *py_ped_unit_get_by_name(PyObject *s, PyObject *args) {
    int ret;
    char *name = NULL;

    if (!PyArg_ParseTuple(args, "z", &name)) {
        return NULL;
    }

    ret = ped_unit_get_by_name(name);
    if (ret < PED_UNIT_FIRST || ret > PED_UNIT_LAST) {
        PyErr_SetString(UnknownTypeException, name);
        return NULL;
    }

    return Py_BuildValue("i", ret);
}
コード例 #2
0
ファイル: ui.c プロジェクト: bcl/parted
int
command_line_get_unit (const char* prompt, PedUnit* unit)
{
        StrList*       opts = NULL;
        PedUnit        walk;
        char*          unit_name;
        const char*    default_unit_name;

        for (walk = PED_UNIT_FIRST; walk <= PED_UNIT_LAST; walk++)
                opts = str_list_append (opts, ped_unit_get_name (walk));

        default_unit_name = ped_unit_get_name (ped_unit_get_default ());
        unit_name = command_line_get_word (prompt, default_unit_name, opts, 1);
        str_list_destroy (opts);

        if (unit_name) {
                *unit = ped_unit_get_by_name (unit_name);
                free (unit_name);
                return 1;
        } else
                return 0;
}