Changeset 4046 for neercs/trunk
- Timestamp:
- Nov 26, 2009, 2:32:27 PM (11 years ago)
- Location:
- neercs/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/configuration.c
r4039 r4046 57 57 {.name = "borders",.set = set_border,.get = get_border}, 58 58 {.name = "cube_duration",.set = set_cube_duration,.get = 59 get_ window_manager},60 {.name = "thumbnails",.set = set_thumbnails,.get = get_ window_manager},61 {.name = "status_bar",.set = set_status_bar,.get = get_ window_manager},59 get_cube_duration}, 60 {.name = "thumbnails",.set = set_thumbnails,.get = get_thumbnails}, 61 {.name = "status_bar",.set = set_status_bar,.get = get_status_bar}, 62 62 {.name = "screensaver_timeout",.set = set_screensaver_timeout,.get = 63 get_ window_manager},63 get_screensaver_timeout}, 64 64 {.name = "autolock_timeout",.set = set_autolock_timeout,.get = 65 get_ window_manager},65 get_autolock_timeout}, 66 66 {.name = "lock_on_detach",.set = set_lock_on_detach,.get = 67 get_ window_manager},68 {.name = "socket_dir",.set = set_socket_dir,.get = get_ window_manager},67 get_lock_on_detach}, 68 {.name = "socket_dir",.set = set_socket_dir,.get = get_socket_dir}, 69 69 {.name = "delay",.set = set_delay,.get = get_delay}, 70 70 … … 136 136 } 137 137 138 struct config_line *get_config_option(void) 139 { 140 return config_option; 141 } 138 142 139 143 int parse_conf_line(char *buf, int size, struct screen_list *screen_list) … … 371 375 372 376 #define IS_OPTION(t) (!strncmp(argv, t, strlen(argv))) 373 #define IS_OPTION_TRUE (IS_OPTION("true") || IS_OPTION(" 1"))377 #define IS_OPTION_TRUE (IS_OPTION("true") || IS_OPTION("True") || IS_OPTION("1")) 374 378 375 379 int set_window_manager(const char *argv, struct screen_list *screen_list) … … 507 511 { 508 512 if (screen_list->mini) 509 return " yes";510 return " no";513 return "true"; 514 return "false"; 511 515 } 512 516 … … 514 518 { 515 519 if (screen_list->status) 516 return " yes";517 return " no";520 return "true"; 521 return "false"; 518 522 } 519 523 … … 521 525 { 522 526 if (screen_list->eyecandy) 523 return " yes";524 return " no";527 return "true"; 528 return "false"; 525 529 } 526 530 … … 528 532 { 529 533 if (screen_list->border_size) 530 return " yes";531 return " no";534 return "true"; 535 return "false"; 532 536 } 533 537 … … 549 553 { 550 554 if (screen_list->lock_on_detach) 551 return " yes";552 else 553 return " no";555 return "true"; 556 else 557 return "false"; 554 558 } 555 559 -
neercs/trunk/src/neercs.h
r4038 r4046 364 364 int fill_config(struct screen_list *screen_list); 365 365 struct config_line *get_config(const char *name); 366 struct config_line *get_config_option(void); 366 367 367 368 /* Python interpreter */ -
neercs/trunk/src/python/interpreter.c
r4040 r4046 41 41 static void del_char(struct screen_list *sl); 42 42 static int python_execute(struct screen_list *sl); 43 staticchar *getStringFromPyObject(PyObject * p);43 char *getStringFromPyObject(PyObject * p); 44 44 static char *getPythonError(void); 45 45 … … 230 230 goto end; 231 231 } 232 233 232 234 233 pModule = PyImport_Import(pName); 235 234 Py_DECREF(pName); 235 236 236 if (pModule != NULL) 237 237 { 238 PyObject *o = PyRun_String(sl->interpreter_props.command, Py_eval_input, PyModule_GetDict(pModule), NULL); 239 debug("py object is %p\n", o); 238 PyObject * dictionary = PyModule_GetDict(pModule); 239 240 getExportedValues(dictionary); 241 242 PyObject *o = PyRun_String(sl->interpreter_props.command, Py_single_input, dictionary, NULL); 240 243 if(!o) 241 244 { … … 245 248 else 246 249 { 247 debug("py res : %s\n", getStringFromPyObject(o)); 250 setExportedValues(dictionary); 251 248 252 sl->interpreter_props.output_res = getStringFromPyObject(o); 249 253 err = 1; … … 293 297 } 294 298 295 staticchar *getStringFromPyObject(PyObject * p)299 char *getStringFromPyObject(PyObject * p) 296 300 { 297 301 PyObject *str = PyObject_Repr(p); -
neercs/trunk/src/python/py_module.c
r4040 r4046 41 41 42 42 PyObject *PyInit_neercs(void); 43 void removeTrailingStuff(char *b); 44 45 46 static void addVariableFromConfig(PyObject * dictionary, 47 const char *varname, const char *configname) 48 { 49 char *v = get_config(configname)->get(screen_list); 50 if (v != NULL) 51 { 52 PyObject *value = Py_BuildValue("s", v); 53 PyDict_SetItemString(dictionary, varname, value); 54 } 55 56 debug("py get '%s' to '%s'\n", varname, 57 get_config(configname)->get(screen_list)); 58 59 } 60 61 void removeTrailingStuff(char *b) 62 { 63 if(!b) return; 64 if(b[0]=='\'') 65 { 66 memmove(b, &b[1], strlen(b)-1); 67 b[strlen(b)-2] = 0; 68 } 69 } 70 71 void setExportedValues(PyObject * dictionary) 72 { 73 struct config_line *config_option = get_config_option(); 74 int i = 0; 75 76 while (strncmp(config_option[i].name, "last", strlen("last"))) 77 { 78 /* Get variable */ 79 PyObject *res = 80 PyDict_GetItemString(dictionary, config_option[i].name); 81 82 /* Got it */ 83 if (res) 84 { 85 86 /* Get object representation 87 * FIXME : find a way to check object's type */ 88 PyObject *str = PyObject_Repr(res); 89 90 /* Make sure it's a string */ 91 char *err = 92 PyBytes_AS_STRING(PyUnicode_AsEncodedString 93 (str, "utf-8", "Error ~")); 94 /* FIXME leak leak leak */ 95 char *s = strdup(err); 96 97 if (s != NULL) 98 { 99 /* Representation can include '' around strings */ 100 removeTrailingStuff(s); 101 get_config(config_option[i].name)->set(s, screen_list); 102 } 103 } 104 i++; 105 } 106 } 107 108 void getExportedValues(PyObject * dictionary) 109 { 110 struct config_line *config_option = get_config_option(); 111 int i = 0; 112 while (strncmp(config_option[i].name, "last", strlen("last"))) 113 { 114 addVariableFromConfig(dictionary, config_option[i].name, 115 config_option[i].name); 116 i++; 117 } 118 } 119 43 120 44 121 static PyObject *neercs_get(PyObject * self, PyObject * args) … … 50 127 if (!PyArg_ParseTuple(args, "s", &s)) 51 128 { 129 PyErr_SetString(PyExc_ValueError, "Can't parse argument"); 52 130 debug("py Can't parse"); 53 131 return NULL; … … 55 133 debug("py Argument : '%s'", s); 56 134 struct config_line *c = get_config(s); 57 debug("py config %p");58 135 59 136 if (c) 60 137 return Py_BuildValue("s", c->get(screen_list)); 61 else62 return Py_BuildValue("s", "Invalid");63 138 139 140 PyErr_SetString(PyExc_ValueError, 141 "Can't get value for specified variable"); 142 return NULL; 64 143 } 65 144 66 145 static PyObject *neercs_version(PyObject * self, PyObject * args) 67 146 { 68 if (!PyArg_ParseTuple(args, ":version"))69 return NULL;70 147 return Py_BuildValue("s", PACKAGE_VERSION); 71 148 } 72 149 73 150 static PyMethodDef NeercsMethods[] = { 74 {"version", neercs_version, METH_ VARARGS, "Return the neercs version."},151 {"version", neercs_version, METH_NOARGS, "Return the neercs version."}, 75 152 {"get", neercs_get, METH_VARARGS, 76 153 "Return the specified variable's value."}, … … 93 170 { 94 171 screen_list = sl; 95 172 PyInit_neercs(); 96 173 } 97 174 -
neercs/trunk/src/python/py_module.h
r4040 r4046 21 21 22 22 void initNeercsModule(struct screen_list *sl); 23 23 void getExportedValues(PyObject * dictionary); 24 void setExportedValues(PyObject * dictionary); 24 25 25 26
Note: See TracChangeset
for help on using the changeset viewer.