-/* see copyright notice in squirrel.h */\r
-#include <squirrel.h>\r
-#include <time.h>\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <sqstdsystem.h>\r
-\r
-#ifdef SQUNICODE\r
-#include <wchar.h>\r
-#define scgetenv _wgetenv\r
-#define scsystem _wsystem\r
-#define scasctime _wasctime\r
-#define scremove _wremove\r
-#define screname _wrename\r
-#else\r
-#define scgetenv getenv\r
-#define scsystem system\r
-#define scasctime asctime\r
-#define scremove remove\r
-#define screname rename\r
-#endif\r
-\r
-static int _system_getenv(HSQUIRRELVM v)\r
-{\r
- const SQChar *s;\r
- if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){\r
- sq_pushstring(v,scgetenv(s),-1);\r
- return 1;\r
- }\r
- return 0;\r
-}\r
-\r
-\r
-static int _system_system(HSQUIRRELVM v)\r
-{\r
- const SQChar *s;\r
- if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){\r
- sq_pushinteger(v,scsystem(s));\r
- return 1;\r
- }\r
- return sq_throwerror(v,_SC("wrong param"));\r
-}\r
-\r
-\r
-static int _system_clock(HSQUIRRELVM v)\r
-{\r
- sq_pushfloat(v,((SQFloat)clock())/(SQFloat)CLOCKS_PER_SEC);\r
- return 1;\r
-}\r
-\r
-static int _system_time(HSQUIRRELVM v)\r
-{\r
- time_t t;\r
- time(&t);\r
- sq_pushinteger(v,*((SQInteger *)&t));\r
- return 1;\r
-}\r
-\r
-static int _system_remove(HSQUIRRELVM v)\r
-{\r
- const SQChar *s;\r
- sq_getstring(v,2,&s);\r
- if(scremove(s)==-1)\r
- return sq_throwerror(v,_SC("remove() failed"));\r
- return 0;\r
-}\r
-\r
-static int _system_rename(HSQUIRRELVM v)\r
-{\r
- const SQChar *oldn,*newn;\r
- sq_getstring(v,2,&oldn);\r
- sq_getstring(v,3,&newn);\r
- if(screname(oldn,newn)==-1)\r
- return sq_throwerror(v,_SC("rename() failed"));\r
- return 0;\r
-}\r
-\r
-static void _set_integer_slot(HSQUIRRELVM v,const SQChar *name,SQInteger val)\r
-{\r
- sq_pushstring(v,name,-1);\r
- sq_pushinteger(v,val);\r
- sq_rawset(v,-3);\r
-}\r
-\r
-static int _system_date(HSQUIRRELVM v)\r
-{\r
- time_t t;\r
- SQInteger format = 'l';\r
- if(sq_gettop(v) > 1) {\r
- sq_getinteger(v,2,(SQInteger*)&t);\r
- if(sq_gettop(v) > 2) {\r
- sq_getinteger(v,3,(SQInteger*)&format);\r
- }\r
- }\r
- else {\r
- time(&t);\r
- }\r
- tm *date;\r
- if(format == 'u')\r
- date = gmtime(&t);\r
- else\r
- date = localtime(&t);\r
- if(!date)\r
- return sq_throwerror(v,_SC("crt api failure"));\r
- sq_newtable(v);\r
- _set_integer_slot(v, _SC("sec"), date->tm_sec);\r
- _set_integer_slot(v, _SC("min"), date->tm_min);\r
- _set_integer_slot(v, _SC("hour"), date->tm_hour);\r
- _set_integer_slot(v, _SC("day"), date->tm_mday);\r
- _set_integer_slot(v, _SC("month"), date->tm_mon);\r
- _set_integer_slot(v, _SC("year"), date->tm_year+1900);\r
- _set_integer_slot(v, _SC("wday"), date->tm_wday);\r
- _set_integer_slot(v, _SC("yday"), date->tm_yday);\r
- return 1;\r
-}\r
-\r
-\r
-\r
-#define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_system_##name,nparams,pmask}\r
-static SQRegFunction systemlib_funcs[]={\r
- _DECL_FUNC(getenv,2,_SC(".s")),\r
- _DECL_FUNC(system,2,_SC(".s")),\r
- _DECL_FUNC(clock,1,NULL),\r
- _DECL_FUNC(time,1,NULL),\r
- _DECL_FUNC(date,-1,_SC(".nn")),\r
- _DECL_FUNC(remove,2,_SC(".s")),\r
- _DECL_FUNC(rename,3,_SC(".ss")),\r
- {0,0}\r
-};\r
-\r
-\r
-int sqstd_register_systemlib(HSQUIRRELVM v)\r
-{\r
- int i=0;\r
- while(systemlib_funcs[i].name!=0)\r
- {\r
- sq_pushstring(v,systemlib_funcs[i].name,-1);\r
- sq_newclosure(v,systemlib_funcs[i].f,0);\r
- sq_setparamscheck(v,systemlib_funcs[i].nparamscheck,systemlib_funcs[i].typemask);\r
- sq_setnativeclosurename(v,-1,systemlib_funcs[i].name);\r
- sq_createslot(v,-3);\r
- i++;\r
- }\r
- return 1;\r
-}\r
+/* see copyright notice in squirrel.h */
+#include <squirrel.h>
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sqstdsystem.h>
+
+#ifdef SQUNICODE
+#include <wchar.h>
+#define scgetenv _wgetenv
+#define scsystem _wsystem
+#define scasctime _wasctime
+#define scremove _wremove
+#define screname _wrename
+#else
+#define scgetenv getenv
+#define scsystem system
+#define scasctime asctime
+#define scremove remove
+#define screname rename
+#endif
+
+static SQInteger _system_getenv(HSQUIRRELVM v)
+{
+ const SQChar *s;
+ if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){
+ sq_pushstring(v,scgetenv(s),-1);
+ return 1;
+ }
+ return 0;
+}
+
+
+static SQInteger _system_system(HSQUIRRELVM v)
+{
+ const SQChar *s;
+ if(SQ_SUCCEEDED(sq_getstring(v,2,&s))){
+ sq_pushinteger(v,scsystem(s));
+ return 1;
+ }
+ return sq_throwerror(v,_SC("wrong param"));
+}
+
+
+static SQInteger _system_clock(HSQUIRRELVM v)
+{
+ sq_pushfloat(v,((SQFloat)clock())/(SQFloat)CLOCKS_PER_SEC);
+ return 1;
+}
+
+static SQInteger _system_time(HSQUIRRELVM v)
+{
+ time_t t;
+ time(&t);
+ sq_pushinteger(v,*((SQInteger *)&t));
+ return 1;
+}
+
+static SQInteger _system_remove(HSQUIRRELVM v)
+{
+ const SQChar *s;
+ sq_getstring(v,2,&s);
+ if(scremove(s)==-1)
+ return sq_throwerror(v,_SC("remove() failed"));
+ return 0;
+}
+
+static SQInteger _system_rename(HSQUIRRELVM v)
+{
+ const SQChar *oldn,*newn;
+ sq_getstring(v,2,&oldn);
+ sq_getstring(v,3,&newn);
+ if(screname(oldn,newn)==-1)
+ return sq_throwerror(v,_SC("rename() failed"));
+ return 0;
+}
+
+static void _set_integer_slot(HSQUIRRELVM v,const SQChar *name,SQInteger val)
+{
+ sq_pushstring(v,name,-1);
+ sq_pushinteger(v,val);
+ sq_rawset(v,-3);
+}
+
+static SQInteger _system_date(HSQUIRRELVM v)
+{
+ time_t t;
+ SQInteger it;
+ SQInteger format = 'l';
+ if(sq_gettop(v) > 1) {
+ sq_getinteger(v,2,&it);
+ t = it;
+ if(sq_gettop(v) > 2) {
+ sq_getinteger(v,3,(SQInteger*)&format);
+ }
+ }
+ else {
+ time(&t);
+ }
+ tm *date;
+ if(format == 'u')
+ date = gmtime(&t);
+ else
+ date = localtime(&t);
+ if(!date)
+ return sq_throwerror(v,_SC("crt api failure"));
+ sq_newtable(v);
+ _set_integer_slot(v, _SC("sec"), date->tm_sec);
+ _set_integer_slot(v, _SC("min"), date->tm_min);
+ _set_integer_slot(v, _SC("hour"), date->tm_hour);
+ _set_integer_slot(v, _SC("day"), date->tm_mday);
+ _set_integer_slot(v, _SC("month"), date->tm_mon);
+ _set_integer_slot(v, _SC("year"), date->tm_year+1900);
+ _set_integer_slot(v, _SC("wday"), date->tm_wday);
+ _set_integer_slot(v, _SC("yday"), date->tm_yday);
+ return 1;
+}
+
+
+
+#define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_system_##name,nparams,pmask}
+static SQRegFunction systemlib_funcs[]={
+ _DECL_FUNC(getenv,2,_SC(".s")),
+ _DECL_FUNC(system,2,_SC(".s")),
+ _DECL_FUNC(clock,1,NULL),
+ _DECL_FUNC(time,1,NULL),
+ _DECL_FUNC(date,-1,_SC(".nn")),
+ _DECL_FUNC(remove,2,_SC(".s")),
+ _DECL_FUNC(rename,3,_SC(".ss")),
+ {0,0}
+};
+
+
+SQInteger sqstd_register_systemlib(HSQUIRRELVM v)
+{
+ SQInteger i=0;
+ while(systemlib_funcs[i].name!=0)
+ {
+ sq_pushstring(v,systemlib_funcs[i].name,-1);
+ sq_newclosure(v,systemlib_funcs[i].f,0);
+ sq_setparamscheck(v,systemlib_funcs[i].nparamscheck,systemlib_funcs[i].typemask);
+ sq_setnativeclosurename(v,-1,systemlib_funcs[i].name);
+ sq_createslot(v,-3);
+ i++;
+ }
+ return 1;
+}