PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/common/conf_parser/skyeye_options.c

https://github.com/antmar/Skyeye-fixes
C | 300 lines | 210 code | 33 blank | 57 comment | 53 complexity | b8d9f73fc1d9a98f90324eab3d7acd07 MD5 | raw file
  1. /*
  2. skyeye_options.c - skyeye config file options' functions
  3. Copyright (C) 2003 Skyeye Develop Group
  4. for help please send mail to <skyeye-developer@lists.sf.linuxforum.net>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /* 08/20/2003 add log option function
  18. chenyu
  19. 4/02/2003 add net option function
  20. * walimis <walimi@peoplemail.com.cn>
  21. * 3/22/2003 add cpu, mem_num, mem_bank, arch, dummy option function
  22. * walimis <walimi@peoplemail.com.cn>
  23. * 10/24/2005 add dbct test speed function
  24. * teawater <c7code-uc@yahoo.com.cn>
  25. * */
  26. #include <sys/types.h>
  27. #include <sys/stat.h>
  28. #include <fcntl.h>
  29. #include "skyeye_options.h"
  30. //#include "skyeye_arch.h"
  31. #include "skyeye_config.h"
  32. #include "skyeye_pref.h"
  33. #include "skyeye_types.h"
  34. /* 2007-01-18 added by Anthony Lee: for new uart device frame */
  35. /*#include "skyeye_uart.h"
  36. #include "skyeye_net.h"
  37. #include "skyeye_lcd.h"
  38. */
  39. int
  40. do_load_addr_option (skyeye_option_t * this_option, int num_params,
  41. const char *params[]);
  42. extern FILE *skyeye_logfd;
  43. int
  44. split_param (const char *param, char *name, char *value)
  45. {
  46. const char *src = param;
  47. char *dst = name;
  48. while (*src && (*src != '='))
  49. *dst++ = *src++;
  50. *dst = '\0';
  51. if (*src == '\0') {
  52. value = '\0';
  53. return -1;
  54. }
  55. strcpy (value, src + 1);
  56. return 0;
  57. }
  58. /* we need init some options before read the option file.
  59. * now put them here.
  60. * */
  61. /* 2007-01-22 : SKYEYE4ECLIPSE moved to skyeye_config.c */
  62. static skyeye_option_t* skyeye_option_list;
  63. int
  64. skyeye_option_init (skyeye_config_t * config)
  65. {
  66. /* 2007-01-18 added by Anthony Lee: for new uart device frame */
  67. config->uart.count = 0;
  68. /* should move to uart module loading */
  69. //atexit(skyeye_uart_cleanup);
  70. /*ywc 2005-04-01 */
  71. config->no_dbct = 1; /*default, dbct is off */
  72. //teawater add for new tb manage function 2005.07.10----------------------------
  73. config->tb_tbt_size = 0;
  74. #if DBCT
  75. config->tb_tbp_size = TB_TBP_DEFAULT;
  76. #else
  77. config->tb_tbp_size = 0;
  78. #endif
  79. skyeye_option_list = NULL;
  80. register_option("cpu", do_deprecated_option, "Do not need to provide cpu option any more.\n");
  81. register_option("load_addr", do_load_addr_option, "Set load base address and mask value for elf file loading.\n");
  82. }
  83. exception_t register_option(char* option_name, do_option_t do_option_func, char* helper){
  84. if(option_name == NULL || !do_option_func)
  85. return Invarg_exp;
  86. skyeye_option_t* node = malloc(sizeof(skyeye_option_t));
  87. if(node == NULL)
  88. return Malloc_exp;
  89. node->option_name = skyeye_strdup(option_name);
  90. if(node->option_name == NULL){
  91. skyeye_free(node);
  92. return Malloc_exp;
  93. }
  94. node->do_option = do_option_func;
  95. /* maybe we should use skyeye_mm to replace all the strdup */
  96. node->helper = skyeye_strdup(helper);
  97. if(node->helper == NULL){
  98. skyeye_free(node->option_name);
  99. skyeye_free(node);
  100. return Malloc_exp;
  101. }
  102. node->next = skyeye_option_list;
  103. skyeye_option_list = node;
  104. //skyeye_log(Info_log, __FUNCTION__, "register option %s successfully.", option_name);
  105. return No_exp;
  106. }
  107. skyeye_option_t* get_option_list(){
  108. return skyeye_option_list;
  109. }
  110. #if 0
  111. int com_list_options(char* arg){
  112. char* format = "%-20s\t%s\n";
  113. printf(format, "Option Name", "Description");
  114. skyeye_option_t* list = get_option_list();
  115. while(list != NULL){
  116. printf(format, list->option_name, list->helper);
  117. list = list->next;
  118. }
  119. return 0;
  120. }
  121. #endif
  122. int
  123. do_dummy_option (skyeye_option_t * this_option, int num_params,
  124. const char *params[])
  125. {
  126. return 0;
  127. };
  128. /* parse "int" parameters. e.g. int=16:17*/
  129. int
  130. get_interrupts (char value[], uint32 * interrupts)
  131. {
  132. char *cur = value;
  133. char *next = value;
  134. int i = 0, end = 0;
  135. while ((*next != ':') && (*next != 0))
  136. next++;
  137. while (*cur != 0) {
  138. if (*next != 0) {
  139. *next = '\0';
  140. }
  141. else
  142. end = 1;
  143. interrupts[i] = strtoul (cur, NULL, 0);
  144. //printf("%s:%s\n", __FUNCTION__, cur);
  145. i++;
  146. if ((i > 4) || end == 1)
  147. return 0;
  148. cur = ++next;
  149. while ((*next != ':') && (*next != 0))
  150. next++;
  151. }
  152. return 0;
  153. }
  154. #if 0
  155. /* defined in skyeye_arch.c */
  156. extern arch_config_t *skyeye_archs[];
  157. int
  158. do_cpu_option (skyeye_option_t * this_option, int num_params,
  159. const char *params[])
  160. {
  161. int ret;
  162. if (skyeye_config.arch == NULL) {
  163. /* If we don't set arch, we use "arm" as default. */
  164. char *default_arch = "arm";
  165. int i;
  166. for (i = 0; i < MAX_SUPP_ARCH; i++) {
  167. if (skyeye_archs[i] == NULL)
  168. continue;
  169. if (!strncmp
  170. (default_arch, skyeye_archs[i]->arch_name,
  171. MAX_PARAM_NAME)) {
  172. skyeye_config.arch = skyeye_archs[i];
  173. SKYEYE_INFO ("arch: %s\n",
  174. skyeye_archs[i]->arch_name);
  175. }
  176. }
  177. if (skyeye_config.arch == NULL) {
  178. SKYEYE_ERR
  179. ("ERROR: No arch option found! Maybe you use low version of skyeye?\n");
  180. skyeye_exit (-1);
  181. }
  182. }
  183. ret = skyeye_config.arch->parse_cpu (params);
  184. if (ret < 0)
  185. SKYEYE_ERR ("Error: Unknown cpu name \"%s\"\n", params[0]);
  186. return ret;
  187. }
  188. #endif
  189. #if 0
  190. int
  191. do_mach_option (skyeye_option_t * this_option, int num_params,
  192. const char *params[])
  193. {
  194. int ret;
  195. machine_config_t *mach = skyeye_config.mach;
  196. ret = skyeye_config.arch->parse_mach (mach, params);
  197. if (ret < 0) {
  198. SKYEYE_ERR ("Error: Unknown mach name \"%s\"\n", params[0]);
  199. }
  200. return ret;
  201. }
  202. #endif
  203. /*
  204. * we can add this option using:
  205. * step_disassemble:on[ON|1] for open this option
  206. * step_disassemble:off[OFF|0] for disable this option
  207. * oyangjian add here
  208. */
  209. #if 0
  210. int
  211. do_step_disassemble_option (skyeye_option_t * this_option, int num_params,
  212. const char *params[])
  213. {
  214. int i;
  215. for (i = 0; i < num_params; i++) {
  216. printf ("step_disassemble state:%s\n", params[0]);
  217. if (!params[0]) {
  218. SKYEYE_ERR ("Error :usage: step_disassemble:on[off]");
  219. return -1;
  220. }
  221. if (!strncmp (params[0], "on", 2)
  222. || !strncmp (params[0], "ON", 2)) {
  223. skyeye_config.can_step_disassemble = 1;
  224. return 0;
  225. }
  226. else if (!strncmp (params[0], "off", 3)
  227. || !strncmp (params[0], "OFF", 3)) {
  228. skyeye_config.can_step_disassemble = 0;
  229. return 0;
  230. }
  231. }
  232. SKYEYE_ERR ("Error: Unknown cpu name \"%s\"\n", params[0]);
  233. return -1;
  234. }
  235. #endif
  236. int
  237. parse_line_formatted (int num_params, const char *params[])
  238. {
  239. skyeye_option_t *sop;
  240. //int len = sizeof (skyeye_options) / sizeof (skyeye_option_t);
  241. int retval = 0;
  242. if(skyeye_option_list == NULL)
  243. return 0;
  244. sop = skyeye_option_list;
  245. if (num_params < 1)
  246. return 0;
  247. while(sop != NULL){
  248. if (!strncmp (sop->option_name, params[0], MAX_OPTION_NAME)) {
  249. if (retval = sop->do_option (sop, num_params - 1,
  250. &params[1]) < 0) {
  251. fprintf (stderr,
  252. "\"%s\" option parameter error!\n",
  253. params[0]);
  254. return retval;
  255. }
  256. else
  257. return retval;
  258. }
  259. sop = sop->next;
  260. }
  261. fprintf (stderr, "Unknown option: %s\n", params[0]);
  262. return -1; /* unknow option specified */
  263. }