Update of /cvsroot/dhcp-agent/dhcp-agent/src
In directory sc8-pr-cvs1:/tmp/cvs-serv19018
Modified Files:
dhcp-guile-util.c dhcp-guile-util.h
Log Message:
added more utilities
Index: dhcp-guile-util.c
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-guile-util.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** dhcp-guile-util.c 5 Aug 2003 04:49:09 -0000 1.1
--- dhcp-guile-util.c 10 Aug 2003 01:21:33 -0000 1.2
***************
*** 21,25 ****
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
! * guile utility routines which guile should be offering but isn't :|
*
*/
--- 21,25 ----
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
! * guile utility routines.
*
*/
***************
*** 29,32 ****
--- 29,36 ----
#include "dhcp-guile-util.h"
+ /* * * * * * * * * * * * * * * * * * * * *
+ * routines guile should be offering but isn't :| *
+ * * * * * * * * * * * * * * * * * * * * */
+
char *x_scm_symbol2newstr(SCM symbol)
{
***************
*** 54,55 ****
--- 58,121 ----
return newstr;
}
+
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * converting between our own native types and guile. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+ /* take a string list from guile and turn it into a native list. */
+ list_t *x_scm_guile_string_list_to_list(SCM scm_list)
+ {
+ list_t *list;
+ int i, list_length;
+ char *str;
+ SCM scm_list_length, scm_string;
+
+ list = list_create();
+
+ scm_list_length = scm_length(scm_list);
+ list_length = scm_num2int(scm_list_length, SCM_ARG1, "x_scm_guile_string_list_to_list");
+
+ for(i = 0; i < list_length; i++) {
+ scm_string = scm_list_ref(scm_list, SCM_MAKINUM(i));
+
+ if(!(SCM_STRINGP(scm_string))) {
+ list_destroy(list, xfree);
+ return NULL;
+ }
+
+ str = x_scm_string2newstr(scm_string);
+ list_add_to_end(list, str);
+
+ }
+
+ return list;
+ }
+
+ /* take a string which contains atoms which are comma delimited, and create an SCM list of strings */
+ SCM x_scm_comma_delimited_string_to_scm_list(const char *string_val)
+ {
+ char *str_copy, *cptr, *ptr;
+ SCM scm_string_list = SCM_EOL;
+
+ str_copy = xstrdup(string_val);
+
+ ptr = str_copy;
+ for(cptr = str_copy; ptr; ptr = strchr(cptr, ',')) {
+
+ *ptr = 0;
+ ptr++;
+
+ while(*cptr == ' ')
+ cptr++;
+
+ if(*cptr == 0)
+ return SCM_EOL; /* munged string list. */
+
+ scm_string_list = scm_cons(scm_makfrom0str(cptr), scm_string_list);
+ }
+
+ scm_string_list = scm_reverse(scm_string_list);
+
+ return scm_string_list;
+ }
+
Index: dhcp-guile-util.h
===================================================================
RCS file: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-guile-util.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** dhcp-guile-util.h 5 Aug 2003 04:49:09 -0000 1.1
--- dhcp-guile-util.h 10 Aug 2003 01:21:33 -0000 1.2
***************
*** 30,33 ****
--- 30,35 ----
extern char *x_scm_symbol2newstr(SCM symbol);
extern char *x_scm_string2newstr(SCM string);
+ extern list_t *x_scm_guile_string_list_to_list(SCM scm_list);
+ extern SCM x_scm_comma_delimited_string_to_scm_list(const char *string_val);
#endif /* DHCP_GUILE_UTIL_H */
|