stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src ai/ccl_ai.c clone/ccl.c clone/mai...


From: Ingo Ruhnke
Subject: [Stratagus-CVS] stratagus/src ai/ccl_ai.c clone/ccl.c clone/mai...
Date: Sat, 02 Aug 2003 09:34:26 -0400

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Ingo Ruhnke <address@hidden>    03/08/02 09:34:26

Modified files:
        src/ai         : ccl_ai.c 
        src/clone      : ccl.c mainloop.c unit.c 
        src/editor     : editloop.c 
        src/game       : campaign.c game.c loadgame.c savegame.c 
                         trigger.c 
        src/include    : ccl.h siodp.h 
        src/map        : ccl_map.c ccl_tileset.c tileset.c 
        src/network    : commands.c 
        src/pathfinder : ccl_pathfinder.c 
        src/sound      : ccl_sound.c sound_server.c 
        src/ui         : ccl_ui.c interface.c menus.c 
        src/unit       : ccl_unittype.c 

Log message:
        - added optional guile support
        - fixed a few more missing includes

Patches:
Index: stratagus/src/ai/ccl_ai.c
diff -u stratagus/src/ai/ccl_ai.c:1.64 stratagus/src/ai/ccl_ai.c:1.65
--- stratagus/src/ai/ccl_ai.c:1.64      Fri Jul 11 10:35:29 2003
+++ stratagus/src/ai/ccl_ai.c   Sat Aug  2 09:34:24 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_ai.c,v 1.64 2003/07/11 14:35:29 n0body Exp $
+//     $Id: ccl_ai.c,v 1.65 2003/08/02 13:34:24 grumbel Exp $
 
 //@{
 
@@ -34,6 +34,7 @@
 --     Includes
 ----------------------------------------------------------------------------*/
 
+#include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -871,7 +872,7 @@
     int i;
     SCM old;
 
-    old=cons_array(gh_int2scm(MaxCosts),NIL);
+    old = cons_array(gh_int2scm(MaxCosts), 0);
     for( i=0; i<MaxCosts; ++i ) {
        aset1(old,gh_int2scm(i),gh_int2scm(AiPlayer->Reserve[i]));
     }
@@ -892,7 +893,7 @@
     int i;
     SCM old;
 
-    old=cons_array(gh_int2scm(MaxCosts),NIL);
+    old = cons_array(gh_int2scm(MaxCosts), 0);
     for( i=0; i<MaxCosts; ++i ) {
        aset1(old,gh_int2scm(i),gh_int2scm(AiPlayer->Collect[i]));
     }
Index: stratagus/src/clone/ccl.c
diff -u stratagus/src/clone/ccl.c:1.106 stratagus/src/clone/ccl.c:1.107
--- stratagus/src/clone/ccl.c:1.106     Mon Jul 14 15:34:28 2003
+++ stratagus/src/clone/ccl.c   Sat Aug  2 09:34:24 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl.c,v 1.106 2003/07/14 19:34:28 grumbel Exp $
+//     $Id: ccl.c,v 1.107 2003/08/02 13:34:24 grumbel Exp $
 
 //@{
 
@@ -71,6 +71,10 @@
 --     Variables
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_GUILE
+int siod_verbose_level;
+#endif
+
 global char* CclStartFile;             /// CCL start file
 global char* GameName;                 /// Game Preferences
 global int CclInConfigFile;            /// True while config file parsing
@@ -83,6 +87,108 @@
 --     Functions
 ----------------------------------------------------------------------------*/
 
