00001
00002
00003
00004
00005
00006
00007
00008 #include "extern.h"
00009 #ifndef OS2_PORT
00010 #include "built_ins.h"
00011
00012 #include "modules.h"
00013 #include "sys.h"
00014 #include <dbm.h>
00015
00016 static long
00017 dbminit_internal(args,result,funct)
00018 ptr_psi_term args[],result,funct;
00019 {
00020 if (dbminit((char*)args[0]->value)<0) return FALSE;
00021 else {
00022 unify_bool_result(result,TRUE);
00023 return TRUE;
00024 }
00025 }
00026
00027 static long
00028 c_dbminit()
00029 {
00030 psi_arg args[1];
00031 SETARG(args,0,"1",quoted_string,REQUIRED);
00032 return call_primitive(dbminit_internal,NARGS(args),args,0);
00033 }
00034
00035 static long
00036 dbmfetch_internal(args,result,funct)
00037 ptr_psi_term args[],result,funct;
00038 {
00039 datum d;
00040 d.dptr = (char*)args[0]->value;
00041 d.dsize = strlen(d.dptr);
00042 d = fetch(d);
00043 if (d.dptr == NULL) return FALSE;
00044 else {
00045 ptr_psi_term bytes = stack_bytes(d.dptr,d.dsize);
00046 push_goal(unify,bytes,result,NULL);
00047 return TRUE;
00048 }
00049 }
00050
00051 static long
00052 c_dbmfetch()
00053 {
00054 psi_arg args[1];
00055 SETARG(args,0,"1",quoted_string,REQUIRED);
00056 return call_primitive(dbmfetch_internal,NARGS(args),args,0);
00057 }
00058
00059 static long
00060 dbmstore_internal(args,result,funct)
00061 ptr_psi_term args[],result,funct;
00062 {
00063 datum key,content;
00064 key.dptr = (char*)args[0]->value;
00065 key.dsize = strlen(key.dptr);
00066 content.dptr = (char*)args[1]->value;
00067 content.dsize = strlen(content.dptr);
00068 if (store(key,content)<0) return FALSE;
00069 else return TRUE;
00070 }
00071
00072 static long
00073 c_dbmstore()
00074 {
00075 psi_arg args[2];
00076 SETARG(args,0,"1",quoted_string,REQUIRED);
00077 SETARG(args,1,"2",quoted_string,REQUIRED);
00078 return call_primitive(dbmstore_internal,NARGS(args),args,0);
00079 }
00080
00081 static long
00082 dbmdelete_internal(args,result,funct)
00083 ptr_psi_term args[],result,funct;
00084 {
00085 datum key;
00086 key.dptr = (char*)args[0]->value;
00087 key.dsize = strlen(key.dptr);
00088 if (delete(key)<0) return FALSE;
00089 else return TRUE;
00090 }
00091
00092 static long
00093 c_dbmdelete()
00094 {
00095 psi_arg args[1];
00096 SETARG(args,0,"1",quoted_string,REQUIRED);
00097 return call_primitive(dbmdelete_internal,NARGS(args),args,0);
00098 }
00099
00100 static long
00101 dbmfirstkey_internal(args,result,funct)
00102 ptr_psi_term args[],result,funct;
00103 {
00104 datum key;
00105 key=firstkey();
00106 if (key.dptr==NULL) return FALSE;
00107 else {
00108 ptr_psi_term bytes = stack_bytes(key.dptr,key.dsize);
00109 push_goal(unify,result,bytes,NULL);
00110 return TRUE;
00111 }
00112 }
00113
00114 static long
00115 c_dbmfirstkey()
00116 {
00117 return call_primitive(dbmfirstkey_internal,0,NULL,0);
00118 }
00119
00120 static long
00121 dbmnextkey_internal(args,result,funct)
00122 ptr_psi_term args[],result,funct;
00123 {
00124 datum key;
00125 key.dptr = (char*)args[0]->value;
00126 key.dsize = strlen(key.dptr);
00127 key = nextkey(key);
00128 if (key.dptr==NULL) return FALSE;
00129 else {
00130 ptr_psi_term bytes = stack_bytes(key.dptr,key.dsize);
00131 push_goal(unify,result,bytes,NULL);
00132 return TRUE;
00133 }
00134 }
00135
00136 static long
00137 c_dbmnextkey()
00138 {
00139 psi_arg args[1];
00140 SETARG(args,0,"1",quoted_string,REQUIRED);
00141 return call_primitive(dbmnextkey_internal,NARGS(args),args,0);
00142 }
00143
00144 void
00145 insert_dbm_builtins()
00146 {
00147 new_built_in(sys_module,"dbm_init",function,c_dbminit);
00148 new_built_in(sys_module,"dbm_fetch",function,c_dbmfetch);
00149 new_built_in(sys_module,"dbm_store",predicate,c_dbmstore);
00150 new_built_in(sys_module,"dbm_delete",predicate,c_dbmdelete);
00151 new_built_in(sys_module,"dbm_firstkey",function,c_dbmfirstkey);
00152 new_built_in(sys_module,"dbm_nextkey",function,c_dbmnextkey);
00153 }
00154 #endif