Back to index

plt-scheme  4.2.1
dynexmpl.c
Go to the documentation of this file.
00001 
00002 /* Example dynamically-loaded MzScheme extension, but not a good one.
00003 
00004    For example extensions, see plt/collects/mzscheme/examples. */
00005 
00006 #include "escheme.h"
00007 #include <time.h>
00008 
00009 static Scheme_Object *sch_date(int argc, Scheme_Object **argv)
00010 {
00011   time_t clock;
00012   struct tm *now;
00013   char *str;
00014 
00015   if (argc)
00016     scheme_wrong_count("date", 0, 0, argc, argv);
00017 
00018   time(&clock);
00019   now = localtime(&clock);
00020   str = asctime(now);
00021 
00022   /* Get rid of newline */
00023   str[24] = 0;
00024 
00025   return scheme_make_string(str);
00026 }
00027 
00028 Scheme_Object *scheme_reload(Scheme_Env *env)
00029 {
00030   scheme_add_global("date", scheme_make_prim(sch_date), env);
00031 
00032   return scheme_void;
00033 }
00034 
00035 Scheme_Object *scheme_initialize(Scheme_Env *env)
00036 {
00037   return scheme_reload(env);
00038 }