+/** 
+ * Convert a SCM to a string, SCM must be a symbol or string, else 0
+ * is returned
+ * 
+ * @param scm the SCM to convert to string
+ * 
+ * @return a string representing the SCM or 0 in case the conversion
+ * failed, caller must free() the returned value
+ */
+global char* CclConvertToString(SCM scm)
+{
+#ifdef USE_GUILE
+  if (gh_string_p(scm))
+    return gh_scm2newstr(scm, NULL);
+  else if (gh_symbol_p(scm))
+    return gh_symbol2newstr(scm, NULL);
+  else 
+    return 0;
+#else
+  char* str = try_get_c_string(scm);
+  if (str)
+    return strdup(str);
+  else 
+    return 0;
+#endif
+}
+
+/** 
+ * Return the type of a smob
+ * 
+ * @param smob
+ * 
+ * @return type id of the smob
+ */
+global ccl_smob_type_t CclGetSmobType(SCM smob)
+{
+#ifdef USE_GUILE
+  if (SCM_NIMP (smob))
+    return (ccl_smob_type_t)SCM_CAR (smob);
+  else
+    return 0;
+#else  
+  return TYPE(smob);
+#endif
+}
+
+/** 
+ * Return the pointer that is stored in a smob
+ * 
+ * @param smob the smob that contains the pointer
+ * 
+ * @return pointer that was inside the smob
+ */
+global void* CclGetSmobData(SCM smob)
+{
+#ifdef USE_GUILE
+  return (void*)SCM_SMOB_DATA(smob);
+#else
+  return smob->storage_as.cons.cdr;
+#endif
+}
+
+/** 
+ * Store a pointer inside a SMOB, aka convert a pointer to a SCM
+ * 
+ * @param tag The type of the pointer/smob
+ * @param ptr the pointer that should be converted to a SCM
+ */
+global SCM CclMakeSmobObj(ccl_smob_type_t tag, void* ptr)
+{
+#ifdef USE_GUILE
+  SCM_RETURN_NEWSMOB (tag, ptr);
+#else
+  SCM value   = cons(NIL,NIL);
+
+  value->type                = tag;
+  value->storage_as.cons.cdr = (SCM)ptr;
+
+  return value;
+#endif
+}
+
+/** 
+ * Create a tag for a new type.
+ * 
+ * @param name 
+ * 
+ * @return The newly generated SMOB type
+ */
+global ccl_smob_type_t CclMakeSmobType(const char* name)
+{
+  ccl_smob_type_t new_type;
+
+#ifdef USE_GUILE
+  new_type = scm_make_smob_type ((char*)name, 0);
+#else
+  new_type = allocate_user_tc();
+#endif
+
+  return new_type;
+}
+
 /**
 **     Protect SCM object against garbage collector.
 **
@@ -90,10 +196,13 @@
 */
 global void CclGcProtect(SCM obj)
 {
+#ifdef USE_GUILE
+    scm_gc_protect_object(obj);
+#else
     SCM var;
-
     var=gh_symbol2scm("*ccl-protect*");
     setvar(var,cons(obj,symbol_value(var,NIL)),NIL);
+#endif
 }
 
 /**
@@ -103,6 +212,9 @@
 */
 global void CclGcUnprotect(SCM obj)
 {
+#ifdef USE_GUILE
+    scm_gc_unprotect_object(obj);
+#else
     // Remove obj from the list *ccl-protect*
     SCM sym;
     SCM old_lst;
@@ -112,6 +224,7 @@
     old_lst = symbol_value(sym, NIL);
     new_lst = NIL;
 
+    // FIXME: Doesn't handle nested protect/unprotects
     while( !gh_null_p(old_lst) ) {
         SCM el = gh_car(old_lst);
 
@@ -122,6 +235,7 @@
       }
     
     setvar(sym, new_lst, NIL);
+#endif
 }
 
 /*............................................................................
@@ -211,7 +325,7 @@
 {
     char* str;
 
-    str=gh_scm2newstr(name,NIL);
+    str=gh_scm2newstr(name, 0);
     strncpy(LocalPlayerName,str,sizeof(LocalPlayerName)-1);
     LocalPlayerName[sizeof(LocalPlayerName)-1]='\0';
     return SCM_UNSPECIFIED;
@@ -459,7 +573,7 @@
        DefaultActions[i]=NULL;
     }
     for( i=0; i<MaxCosts && !gh_null_p(list); ++i ) {
-       DefaultActions[i]=gh_scm2newstr(gh_car(list),NIL);
+       DefaultActions[i] = gh_scm2newstr(gh_car(list), 0);
        list=gh_cdr(list);
     }
     return SCM_UNSPECIFIED;
@@ -477,7 +591,7 @@
        DefaultResourceNames[i]=NULL;
     }
     for( i=0; i<MaxCosts && !gh_null_p(list); ++i ) {
-       DefaultResourceNames[i]=gh_scm2newstr(gh_car(list),NIL);
+       DefaultResourceNames[i] = gh_scm2newstr(gh_car(list), 0);
        list=gh_cdr(list);
     }
     return SCM_UNSPECIFIED;
@@ -650,14 +764,18 @@
 global void CclCommand(const char* command)
 {
     char msg[80];
+#ifndef USE_GUILE
     int retval;
-
+#endif
     strncpy(msg,command,sizeof(msg));
 
     // FIXME: cheat protection
-    retval=repl_c_string(msg,0,0,sizeof(msg));
+#ifdef USE_GUILE
+    gh_eval_str(msg);
+#else
+    retval = repl_c_string(msg,0,0,sizeof(msg));
     DebugLevel3("\n%d=%s\n" _C_ retval _C_ msg);
-
+#endif
     SetMessage("%s",msg);
 }
 
@@ -670,8 +788,18 @@
 */
 global void InitCcl(void)
 {
+#ifdef USE_GUILE
+  scm_init_guile();
+
+  gh_eval_str("(display \"Guile: Enabling debugging...\\n\")"
+              "(debug-enable 'debug)"
+              "(debug-enable 'backtrace)"
+              "(read-enable 'positions)"
+              "(define *scheme* 'guile)");
+#else
     char* sargv[5];
     char* buf;
+    char  msg[] = "(define *scheme* 'siod)";
 
     sargv[0] = "Stratagus";
     sargv[1] = "-v1";
@@ -680,8 +808,10 @@
     buf=malloc(strlen(StratagusLibPath)+4);
     sprintf(buf,"-l%s",StratagusLibPath);
     sargv[4] = buf;                    // never freed
+    
     siod_init(5,sargv);
-
+    repl_c_string(msg, 0,0,sizeof(msg));
+#endif
     gh_new_procedure0_0("library-path",CclStratagusLibraryPath);
     gh_new_procedure0_0("game-cycle",CclGameCycle);
     gh_new_procedure1_0("set-game-name!",CclSetGameName);
@@ -893,7 +1023,7 @@
     }
 
     fprintf(fd,";;; -----------------------------------------\n");
-    fprintf(fd,";;; $Id: ccl.c,v 1.106 2003/07/14 19:34:28 grumbel Exp $\n");
+    fprintf(fd,";;; $Id: ccl.c,v 1.107 2003/08/02 13:34:24 grumbel Exp $\n");
 
     fprintf(fd,"(set-video-resolution! %d %d)\n", VideoWidth, VideoHeight);
     
@@ -917,7 +1047,7 @@
     }
 
     fprintf(fd,";;; -----------------------------------------\n");
