Hi all, I need to use a program in C that is designed to be used in Guile. I'm
not a Guile user myself so I don't know well how to remove the Guile code from
the C program, so that I can run it without Guile (Please, don't be ofended for
that ;) ).
I looked at the program's code and it looks a bit difficult to change it, and I
must say I'm a beginner in C. Could anyone give me the steps of the changes I'd
need to remove Guile-dependent code from C code?
The program has about 10 files, so here I'm pasting only one of the files. The
code is open-source so I could share it if anyone wants to see the other files.
I'd massively appreciate any help. Thanks,
Jose
-- ATTACHED CODE --
#include
...
#define INFO contain
#define TEXTMGRP(x) (SCM_NIMP(x) && SCM_CAR(x) == (SCM)scm_tc16_textmgr)
#define TEXTMGR(x) ((TextFile*) SCM_CDR(x))
long scm_tc16_textmgr;
SCM mark_textmgr(SCM obj)
{
SCM_SETGC8MARK(obj);
return SCM_BOOL_F;
}
size_t free_textmgr(SCM obj)
{
if (TEXTMGR(obj)) {
TEXTMGR(obj)->foreach(markref);
TEXTMGR(obj)->hashtable()->foreach(decref);
delete TEXTMGR(obj);
}
return 0;
}
int print_textmgr(SCM obj, SCM port, scm_print_state * pstate)
{
scm_puts("#filename(), port);
scm_puts(">", port);
return 1;
}
SCM textmgr2scm(TextFile* text)
{
SCM result;
SCM_NEWCELL(result);
SCM_SETCAR(result, (SCM) scm_tc16_textmgr);
SCM_SETCDR(result, (SCM) text);
return result;
}
SCM_PROC(s_open_text, "open-text", 1, 0, 0, open_text);
SCM open_text(SCM name)
{
SCM txt;
if (scm_string_p(name) != SCM_BOOL_T)
scm_wrong_type_arg(s_open_text, 1, name);
txt = textmgr2scm(new TextFile(SCM_CHARS(name)));
TEXTMGR(txt)->foreach(markref);
TEXTMGR(txt)->hashtable()->foreach(incref);
return txt;
}
SCM_PROC(s_append_text, "append-text", 2, 0, 0, append_text);
SCM append_text(SCM obj, SCM name)
{
if (!TEXTMGRP(obj))
scm_wrong_type_arg(s_append_text, 1, obj);
if (!TEXTMGR(obj))
scm_misc_error(s_append_text, "Text object is empty", SCM_EOL);
if (scm_string_p(name) != SCM_BOOL_T)
scm_wrong_type_arg(s_append_text, 2, name);
TEXTMGR(obj)->foreach(markref);
TEXTMGR(obj)->hashtable()->foreach(decref);
TEXTMGR(obj)->append(SCM_CHARS(name));
TEXTMGR(obj)->foreach(markref);
TEXTMGR(obj)->hashtable()->foreach(incref);
return obj;
}
SCM_PROC(s_close_text, "close-text", 1, 0, 0, close_text);
SCM close_text(SCM obj)
{
if (!TEXTMGRP(obj))
scm_wrong_type_arg(s_close_text, 1, obj);
if (TEXTMGR(obj)) {
scm_gc();
TEXTMGR(obj)->foreach(markref);
TEXTMGR(obj)->hashtable()->foreach(decref);
TEXTMGR(obj)->hashtable()->removeif(delrefp);
delete TEXTMGR(obj);
SCM_SETCDR(obj, 0);
}
return SCM_UNSPECIFIED;
}
SCM_PROC(s_rewind_text, "rewind-text", 1, 0, 0, rewind_text);
SCM rewind_text(SCM obj)
{
if (!TEXTMGRP(obj))
scm_wrong_type_arg(s_rewind_text, 1, obj);
if (!TEXTMGR(obj))
scm_misc_error(s_rewind_text, "Text object is empty", SCM_EOL);
TEXTMGR(obj)->rewind();
return SCM_UNSPECIFIED;
}
SCM_PROC(s_get_next_word, "get-next-word", 1, 0, 0, get_next_word);
SCM get_next_word(SCM obj)
{
contain* cn;
if (!TEXTMGRP(obj))
scm_wrong_type_arg(s_get_next_word, 1, obj);
if (!TEXTMGR(obj))
scm_misc_error(s_get_next_word, "Text object is empty", SCM_EOL);
cn = TEXTMGR(obj)->getnext();
if (cn)
return cn->content;
else
return SCM_BOOL_F;
}
SCM_PROC(s_get_word, "get-word", 2, 0, 0, get_word);
SCM get_word(SCM obj, SCM n)
{
contain* cn;
if (!TEXTMGRP(obj))
scm_wrong_type_arg(s_get_word, 1, obj);
if (!TEXTMGR(obj))
scm_misc_error(s_get_word, "Text object is empty", SCM_EOL);
if (scm_integer_p(n) != SCM_BOOL_T)
scm_wrong_type_arg(s_get_word, 2, n);
cn = TEXTMGR(obj)->get(gh_scm2int(n));
if (cn)
return cn->content;
else
return SCM_BOOL_F;
}
SCM_PROC(s_scramble_text, "scramble-text", 1, 0, 0, scramble_text);
SCM scramble_text(SCM obj)
{
if (!TEXTMGRP(obj))
scm_wrong_type_arg(s_scramble_text, 1, obj);
if (!TEXTMGR(obj))
scm_misc_error(s_scramble_text, "Text object is empty", SCM_EOL);
return textmgr2scm(TEXTMGR(obj)->scramble());
}
static SCM currentproc = 0;
void iterproc(contain* cn)
{
gh_call1(currentproc, cn->content);
}
SCM_PROC(s_for_each_word, "for-each-word", 2, 0, 0, for_each_word);
SCM for_each_word(SCM obj, SCM proc)
{
SCM lastproc = currentproc;
if (!TEXTMGRP(obj))
scm_wrong_type_arg(s_for_each_word, 1, obj);
if (!TEXTMGR(obj))
scm_misc_error(s_for_each_word, "Text object is empty", SCM_EOL);
currentproc = proc;
TEXTMGR(obj)->foreach(iterproc);
currentproc = lastproc;
return SCM_UNSPECIFIED;
}
SCM_PROC(s_for_each_unique_word, "for-each-unique-word", 1, 0, 0,
for_each_unique_word);
SCM for_each_unique_word(SCM proc)
{
SCM lastproc = currentpro