-    fprintf(fd,";;; $Id: ccl.c,v 1.106 2003/07/14 19:34:28 grumbel Exp $\n");
+    fprintf(fd,";;; $Id: ccl.c,v 1.107 2003/08/02 13:34:24 grumbel Exp $\n");
 
     // Global options
     if( OriginalFogOfWar ) {
@@ -996,7 +1126,6 @@
     char* file;
     char* s;
     char buf[1024];
-    extern LISP fast_load(LISP lfname,LISP noeval);
 
     //
     // Load and evaluate configuration file
@@ -1022,17 +1151,19 @@
 */
 global void SaveCcl(FILE* file)
 {
+#ifdef USE_GUILE
+#else
     SCM list;
     extern SCM oblistvar;
 
     fprintf(file,"\n;;; -----------------------------------------\n");
-    fprintf(file,";;; MODULE: CCL $Id: ccl.c,v 1.106 2003/07/14 19:34:28 
grumbel Exp $\n\n");
+    fprintf(file,";;; MODULE: CCL $Id: ccl.c,v 1.107 2003/08/02 13:34:24 
grumbel Exp $\n\n");
 
-    for( list=oblistvar; CONSP(list); list=CDR(list) ) {
+    for(list = oblistvar; gh_list_p(list); list = gh_cdr(list) ) {
        SCM sym;
 
-       sym=CAR(list);
-       if( !gh_null_p(symbol_boundp(sym, NIL)) ) {
+       sym=gh_car(list);
+       if(symbol_boundp(sym, NIL)) {
            SCM value;
 
            fprintf(file,";;(define %s\n",get_c_string(sym));
@@ -1046,6 +1177,7 @@
 #endif
        }
     }
+#endif
 }
 
 //@}
Index: stratagus/src/clone/mainloop.c
diff -u stratagus/src/clone/mainloop.c:1.138 
stratagus/src/clone/mainloop.c:1.139
--- stratagus/src/clone/mainloop.c:1.138        Fri Jul 11 10:35:30 2003
+++ stratagus/src/clone/mainloop.c      Sat Aug  2 09:34:24 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: mainloop.c,v 1.138 2003/07/11 14:35:30 n0body Exp $
+//     $Id: mainloop.c,v 1.139 2003/08/02 13:34:24 grumbel Exp $
 
 //@{
 
@@ -34,6 +34,7 @@
 //     Includes
 //----------------------------------------------------------------------------
 
+#include <string.h>
 #include <stdio.h>
 #if defined(DEBUG) && defined(HIERARCHIC_PATHFINDER)
 #include <stdlib.h>
Index: stratagus/src/clone/unit.c
diff -u stratagus/src/clone/unit.c:1.280 stratagus/src/clone/unit.c:1.281
--- stratagus/src/clone/unit.c:1.280    Thu Jul 24 15:27:32 2003
+++ stratagus/src/clone/unit.c  Sat Aug  2 09:34:24 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit.c,v 1.280 2003/07/24 19:27:32 n0body Exp $
+//     $Id: unit.c,v 1.281 2003/08/02 13:34:24 grumbel Exp $
 
 //@{
 
@@ -323,7 +323,7 @@
        SCM fun;
 
        fun = gh_symbol2scm("gen-unit-name");
-       if (!gh_null_p(symbol_boundp(fun, NIL))) {
+       if (symbol_boundp(fun, NIL)) {
            SCM value;
 
            value = symbol_value(fun, NIL);
@@ -4273,7 +4273,7 @@
     int InRun, RunStart;
 
     fprintf(file,"\n;;; -----------------------------------------\n");
-    fprintf(file,";;; MODULE: units $Id: unit.c,v 1.280 2003/07/24 19:27:32 
n0body Exp $\n\n");
+    fprintf(file,";;; MODULE: units $Id: unit.c,v 1.281 2003/08/02 13:34:24 
grumbel Exp $\n\n");
 
     //
     // Local variables
Index: stratagus/src/editor/editloop.c
diff -u stratagus/src/editor/editloop.c:1.123 
stratagus/src/editor/editloop.c:1.124
--- stratagus/src/editor/editloop.c:1.123       Tue Jul 22 10:32:21 2003
+++ stratagus/src/editor/editloop.c     Sat Aug  2 09:34:24 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: editloop.c,v 1.123 2003/07/22 14:32:21 n0body Exp $
+//     $Id: editloop.c,v 1.124 2003/08/02 13:34:24 grumbel Exp $
 
 //@{
 
@@ -1802,7 +1802,6 @@
     char *s;
     char buf[PATH_MAX];
     CLFile *clf;
-    extern LISP fast_load(LISP lfname, LISP noeval);
     int scm;
 
     scm = 0;
Index: stratagus/src/game/campaign.c
diff -u stratagus/src/game/campaign.c:1.31 stratagus/src/game/campaign.c:1.32
--- stratagus/src/game/campaign.c:1.31  Fri Jul 11 10:35:30 2003
+++ stratagus/src/game/campaign.c       Sat Aug  2 09:34:24 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: campaign.c,v 1.31 2003/07/11 14:35:30 n0body Exp $
+//     $Id: campaign.c,v 1.32 2003/08/02 13:34:24 grumbel Exp $
 
 //@{
 
@@ -238,7 +238,7 @@
                    sublist=gh_cdr(sublist);
                } else if( gh_eq_p(value,gh_symbol2scm("align")) ) {
                    char* str;
-                   str=gh_scm2newstr(gh_car(sublist),NIL);
+                   str=gh_scm2newstr(gh_car(sublist), 0);
                    if( !strcmp(str,"left") ) {
                        (*text)->Align=PictureTextAlignLeft;
                    } else if( !strcmp(str,"center") ) {
@@ -249,7 +249,7 @@
                    free(str);
                    sublist=gh_cdr(sublist);
                } else if( gh_eq_p(value,gh_symbol2scm("text")) ) {
-                   (*text)->Text=gh_scm2newstr(gh_car(sublist),NIL);
+                  (*text)->Text = gh_scm2newstr(gh_car(sublist), 0);
                    sublist=gh_cdr(sublist);
                }
            }
@@ -529,7 +529,7 @@
     int i;
 
     fprintf(file,"\n;;; -----------------------------------------\n");
-    fprintf(file,";;; MODULE: campaign $Id: campaign.c,v 1.31 2003/07/11 
14:35:30 n0body Exp $\n\n");
+    fprintf(file,";;; MODULE: campaign $Id: campaign.c,v 1.32 2003/08/02 
13:34:24 grumbel Exp $\n\n");
     if( !CurrentCampaign ) {
        return;
     }
Index: stratagus/src/game/game.c
diff -u stratagus/src/game/game.c:1.98 stratagus/src/game/game.c:1.99
--- stratagus/src/game/game.c:1.98      Fri Jul 11 10:35:30 2003
+++ stratagus/src/game/game.c   Sat Aug  2 09:34:25 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: game.c,v 1.98 2003/07/11 14:35:30 n0body Exp $
+//     $Id: game.c,v 1.99 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -98,7 +98,7 @@
     }
     InitPlayers();
     lcm_prevent_recurse = 1;
-    gh_eval_file((char*)filename);
+    gh_load((char*)filename);
     lcm_prevent_recurse = 0;
 
 #if 0
Index: stratagus/src/game/loadgame.c
diff -u stratagus/src/game/loadgame.c:1.54 stratagus/src/game/loadgame.c:1.55
--- stratagus/src/game/loadgame.c:1.54  Fri Jul 11 10:35:30 2003
+++ stratagus/src/game/loadgame.c       Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: loadgame.c,v 1.54 2003/07/11 14:35:30 n0body Exp $
+//     $Id: loadgame.c,v 1.55 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -215,7 +215,6 @@
 global void LoadGame(char* filename)
 {
     int old_siod_verbose_level;
-    extern int siod_verbose_level;
     unsigned long game_cycle;
 
     CleanModules();
@@ -224,7 +223,7 @@
     siod_verbose_level=4;
     user_gc(SCM_BOOL_F);
     siod_verbose_level=old_siod_verbose_level;
-    gh_eval_file(filename);
+    gh_load(filename);
     user_gc(SCM_BOOL_F);
 
     game_cycle=GameCycle;
Index: stratagus/src/game/savegame.c
diff -u stratagus/src/game/savegame.c:1.27 stratagus/src/game/savegame.c:1.28
--- stratagus/src/game/savegame.c:1.27  Fri Jul 11 10:35:30 2003
+++ stratagus/src/game/savegame.c       Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: savegame.c,v 1.27 2003/07/11 14:35:30 n0body Exp $
+//     $Id: savegame.c,v 1.28 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -34,6 +34,7 @@
 --     Includes
 ----------------------------------------------------------------------------*/
 
+#include <string.h>
 #include <stdio.h>
 #if !defined(_MSC_VER) || !defined(_WIN32_WCE)
 #include <time.h>
@@ -100,7 +101,7 @@
     fprintf(file,";;;(save-game\n");
     fprintf(file,";;;  'comment\t\"Generated by Stratagus Version " VERSION 
"\"\n");
     fprintf(file,";;;  'comment\t\"Visit http://Stratagus.Org for more 
informations\"\n");
-    fprintf(file,";;;  'comment\t\"$Id: savegame.c,v 1.27 2003/07/11 14:35:30 
n0body Exp $\"\n");
+    fprintf(file,";;;  'comment\t\"$Id: savegame.c,v 1.28 2003/08/02 13:34:25 
grumbel Exp $\"\n");
     fprintf(file,";;;  'type\t\"%s\"\n","single-player");
     fprintf(file,";;;  'date\t\"%s\"\n",s);
     fprintf(file,";;;  'map\t\"%s\"\n",TheMap.Description);
@@ -112,7 +113,7 @@
     { SCM var;
        fprintf(file,";;;  'media\t'");
        var=gh_symbol2scm("media-version");
-       if( !gh_null_p(symbol_boundp(var, NIL)) ) {
+       if (symbol_boundp(var, NIL)) {
            var=symbol_value(var,NIL);
            lprin1f(var,file);
        } else {
Index: stratagus/src/game/trigger.c
diff -u stratagus/src/game/trigger.c:1.40 stratagus/src/game/trigger.c:1.41
--- stratagus/src/game/trigger.c:1.40   Fri Jul 18 16:26:20 2003
+++ stratagus/src/game/trigger.c        Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: trigger.c,v 1.40 2003/07/18 20:26:20 grumbel Exp $
+//     $Id: trigger.c,v 1.41 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -46,7 +46,6 @@
 #include "trigger.h"
 #include "campaign.h"
 #include "interface.h"
-#include "siodp.h"
 
 /*----------------------------------------------------------------------------
 --     Declarations
@@ -912,15 +911,18 @@
     // Make a list of all triggers.
     //         A trigger is a pair of condition and action
     //
-    var=gh_symbol2scm("*triggers*");
+    var = gh_symbol2scm("*triggers*");
+
     if( gh_null_p(symbol_value(var,NIL)) ) {
+         puts("Trigger not set, defining trigger");
        setvar(var, cons(cons(condition,action),NIL), NIL);
     } else {
+        // Search for the last element in the list
        var=symbol_value(var,NIL);
        while( !gh_null_p(gh_cdr(var)) ) {
            var=gh_cdr(var);
        }
-       setcdr(var,cons(cons(condition,action),NIL));
+       gh_set_cdr_x(var, cons(cons(condition,action),NIL));
     }
 
     return SCM_UNSPECIFIED;
@@ -972,7 +974,7 @@
     value=NULL;
 
     while( !gh_null_p(script) ) {
-       value=gh_eval(gh_car(script),NIL);
+       value = gh_eval(gh_car(script), NIL);
        script=gh_cdr(script);
        if( WaitFrame>FrameCounter ) {
            WaitScript=script;
@@ -995,11 +997,11 @@
 local void TriggerRemoveTrigger(SCM trig)
 {
     if( !gh_null_p(Trigger) ) {
-       setcar(trig,gh_car(Trigger));
-       setcdr(trig,gh_cdr(Trigger));
+       gh_set_car_x(trig,gh_car(Trigger));
+       gh_set_cdr_x(trig,gh_cdr(Trigger));
     } else {
-       setcar(trig,NIL);
-       setcdr(trig,NIL);
+       gh_set_car_x(trig, NIL);
+       gh_set_cdr_x(trig, NIL);
     }
     Trigger=trig;
 }
@@ -1047,7 +1049,7 @@
                script=gh_cdr(script);
            }
            // If condition is true execute action
-           if( !gh_null_p(value) ) {
+           if( value != SCM_BOOL_F ) {
                if( TriggerExecuteAction(gh_cdr(pair)) ) {
                    TriggerRemoveTrigger(trig);
                }
@@ -1098,9 +1100,11 @@
 **     @param exp      Expression
 **     @param f        File to print to
 */
-local void PrintTrigger(LISP exp,FILE *f)
+local void PrintTrigger(SCM exp, FILE *f)
 {
-    LISP tmp;
+#ifdef USE_GUILE
+#else
+    SCM tmp;
     long n;
 //    struct user_type_hooks *p;
     extern char *subr_kind_str(long);
@@ -1176,6 +1180,7 @@
        }
 #endif
     }
+#endif
 }
 
 /**
@@ -1190,7 +1195,7 @@
     int trigger;
 
     fprintf(file,"\n;;; -----------------------------------------\n");
-    fprintf(file,";;; MODULE: trigger $Id: trigger.c,v 1.40 2003/07/18 
20:26:20 grumbel Exp $\n\n");
+    fprintf(file,";;; MODULE: trigger $Id: trigger.c,v 1.41 2003/08/02 
13:34:25 grumbel Exp $\n\n");
 
     i=0;
     trigger=-1;
Index: stratagus/src/include/ccl.h
diff -u stratagus/src/include/ccl.h:1.36 stratagus/src/include/ccl.h:1.37
--- stratagus/src/include/ccl.h:1.36    Mon Jul 14 15:34:28 2003
+++ stratagus/src/include/ccl.h Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl.h,v 1.36 2003/07/14 19:34:28 grumbel Exp $
+//     $Id: ccl.h,v 1.37 2003/08/02 13:34:25 grumbel Exp $
 
 #ifndef __CCL_H__
 #define __CCL_H__
@@ -37,9 +37,43 @@
 --     Includes
 ----------------------------------------------------------------------------*/
 
-#include <string.h>
-#include "siod.h"
+#ifdef USE_GUILE
+#  include <guile/gh.h>
+#  define get_c_string(lisp)     CclConvertToString(lisp)
+#  define try_get_c_string(lisp) CclConvertToString(lisp)
+#  define symbol_value(x, env)   scm_variable_ref(scm_lookup(x))
+#  define NIL                    SCM_EOL
+#  define cons(a, b)             gh_cons(a, b)
+#  define symbol_boundp(x, env)  (!SCM_UNBNDP(x))
+#  define fast_load(s_filename, bogus)  scm_primitive_load(s_filename)
+#  define cons_array              gh_make_vector
+#  define gh_eval(expr, env)      scm_primitive_eval(expr)
+#  define setvar(sym, value, env) scm_define(sym,value)
+#  define vload(buf,cflag,rflag)  gh_load(buf)
+#  define errl(message, value)    { fputs(message, stdout); gh_display(value); 
putchar('\n'); }
+#  define lprin1f(var, file)
+#  define gh_new_procedureN(name, proc) gh_new_procedure(name, proc, 0, 0, 1)
+#  define aset1(array, pos, value)      gh_vector_set_x(array, pos, value)
+#  define repl_c_string(msg, a, b, c  ) gh_eval_str(msg)
+#  define print_welcome()         
+#  define user_gc(a)              scm_gc()
+#  define gh_scm2newstr(scm, lenp) \
+  (gh_symbol_p(scm) ? gh_symbol2newstr(scm, lenp) : gh_scm2newstr(scm,lenp))
+#  define gh_scm2int(val) \
+  (gh_inexact_p(val) ? (int)gh_scm2double(val) : gh_scm2int(val))
+#  define gh_scm2long(val) \
+  (gh_inexact_p(val) ? (long)gh_scm2double(val) : gh_scm2long(val))
+
+extern int siod_verbose_level;
+struct gen_printio* f;
+typedef scm_t_bits ccl_smob_type_t;
+
+#else
+#  include <string.h>
+#  include "siod.h"
+#  include "siodp.h"
 
+extern LISP fast_load(LISP lfname,LISP noeval);
 /*----------------------------------------------------------------------------
 --     Macros
 ----------------------------------------------------------------------------*/
@@ -62,8 +96,12 @@
 #define gh_cddr(lisp)          cddr(lisp)
 #define gh_length(lisp)                nlength(lisp)
 
+#define gh_set_car_x(pair, val) setcar(pair, val)
+#define gh_set_cdr_x(pair, val) setcdr(pair, val)
+
 #define gh_exact_p(lisp)       TYPEP(lisp,tc_flonum)
 #define gh_scm2int(lisp)       (long)FLONM(lisp)
+#define gh_scm2long(lisp)      (long)FLONM(lisp)
 #define gh_int2scm(num)                flocons(num)
 
 #define gh_string_p(lisp)      TYPEP(lisp,tc_string)
@@ -87,7 +125,7 @@
 #define gh_display(lisp)       lprin1f(lisp,stdout)
 #define gh_newline()           fprintf(stdout,"\n")
 
-#define gh_eval_file(str)      vload(str,0,0)
+#define gh_load(str)           vload(str,0,0)
 
 #define gh_apply(proc,args)    lapply(proc,args)
 #define gh_eval(proc,env)      leval(proc,env)
@@ -103,7 +141,12 @@
 #define SCM_BOOL_T     sym_t
 #define SCM_BOOL_F     NIL
 
+#define gh_vector_set_x(array, pos, value) aset1(array, pos, value) 
+
 extern LISP sym_t;
+typedef long ccl_smob_type_t;
+
+#endif // !USE_GUILE
 
 //extern SCM CclEachSecond;            /// Scheme function called each second
 
@@ -117,6 +160,12 @@
 /*----------------------------------------------------------------------------
 --     Functions
 ----------------------------------------------------------------------------*/
+
+extern char*           CclConvertToString(SCM scm);
+extern ccl_smob_type_t CclMakeSmobType(const char* name);
+extern SCM             CclMakeSmobObj(ccl_smob_type_t tag, void* ptr);
+extern void*           CclGetSmobData(SCM smob);
+extern ccl_smob_type_t CclGetSmobType(SCM smob);
 
 extern void CclGcProtect(SCM obj);     /// Protect scm object for GC
 extern void CclGcUnprotect(SCM obj);   /// Unprotect scm object for GC
Index: stratagus/src/include/siodp.h
diff -u stratagus/src/include/siodp.h:1.4 stratagus/src/include/siodp.h:1.5
--- stratagus/src/include/siodp.h:1.4   Wed Jun 20 20:02:39 2001
+++ stratagus/src/include/siodp.h       Sat Aug  2 09:34:25 2003
@@ -7,10 +7,11 @@
 Declarations which are private to SLIB.C internals.
 However, some of these should be moved to siod.h
 
- $Id: siodp.h,v 1.4 2001/06/21 00:02:39 johns Exp $
+ $Id: siodp.h,v 1.5 2003/08/02 13:34:25 grumbel Exp $
 
 */
 
+#include <setjmp.h>
 
 extern char *tkbuffer;
 extern LISP heap,heap_end,heap_org;
Index: stratagus/src/map/ccl_map.c
diff -u stratagus/src/map/ccl_map.c:1.34 stratagus/src/map/ccl_map.c:1.35
--- stratagus/src/map/ccl_map.c:1.34    Thu Jul 24 15:27:33 2003
+++ stratagus/src/map/ccl_map.c Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_map.c,v 1.34 2003/07/24 19:27:33 n0body Exp $
+//     $Id: ccl_map.c,v 1.35 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -34,6 +34,7 @@
 --     Includes
 ----------------------------------------------------------------------------*/
 
+#include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -94,7 +95,7 @@
 
            str=gh_scm2newstr(data,NULL);
            strncpy(TheMap.Description,str,sizeof(TheMap.Description));
-           TheMap.Info->Description=strdup(str);
+           TheMap.Info->Description = strdup(str);
            free(str);
        } else if( gh_eq_p(value,gh_symbol2scm("the-map")) ) {
            data=gh_car(list);
Index: stratagus/src/map/ccl_tileset.c
diff -u stratagus/src/map/ccl_tileset.c:1.28 
stratagus/src/map/ccl_tileset.c:1.29
--- stratagus/src/map/ccl_tileset.c:1.28        Fri Jul 11 10:35:32 2003
+++ stratagus/src/map/ccl_tileset.c     Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_tileset.c,v 1.28 2003/07/11 14:35:32 n0body Exp $
+//     $Id: ccl_tileset.c,v 1.29 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -34,6 +34,7 @@
 --     Includes
 ----------------------------------------------------------------------------*/
 
+#include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -509,7 +510,7 @@
        num=gh_scm2int(value);
        value=gh_car(list);
        list=gh_cdr(list);
-       unit=gh_scm2newstr(value,NIL);
+       unit=gh_scm2newstr(value, 0);
        sprintf(buf,"%d",num);
        if( (h=(char**)hash_find(tileset->ItemsHash,buf)) != NULL ) {
            free(*h);
Index: stratagus/src/map/tileset.c
diff -u stratagus/src/map/tileset.c:1.46 stratagus/src/map/tileset.c:1.47
--- stratagus/src/map/tileset.c:1.46    Fri Jul 11 10:35:32 2003
+++ stratagus/src/map/tileset.c Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: tileset.c,v 1.46 2003/07/11 14:35:32 n0body Exp $
+//     $Id: tileset.c,v 1.47 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -38,11 +38,11 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "ccl.h"
 #include "stratagus.h"
 #include "tileset.h"
 #include "map.h"
 #include "iolib.h"
-#include "siod.h"
 
 /*----------------------------------------------------------------------------
 --     Variables
@@ -725,7 +725,7 @@
 
     fprintf(file, "\n;;; -----------------------------------------\n");
     fprintf(file,
-       ";;; MODULE: tileset $Id: tileset.c,v 1.46 2003/07/11 14:35:32 n0body 
Exp $\n\n");
+       ";;; MODULE: tileset $Id: tileset.c,v 1.47 2003/08/02 13:34:25 grumbel 
Exp $\n\n");
 
     //  Original number to internal tileset name
 
Index: stratagus/src/network/commands.c
diff -u stratagus/src/network/commands.c:1.61 
stratagus/src/network/commands.c:1.62
--- stratagus/src/network/commands.c:1.61       Tue Jul 22 10:32:22 2003
+++ stratagus/src/network/commands.c    Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: commands.c,v 1.61 2003/07/22 14:32:22 n0body Exp $
+//     $Id: commands.c,v 1.62 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -145,7 +145,7 @@
        fprintf(LogFile,"(replay-log\n");
        fprintf(LogFile,"  'comment\t\"Generated by Stratagus Version " VERSION 
"\"\n");
        fprintf(LogFile,"  'comment\t\"Visit http://Stratagus.Org for more 
information\"\n");
-       fprintf(LogFile,"  'comment\t\"$Id: commands.c,v 1.61 2003/07/22 
14:32:22 n0body Exp $\"\n");
+       fprintf(LogFile,"  'comment\t\"$Id: commands.c,v 1.62 2003/08/02 
13:34:25 grumbel Exp $\"\n");
        if( NetworkFildes==-1 ) {
            fprintf(LogFile,"  'type\t\"%s\"\n","single-player");
            fprintf(LogFile,"  'race\t%d\n",GameSettings.Presets[0].Race);
@@ -246,7 +246,7 @@
        while( !gh_null_p(gh_cdr(tmp)) ) {
            tmp=gh_cdr(tmp);
        }
-       setcdr(tmp,cons(list,NIL));
+       gh_set_cdr_x(tmp,cons(list,NIL));
     }
 
     return SCM_UNSPECIFIED;
@@ -360,7 +360,7 @@
                    num=gh_scm2int(gh_car(sublist));
                    sublist=gh_cdr(sublist);
                } else if( gh_eq_p(value,gh_symbol2scm("name")) ) {
-                   name=gh_scm2newstr(gh_car(sublist),NIL);
+                   name=gh_scm2newstr(gh_car(sublist), 0);
                    sublist=gh_cdr(sublist);
                } else if( gh_eq_p(value,gh_symbol2scm("race")) ) {
                    race=gh_scm2int(gh_car(sublist));
Index: stratagus/src/pathfinder/ccl_pathfinder.c
diff -u stratagus/src/pathfinder/ccl_pathfinder.c:1.19 
stratagus/src/pathfinder/ccl_pathfinder.c:1.20
--- stratagus/src/pathfinder/ccl_pathfinder.c:1.19      Fri Jul 11 10:35:33 2003
+++ stratagus/src/pathfinder/ccl_pathfinder.c   Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_pathfinder.c,v 1.19 2003/07/11 14:35:33 n0body Exp $
+//     $Id: ccl_pathfinder.c,v 1.20 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -89,7 +89,7 @@
                AStarFixedUnitCrossingCost=i;
            }
        } else if( gh_eq_p(value,gh_symbol2scm("moving-unit-cost")) ) {
-           i=gh_scm2int(list);
+           i=gh_scm2int(gh_car(list));
            list=gh_cdr(list);
            if( i<=0) {
                PrintFunction();
Index: stratagus/src/sound/ccl_sound.c
diff -u stratagus/src/sound/ccl_sound.c:1.49 
stratagus/src/sound/ccl_sound.c:1.50
--- stratagus/src/sound/ccl_sound.c:1.49        Fri Jul 11 10:35:33 2003
+++ stratagus/src/sound/ccl_sound.c     Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_sound.c,v 1.49 2003/07/11 14:35:33 n0body Exp $
+//     $Id: ccl_sound.c,v 1.50 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -34,6 +34,7 @@
 --     Includes
 ----------------------------------------------------------------------------*/
 
+#include <string.h>
 #include <stdio.h>
 
 #include "stratagus.h"
@@ -56,10 +57,10 @@
 ** C representation for the siod sound type
 ** ALPHA VERSION!!!!!!!!!
 */
-local long SiodSoundTag;
+local ccl_smob_type_t SiodSoundTag;
 
-#define CCL_SOUNDP(x)  TYPEP(x,SiodSoundTag)
-#define CCL_SOUND_ID(x) ( (SoundId)CDR(x) )
+#define CCL_SOUNDP(x)  (CclGetSmobType(x) == SiodSoundTag)
+#define CCL_SOUND_ID(x) ((SoundId)CclGetSmobData(x))
 
 /*----------------------------------------------------------------------------
 --     Functions
@@ -74,13 +75,9 @@
 */
 local SCM sound_id_ccl(SoundId id)
 {
-     SCM sound_id;
-
-     sound_id=cons(NIL,NIL);
-     sound_id->type=SiodSoundTag;
-     sound_id->storage_as.cons.cdr=(SCM)id;
-
-     return sound_id;
+    SCM sound_id;
+    sound_id = CclMakeSmobObj(SiodSoundTag, id);
+    return sound_id;
 }
 
 /**
@@ -669,7 +666,7 @@
 */
 global void SoundCclRegister(void)
 {
-    SiodSoundTag=allocate_user_tc();
+    SiodSoundTag = CclMakeSmobType("Sound");
 
     gh_new_procedure1_0("set-sound-volume!",CclSetSoundVolume);
     gh_new_procedure1_0("set-music-volume!",CclSetMusicVolume);
Index: stratagus/src/sound/sound_server.c
diff -u stratagus/src/sound/sound_server.c:1.118 
stratagus/src/sound/sound_server.c:1.119
--- stratagus/src/sound/sound_server.c:1.118    Fri Jul 11 10:35:33 2003
+++ stratagus/src/sound/sound_server.c  Sat Aug  2 09:34:25 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: sound_server.c,v 1.118 2003/07/11 14:35:33 n0body Exp $
+//     $Id: sound_server.c,v 1.119 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -190,7 +190,7 @@
            // FIXME: we are inside the SDL callback!
            if (CallbackMusic) {
                cb = gh_symbol2scm("music-stopped");
-               if (!gh_null_p(symbol_boundp(cb, NIL))) {
+               if (symbol_boundp(cb, NIL)) {
                    SCM value;
 
                    value = symbol_value(cb, NIL);
Index: stratagus/src/ui/ccl_ui.c
diff -u stratagus/src/ui/ccl_ui.c:1.116 stratagus/src/ui/ccl_ui.c:1.117
--- stratagus/src/ui/ccl_ui.c:1.116     Fri Jul 11 10:35:33 2003
+++ stratagus/src/ui/ccl_ui.c   Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_ui.c,v 1.116 2003/07/11 14:35:33 n0body Exp $
+//     $Id: ccl_ui.c,v 1.117 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -2524,7 +2524,7 @@
            value=gh_car(list);
            list=gh_cdr(list);
            if( gh_exact_p(value) ) {
-               sprintf(buf,"%ld",gh_scm2int(value));
+               sprintf(buf,"%ld",gh_scm2long(value));
                s1=strdup(buf);
            } else {
                s1=gh_scm2newstr(value,NULL);
@@ -2875,7 +2875,8 @@
 local SCM CclAddKeystrokeHelp(SCM list)
 {
     SCM value;
-    char *s1, *s2;
+    char *s1 = 0;
+    char *s2 = 0;
     int n;
 
     if (!gh_null_p(list)) {
Index: stratagus/src/ui/interface.c
diff -u stratagus/src/ui/interface.c:1.131 stratagus/src/ui/interface.c:1.132
--- stratagus/src/ui/interface.c:1.131  Fri Jul 11 10:35:33 2003
+++ stratagus/src/ui/interface.c        Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: interface.c,v 1.131 2003/07/11 14:35:33 n0body Exp $
+//     $Id: interface.c,v 1.132 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -36,6 +36,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "stratagus.h"
 #include "video.h"
Index: stratagus/src/ui/menus.c
diff -u stratagus/src/ui/menus.c:1.553 stratagus/src/ui/menus.c:1.554
--- stratagus/src/ui/menus.c:1.553      Tue Jul 22 10:32:22 2003
+++ stratagus/src/ui/menus.c    Sat Aug  2 09:34:25 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: menus.c,v 1.553 2003/07/22 14:32:22 n0body Exp $
+//     $Id: menus.c,v 1.554 2003/08/02 13:34:25 grumbel Exp $
 
 //@{
 
@@ -1812,7 +1812,7 @@
        MusicOff = 0;
        if (CallbackMusic) {
            cb = gh_symbol2scm("music-stopped");
-           if (!gh_null_p(symbol_boundp(cb, NIL))) {
+           if (symbol_boundp(cb, NIL)) {
                SCM value;
 
                value = symbol_value(cb, NIL);
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.69 
stratagus/src/unit/ccl_unittype.c:1.70
--- stratagus/src/unit/ccl_unittype.c:1.69      Thu Jul 24 15:27:33 2003
+++ stratagus/src/unit/ccl_unittype.c   Sat Aug  2 09:34:26 2003
@@ -26,14 +26,14 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unittype.c,v 1.69 2003/07/24 19:27:33 n0body Exp $
+//     $Id: ccl_unittype.c,v 1.70 2003/08/02 13:34:26 grumbel Exp $
 
 //@{
 
 /*----------------------------------------------------------------------------
 --     Includes
 ----------------------------------------------------------------------------*/
-
+#include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -59,7 +59,7 @@
 
 global _AnimationsHash AnimationsHash; /// Animations hash table
 
-local long SiodUnitTypeTag;            /// siod unit-type object
+local ccl_smob_type_t SiodUnitTypeTag;         /// siod unit-type object
 
 /*----------------------------------------------------------------------------
 --     Functions
@@ -594,16 +594,20 @@
 */
 global UnitType* CclGetUnitType(SCM ptr)
 {
-    const char* str;
+    char* str;
 
     // Be kind allow also strings or symbols
-    if( (str=try_get_c_string(ptr)) ) {
-       return UnitTypeByIdent(str);
-    }
-    if( NTYPEP(ptr,SiodUnitTypeTag) ) {
-       errl("not an unit-type",ptr);
+    if( (str = CclConvertToString(ptr)) != NULL )  {
+        printf("CclGetUnitType: %s\n", str);
+        UnitType* type = UnitTypeByIdent(str);
+        free(str);
+        return type;
+    } else if (CclGetSmobType(ptr) == SiodUnitTypeTag)  {
+        return CclGetSmobData(ptr);
+    } else {
+        errl("CclGetUnitType: not an unit-type", ptr);
+        return 0;
     }
-    return (UnitType*)CAR(ptr);
 }
 
 /**
@@ -612,14 +616,26 @@
 **     @param ptr      Scheme object.
 **     @param f        Output structure.
 */
-local void CclUnitTypePrin1(SCM ptr,struct gen_printio* f)
+local void CclUnitTypePrin1(SCM ptr, struct gen_printio* f)
 {
+#ifndef USE_GUILE
     char buf[1024];
     const UnitType* type;
 
-    type=CclGetUnitType(ptr);
-    sprintf(buf,"#<UnitType %p %s>",type,type->Ident);
+    type = CclGetUnitType(ptr);
+
+    if (type) {
+        if (type->Ident) {
+            sprintf(buf, "#<UnitType %p '%s'>", type, type->Ident);
+        } else {
+            sprintf(buf, "#<UnitType %p '(null)'>", type);
+        }
+    } else {
+        sprintf(buf, "#<UnitType NULL>");
+    }
+
     gput_st(f,buf);
+#endif
 }
 
 /**
@@ -631,19 +647,22 @@
 */
 local SCM CclUnitType(SCM ident)
 {
-    const char* str;
-    const UnitType* type;
-    SCM value;
-
-    str=get_c_string(ident);
-
-    type=UnitTypeByIdent(str);
-
-    value=cons(NIL,NIL);
-    value->type=SiodUnitTypeTag;
-    CAR(value)=(SCM)type;
-
-    return value;
+    char* str;
+    UnitType* type;
+    
+    str = CclConvertToString(ident);
+    if (str)
+      {
+        type = UnitTypeByIdent(str);
+        printf("CclUnitType: '%s' -> '%ld'\n", str, (long)type);
+        free(str);
+        return CclMakeSmobObj(SiodUnitTypeTag, type);
+      }
+    else
+      {
+        errl("CclUnitType: no unittype by ident: ", ident);
+        return SCM_BOOL_F;
+      }
 }
 
 /**
@@ -657,13 +676,11 @@
     SCM value;
     int i;
 
-    array=cons_array(flocons(UnitTypeMax),NIL);
+    array = cons_array(gh_int2scm(UnitTypeMax), NIL);
 
     for( i=0; i<UnitTypeMax; ++i ) {
-       value=cons(NIL,NIL);
-       value->type=SiodUnitTypeTag;
-       CAR(value)=(SCM)&UnitTypes[i];
-       array->storage_as.lisp_array.data[i]=value;
+      value = CclMakeSmobObj(SiodUnitTypeTag, &UnitTypes[i]);
+      gh_vector_set_x(array, gh_int2scm(i), value);
     }
     return array;
 }
@@ -881,8 +898,11 @@
     gh_new_procedureN("define-unit-type",CclDefineUnitType);
     gh_new_procedureN("define-unit-stats",CclDefineUnitStats);
 
-    SiodUnitTypeTag=allocate_user_tc();
+    SiodUnitTypeTag = CclMakeSmobType("UnitType");
+
+#ifndef USE_GUILE
     set_print_hooks(SiodUnitTypeTag,CclUnitTypePrin1);
+#endif 
 
     gh_new_procedure1_0("unit-type",CclUnitType);
     gh_new_procedure0_0("unit-type-array",CclUnitTypeArray);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]