slgdbm-1.7.1/0000755000076400017500000000000010673300452011460 5ustar paulpaulslgdbm-1.7.1/Makefile0000644000076400017500000000533110673241654013132 0ustar paulpaul#--------------------------------------------------------------------------- # Installation Directories #--------------------------------------------------------------------------- prefix = /usr/local exec_prefix = ${prefix} MODULE_INSTALL_DIR = ${exec_prefix}/lib/slang/v2/modules SL_FILES_INSTALL_DIR = ${prefix}/share/slsh/local-packages HLP_FILES_INSTALL_DIR = $(SL_FILES_INSTALL_DIR)/help #--------------------------------------------------------------------------- # DESTDIR is designed to facilitate making packages. Normally it is empty #--------------------------------------------------------------------------- DESTDIR = DEST_MODULE_INSTALL_DIR = $(DESTDIR)$(MODULE_INSTALL_DIR) DEST_SL_FILES_INSTALL_DIR = $(DESTDIR)$(SL_FILES_INSTALL_DIR) DEST_HLP_FILES_INSTALL_DIR = $(DESTDIR)$(HLP_FILES_INSTALL_DIR) #--------------------------------------------------------------------------- # Location of the S-Lang library and its include file #--------------------------------------------------------------------------- SLANG_INC = -I/usr/local/include SLANG_LIB = -L/usr/local/lib -lslang #--------------------------------------------------------------------------- # C Compiler to create a shared library #--------------------------------------------------------------------------- CC_SHARED = $(CC) $(CFLAGS) -shared -Wall -fPIC #--------------------------------------------------------------------------- # Misc Programs required for installation #--------------------------------------------------------------------------- INSTALL = /usr/bin/install -m 644 MKINSDIR = /usr/bin/install -d #--------------------------------------------------------------------------- # You shouldn't need to edit anything below this line #--------------------------------------------------------------------------- LIBS = $(SLANG_LIB) -lm -lgdbm INCS = $(SLANG_INC) all: gdbm-module.so gdbm-module.so: gdbm-module.c $(CC_SHARED) $(INCS) gdbm-module.c -o gdbm-module.so $(LIBS) gdbm.o: gdbm-module.c gcc $(CFLAGS) $(INCS) -O2 -c -g gdbm-module.c -o gdbm.o gdbm.hlp: gdbm-module.c sl2tm gdbm-module.c | tm2txt > gdbm.hlp clean: rm -f gdbm-module.so *.o #--------------------------------------------------------------------------- # Installation Rules #--------------------------------------------------------------------------- install_directories: $(MKINSDIR) $(DEST_MODULE_INSTALL_DIR) $(MKINSDIR) $(DEST_SL_FILES_INSTALL_DIR) $(MKINSDIR) $(DEST_HLP_FILES_INSTALL_DIR) install_modules: $(INSTALL) gdbm-module.so $(DEST_MODULE_INSTALL_DIR) install_slfiles: $(INSTALL) gdbm.sl $(DEST_SL_FILES_INSTALL_DIR) install_hlpfiles: $(INSTALL) gdbm.hlp $(DEST_HLP_FILES_INSTALL_DIR) install: all install_directories install_modules install_slfiles install_hlpfiles slgdbm-1.7.1/gdbm.hlp0000644000076400017500000001214010673300034013070 0ustar paulpaulgdbm_open SYNOPSIS open a gdbm database USAGE GDBM_Type gdbm_open(String_Type file, Int_Type flags, Int_Type mode) DESCRIPTION The `gdbm_open' function opens a GDBM file and returns a GDBM_Type object. On failure it returns NULL and sets `gdbm_errno'. The flags are GDBM_READER for opening read-only, GDBM_WRITER for a reader/writer, and GDBM_WRCREAT for creating the file if it does not exist. There are other flags as well, see the info documentation for gdbm. The mode specifies the file permissions of a newly created file. NOTES Only one application at a time can open a dbf for writing. A dbf can be opened by many readers, but not if it is opened for writing. SEE ALSO gdbm_close, gdbm_store, gdbm_fetch, gdbm_exists, gdbm_delete -------------------------------------------------------------- gdbm_close SYNOPSIS close a gdbm database USAGE gdbm_close(GDBM_Type dbf) DESCRIPTION closes a gdbm database. NOTES The database is also automatically closed when the `dbf' variable goes out of scope. -------------------------------------------------------------- gdbm_store SYNOPSIS stores a key/value pair in a GDBM dbf USAGE Int_Type gdbm_store(GDBM_Type dbf, String_Type key, String_Type val, Int_Type flags) DESCRIPTION Inserts or replaces records in the database. If the flag is GDBM_INSERT, and the key is already in the database, it fails. If the flag is GDBM_REPLACE, the old value is replaced. On success it returns 0. NOTES You can also write `dbf[key] = value;' This implies GDBM_REPLACE. SEE ALSO gdbm_delete, gdbm_fetch, gdbm_exists -------------------------------------------------------------- gdbm_fetch SYNOPSIS fetch a value from a gdbm database USAGE String_Type gdbm_fetch(GDBM_Type dbf, String_Type key) DESCRIPTION Gets the value of the entry with key `key' from the GDBM file `dbf'. If the key does not exist it returns NULL. NOTES You can also fetch the value with the expression `dbf[key]' SEE ALSO gdbm_exists -------------------------------------------------------------- gdbm_exists SYNOPSIS test if a value is present in a database USAGE Integer_Type gdbm_exists(GDBM_Type dbf, String_Type key) DESCRIPTION If the `key' exists in the database `dbf', it returns 1. Otherwise 0. -------------------------------------------------------------- gdbm_delete SYNOPSIS delete a record from a GDBM database USAGE Integer_Type gdbm_delete(GDBM_Type dbf, String_Type key) DESCRIPTION `gdbm_delete' removes the keyed item and the `key' from the database `dbf'. The ret value is -1 if the item is not present or the requester is a reader. The ret value is 0 if there was a successful delete. -------------------------------------------------------------- gdbm_get_keys SYNOPSIS get all keys in a GDBM dbf USAGE String_Type[] gdbm_get_keys(GDBM_Type dbf) DESCRIPTION This function returns all the key names of `dbf' as an ordinary one dimensional array of strings. If the `dbf' contains no records, an empty array will be returned. NOTES It is also possible to iterate over a dbf's records with `foreach (dbf) using (keys)' etc. SEE ALSO gdbm_get_values, gdbm_get_keys_and_values -------------------------------------------------------------- gdbm_get_values SYNOPSIS get values from a gdbm USAGE String_Type[] gdbm_get_values(GDBM_Type) DESCRIPTION This function returns all the values in `dbf' as an ordinary one dimensional array of strings. If the `dbf' contains no records, an empty array will be returned. SEE ALSO gdbm_get_keys, gdbm_get_keys_and_values -------------------------------------------------------------- gdbm_get_keys_and_values SYNOPSIS get keys and values from a gdbm USAGE (String_Typep[], String_Type[]) gdbm_get_keys_and_values(GDBM_Type) DESCRIPTION This function returns all the keys and values of `dbf' as two arrays of strings. If the `dbf' contains no records, two empty arrays will be returned. SEE ALSO gdbm_get_keys, gdbm_get_values -------------------------------------------------------------- gdbm_error SYNOPSIS get the gdbm error string USAGE String_Type gdbm_error([Integer_Type code]) DESCRIPTION converts the gdbm error code `code' into English text. Without arguments it returns the error string of `gdbm_errno'. SEE ALSO gdbm_errno -------------------------------------------------------------- gdbm_reorganize SYNOPSIS reorganize a gdbm USAGE Int_Type gdbm_reorganize(GDBM_Type) DESCRIPTION If you have had a lot of deletions and would like to shrink the space used by the `gdbm' file, this function will reorganize the database. If an error is detected, the return value is negative. The value zero is returned after a successful reorganization. -------------------------------------------------------------- gdbm_errno SYNOPSIS gdbm's error code DESCRIPTION When a gdbm functions fails it sets this variable to a non-zero value. SEE ALSO gdbm_error -------------------------------------------------------------- slgdbm-1.7.1/slgdbm.txt0000644000076400017500000000522710673300435013500 0ustar paulpaulThis S-Lang module provides access to gdbm databases. features * when the GDBM_Type handle goes out of scope, the database is automatically closed * it's also possible to explicitly close a database * gdbm_get_keys() returns all keys in the database as an array * gdbm_get_values() returns an array of all values * gdbm_get_keys_and values() returns both arrays. This is more efficient than first calling gdbm_get_keys() and then gdbm_get_values(). Also, in dbm's that allow concurrent write access, another process might delete or insert records inbetween gdbm_get_keys() and gdbm_get_values(). * assoc-like syntax To implement this I started by stealing from the pcre module, then I went on to steal from slstdio.c, then from slassoc.c. limitations * only strings are allowed as keys and values. * keys and values are stored as strings, not including the trailing \0. This is compatible with python and perl, but not with slgdbm 1.2, and maybe other programs (probably the db files in the Netscape cache directory, but since these are in Berkeley DB format I can't access those anyway). In fact when I try to read from a slgdbm 1.2 file, I get an "invalid attempt to free string." Maybe I should use bstrings. That would also allow me to use pack() to store other datatypes. assoc syntax You can access a dbf with an assoc-like syntax. This is similar to the anydbm interface of python and perl's tie() interface. You can write val = key[dbf]; as an alternative to val = gdbm_fetch(dbf, key); as well as dbf[key]=val; as shorthand for () = gdbm_store(dbf, key, val, GDBM_REPLACE); In this last case, gdbm_store() returns a value but dbf[key]=val; does not. I don't know if a syntax like ret = (dbf[key]=val); is possible, but such a syntax would be confusing to C programmers anyway. Also, the chosen syntax has the advantage that it is possible to some extent to write code that works on an object without knowing if the object is an assoc or a dbf. foreach You can also iterate over the database entries using the syntax foreach (dbf) using ("keys", "values") However, this uses gdbm's sequential access method. If you do this foreach(dbf) using ("keys") { key = (); if ( some condition ) gdbm_delete ( dbf, key ); } the hash will be rearranged and some entries may be skipped by the loop. See also info:(gdbm)Sequential. Changing values of entries in a foreach loop is OK, I think. applications A recent files mode for JED using slgdbm is available from the Jed Modes Repository. copyright Slgdbm is Copyright (c) 2004, 2005, 2007 Paul Boekholt. Released under the terms of the GNU GPL (version 2 or later). slgdbm-1.7.1/gdbm.sl0000644000076400017500000000025010315531502012721 0ustar paulpaulimport ("gdbm"); $1 = path_concat (path_concat (path_dirname (__FILE__), "help"), "gdbm.hlp"); if (NULL != stat_file ($1)) add_doc_file ($1); provide ("gdbm"); slgdbm-1.7.1/gdbm-module.c0000644000076400017500000006165410673300014014026 0ustar paulpaul/* gdbm-module.c * SLang bindings for gdbm * * $Id: gdbm-module.c,v 1.8 2007/09/16 19:11:31 paul Exp paul $ * * Copyright (c) 2004, 2005, 2007 Paul Boekholt. * Released under the terms of the GNU GPL (version 2 or later). */ #include #include #include #include SLANG_MODULE(gdbm); #define MODULE_MAJOR_VERSION 1 #define MODULE_MINOR_VERSION 7 #define MODULE_PATCH_LEVEL 1 static char *Module_Version_String = "1.7.1"; #define MODULE_VERSION_NUMBER \ (MODULE_MAJOR_VERSION*10000+MODULE_MINOR_VERSION*100+MODULE_PATCH_LEVEL) static int GDBM_Type_Id = 0; /*{{{ GDBM_Type */ typedef struct { GDBM_FILE p; int inuse; } GDBM_Type; static void free_gdbm_type (GDBM_Type *pt) { if (pt->inuse) gdbm_close(pt->p); SLfree ((char *) pt); } /*}}}*/ /*{{{ open */ static SLang_MMT_Type *allocate_gdbm_type (GDBM_FILE p, int flags) { GDBM_Type *pt; SLang_MMT_Type *mmt; pt = (GDBM_Type *) SLmalloc (sizeof (GDBM_Type)); if (pt == NULL) return NULL; memset ((char *) pt, 0, sizeof (GDBM_Type)); pt->p = p; pt->inuse=1; if (NULL == (mmt = SLang_create_mmt (GDBM_Type_Id, (VOID_STAR) pt))) { free_gdbm_type (pt); return NULL; } return mmt; } static int slgdbm_open(char *name, int *flags, int *mode) { SLang_MMT_Type *mmt; GDBM_FILE dbf; dbf = gdbm_open(name, 0, *flags, *mode, NULL); if (dbf==NULL) { (void) SLang_push_null(); return -1; } if (NULL == (mmt = allocate_gdbm_type (dbf, *flags))) { (void) SLang_push_null(); gdbm_close(dbf); return -1; } if (-1 == SLang_push_mmt (mmt)) { SLang_free_mmt (mmt); (void) SLang_push_null(); return -1; } return 0; } /*}}}*/ /*{{{ close */ static void slgdbm_close() { GDBM_Type *pt; SLang_MMT_Type *mmt; if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) return; pt = SLang_object_from_mmt (mmt); if (pt->inuse) { gdbm_close(pt->p); pt->inuse = 0; } SLang_free_mmt (mmt); } /*}}}*/ /*{{{ store */ static int slgdbm_store(char *key, char *value, int *flags) { GDBM_Type *p; SLang_MMT_Type *mmt; int ret; datum k,v; k.dptr=key; k.dsize=strlen(key); v.dptr=value; v.dsize=strlen(value); if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) { SLang_free_mmt (mmt); return -2; } p = SLang_object_from_mmt (mmt); if (p->inuse) ret = gdbm_store(p->p, k, v, *flags); SLang_free_mmt (mmt); return ret; } /*}}}*/ /*{{{ fetch */ static void slgdbm_fetch(char *key) { GDBM_Type *p; SLang_MMT_Type *mmt; datum k,v; char *str; k.dptr=key; k.dsize=strlen(key); if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) { SLang_free_mmt (mmt); (void) SLang_push_null(); return; } p = SLang_object_from_mmt (mmt); if (p->inuse) { v = gdbm_fetch(p->p, k); if (v.dptr == NULL || (NULL == (str = SLang_create_nslstring((char *)v.dptr, (unsigned int)v.dsize)))) (void)SLang_push_null(); else { (void) SLang_push_string(str); SLang_free_slstring(str); } SLfree(v.dptr); } else (void)SLang_push_null(); SLang_free_mmt (mmt); } /*}}}*/ /*{{{ key exists */ static int slgdbm_exists(char *key) { GDBM_Type *p; SLang_MMT_Type *mmt; datum k; int ret=-1; k.dptr=key; k.dsize=strlen(key); if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) { SLang_free_mmt (mmt); return 0; } p = SLang_object_from_mmt (mmt); if (p->inuse) ret = gdbm_exists(p->p, k); SLang_free_mmt (mmt); return ret; } /*}}}*/ /*{{{ delete key */ static int slgdbm_delete(char *key) { GDBM_Type *p; SLang_MMT_Type *mmt; datum k; int ret=-1; k.dptr=key; k.dsize=strlen(key); if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) { SLang_free_mmt (mmt); return 0; } p = SLang_object_from_mmt (mmt); if (p->inuse) ret = gdbm_delete(p->p, k); SLang_free_mmt (mmt); return ret; } /*}}}*/ /*{{{ get keys */ /* this was adapted from stdio_fgetslines_internal */ static void gdbm_get_keys_internal (GDBM_Type *pt) { unsigned int num_lines, max_num_lines; char **list; SLang_Array_Type *at; SLindex_Type inum_lines; datum key, nextkey; max_num_lines = 1024; list = (char **) SLmalloc (sizeof (char *) * max_num_lines); if (list == NULL) return; num_lines = 0; key = gdbm_firstkey (pt->p); while (key.dptr) { char *strp; if (max_num_lines == num_lines) { char **new_list; max_num_lines += 4096; new_list = (char **) SLrealloc ((char *)list, sizeof (char *) * max_num_lines); if (new_list == NULL) { SLfree (key.dptr); goto return_error; } list = new_list; } strp = SLang_create_nslstring ((char *)key.dptr, (unsigned int) key.dsize); list[num_lines] = strp; num_lines++; nextkey = gdbm_nextkey (pt->p, key); SLfree(key.dptr); key = nextkey; } if (num_lines != max_num_lines) { char **new_list; new_list = (char **)SLrealloc ((char *)list, sizeof (char *) * (num_lines + 1)); if (new_list == NULL) goto return_error; list = new_list; } inum_lines = (SLindex_Type) num_lines; if (NULL == (at = SLang_create_array (SLANG_STRING_TYPE, 0, (VOID_STAR) list, &inum_lines, 1))) goto return_error; if (-1 == SLang_push_array (at, 1)) SLang_push_null (); return; return_error: while (num_lines > 0) { num_lines--; SLang_free_slstring (list[num_lines]); } SLfree ((char *)list); SLang_push_null (); } static void slgdbm_get_keys() { GDBM_Type *pt; SLang_MMT_Type *mmt; if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) return; pt = SLang_object_from_mmt (mmt); if (pt->inuse) { gdbm_get_keys_internal(pt); } else SLang_push_null (); SLang_free_mmt (mmt); } /*}}}*/ /*{{{ get values */ static void gdbm_get_values_internal (GDBM_Type *pt) { unsigned int num_lines, max_num_lines; char **list; SLang_Array_Type *at; SLindex_Type inum_lines; datum key, nextkey, value; max_num_lines = 1024; list = (char **) SLmalloc (sizeof (char *) * max_num_lines); if (list == NULL) return; num_lines = 0; key = gdbm_firstkey (pt->p); while (key.dptr) { char *strp; value = gdbm_fetch(pt->p, key); if (value.dptr == NULL) { nextkey = gdbm_nextkey (pt->p, key); SLfree(key.dptr); key = nextkey; continue; } if (max_num_lines == num_lines) { char **new_list; max_num_lines += 4096; new_list = (char **) SLrealloc ((char *)list, sizeof (char *) * max_num_lines); if (new_list == NULL) { SLfree (key.dptr); SLfree (value.dptr); goto return_error; } list = new_list; } strp = SLang_create_nslstring ((char *)value.dptr, (unsigned int) value.dsize); list[num_lines] = strp; num_lines++; nextkey = gdbm_nextkey (pt->p, key); SLfree(key.dptr); SLfree(value.dptr); key = nextkey; } if (num_lines != max_num_lines) { char **new_list; new_list = (char **)SLrealloc ((char *)list, sizeof (char *) * (num_lines + 1)); if (new_list == NULL) goto return_error; list = new_list; } inum_lines = (SLindex_Type) num_lines; if (NULL == (at = SLang_create_array (SLANG_STRING_TYPE, 0, (VOID_STAR) list, &inum_lines, 1))) goto return_error; if (-1 == SLang_push_array (at, 1)) SLang_push_null (); return; return_error: while (num_lines > 0) { num_lines--; SLang_free_slstring (list[num_lines]); } SLfree ((char *)list); SLang_push_null (); } static void slgdbm_get_values() { GDBM_Type *pt; SLang_MMT_Type *mmt; if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) return; pt = SLang_object_from_mmt (mmt); if (pt->inuse) { gdbm_get_values_internal(pt); } else SLang_push_null (); SLang_free_mmt (mmt); } /*}}}*/ /*{{{ get keys and values */ static void gdbm_get_keys_values_internal (GDBM_Type *pt) { unsigned int num_lines, max_num_lines; char **list, **list2; SLang_Array_Type *at, *at2; SLindex_Type inum_lines; datum key, nextkey, value; max_num_lines = 1024; list = (char **) SLmalloc (sizeof (char *) * max_num_lines); if (list == NULL) return; list2 = (char **) SLmalloc (sizeof (char *) * max_num_lines); if (list2 == NULL) { SLfree ((char *)list); return; } num_lines = 0; key = gdbm_firstkey (pt->p); while (key.dptr) { char *strp, *strp2; value = gdbm_fetch(pt->p, key); if (value.dptr == NULL) { nextkey = gdbm_nextkey (pt->p, key); SLfree(key.dptr); key = nextkey; continue; } if (max_num_lines == num_lines) { char **new_list, **new_list2; max_num_lines += 4096; new_list = (char **) SLrealloc ((char *)list, sizeof (char *) * max_num_lines); if (new_list == NULL) { SLfree (key.dptr); SLfree (value.dptr); goto return_error; } list = new_list; new_list2 = (char **) SLrealloc ((char *)list2, sizeof (char *) * max_num_lines); if (new_list2 == NULL) { SLfree (key.dptr); SLfree (value.dptr); goto return_error; } list2 = new_list2; } strp = SLang_create_nslstring ((char *)key.dptr, (unsigned int) key.dsize); strp2 = SLang_create_nslstring ((char *)value.dptr, (unsigned int) value.dsize); list[num_lines] = strp; list2[num_lines] = strp2; num_lines++; nextkey = gdbm_nextkey (pt->p, key); SLfree(key.dptr); SLfree(value.dptr); key = nextkey; } if (num_lines != max_num_lines) { char **new_list, **new_list2; new_list = (char **)SLrealloc ((char *)list, sizeof (char *) * (num_lines + 1)); if (new_list == NULL) goto return_error; list = new_list; new_list2 = (char **)SLrealloc ((char *)list2, sizeof (char *) * (num_lines + 1)); if (new_list2 == NULL) goto return_error; list2 = new_list2; } inum_lines = (SLindex_Type) num_lines; if (NULL == (at = SLang_create_array (SLANG_STRING_TYPE, 0, (VOID_STAR) list, &inum_lines, 1))) goto return_error; if (NULL == (at2 = SLang_create_array (SLANG_STRING_TYPE, 0, (VOID_STAR) list2, &inum_lines, 1))) { SLang_free_array(at); while (num_lines > 0) { num_lines--; SLang_free_slstring (list2[num_lines]); } SLfree ((char *)list2); SLang_push_null (); return; } if (-1 == SLang_push_array (at, 1)) SLang_push_null (); if (-1 == SLang_push_array (at2, 1)) SLang_push_null (); return; return_error: while (num_lines > 0) { num_lines--; SLang_free_slstring (list[num_lines]); SLang_free_slstring (list2[num_lines]); } SLfree ((char *)list); SLfree ((char *)list2); SLang_push_null (); SLang_push_null (); } static void slgdbm_get_keys_and_values() { GDBM_Type *pt; SLang_MMT_Type *mmt; if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) return; pt = SLang_object_from_mmt (mmt); if (pt->inuse) { gdbm_get_keys_values_internal(pt); } else { SLang_push_null (); SLang_push_null (); } SLang_free_mmt (mmt); } /*}}}*/ /*{{{ aget/aput */ /* this is from slassoc.c */ static int pop_index (unsigned int num_indices, SLang_MMT_Type **mmt, GDBM_Type **a, char **str) { if (NULL == (*mmt = SLang_pop_mmt (GDBM_Type_Id))) { *a = NULL; *str = NULL; return -1; } if ((num_indices != 1) || (-1 == SLang_pop_slstring (str))) { SLang_verror (SL_NOT_IMPLEMENTED, "GDBM_Types require a single string index"); SLang_free_mmt (*mmt); *mmt = NULL; *a = NULL; *str = NULL; return -1; } *a = (GDBM_Type *) SLang_object_from_mmt (*mmt); return 0; } int _SLgdbm_aget (SLtype type, unsigned int num_indices) { SLang_MMT_Type *mmt; char *key, *val; GDBM_Type *pt; int ret; datum k,v; (void) type; if (-1 == pop_index (num_indices, &mmt, &pt, &key)) return -1; /* get the value */ k.dptr=key; k.dsize=strlen(key); if (pt->inuse) { v = gdbm_fetch(pt->p, k); if (v.dptr == NULL || (NULL == (val = SLang_create_nslstring((char *)v.dptr, (unsigned int)v.dsize)))) (void)SLang_push_null(); else { (void) SLang_push_string(val); SLang_free_slstring(val); } SLfree(v.dptr); } else (void)SLang_push_null(); SLang_free_slstring (key); SLang_free_mmt (mmt); return ret; } int _SLgdbm_aput (SLtype type, unsigned int num_indices) { SLang_MMT_Type *mmt; char *key, *val; GDBM_Type *pt; int ret; datum k,v; (void) type; if (-1 == pop_index (num_indices, &mmt, &pt, &key)) return -1; if (-1 == SLpop_string (&val)) { SLang_free_slstring (key); return -1; } ret = -1; /* put the value */ k.dptr=key; k.dsize=strlen(key); v.dptr=val; v.dsize=strlen(val); if (pt->inuse) { ret = gdbm_store(pt->p, k, v, GDBM_REPLACE); if (ret) #if SLANG_VERSION < 20000 SLang_verror(SL_INTRINSIC_ERROR, "Could not write to GDBM"); #else SLang_verror(SL_RunTime_Error, "Could not write to GDBM"); #endif } SLang_free_slstring (key); SLfree (val); SLang_free_mmt (mmt); return ret; } /*}}}*/ /*{{{ foreach */ #if SLANG_VERSION < 20000 struct _SLang_Foreach_Context_Type #else struct _pSLang_Foreach_Context_Type #endif { SLang_MMT_Type *mmt; GDBM_Type *a; datum key; #define CTX_WRITE_KEYS 1 #define CTX_WRITE_VALUES 2 unsigned char flags; }; static SLang_Foreach_Context_Type * cl_foreach_open (SLtype type, unsigned int num) { SLang_Foreach_Context_Type *c; unsigned char flags; SLang_MMT_Type *mmt; (void) type; if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) return NULL; flags = 0; while (num--) { char *s; if (-1 == SLang_pop_slstring (&s)) { SLang_free_mmt (mmt); return NULL; } if (0 == strcmp (s, "keys")) flags |= CTX_WRITE_KEYS; else if (0 == strcmp (s, "values")) flags |= CTX_WRITE_VALUES; else { SLang_verror (SL_NOT_IMPLEMENTED, "using '%s' not supported by GDBM_Type", s); SLang_free_slstring (s); SLang_free_mmt (mmt); return NULL; } SLang_free_slstring (s); } if (NULL == (c = (SLang_Foreach_Context_Type *) SLmalloc (sizeof (SLang_Foreach_Context_Type)))) { SLang_free_mmt (mmt); return NULL; } memset ((char *) c, 0, sizeof (SLang_Foreach_Context_Type)); if (flags == 0) flags = CTX_WRITE_VALUES|CTX_WRITE_KEYS; c->flags = flags; c->mmt = mmt; c->a = (GDBM_Type *) SLang_object_from_mmt (mmt); c->key = gdbm_firstkey(c->a->p); return c; } static void cl_foreach_close (SLtype type, SLang_Foreach_Context_Type *c) { (void) type; if (c == NULL) return; SLang_free_mmt (c->mmt); SLfree ((char *) c); } static int cl_foreach (SLtype type, SLang_Foreach_Context_Type *c) { GDBM_Type *a; datum key, value; (void) type; if (c == NULL) return -1; key = c->key; if(key.dptr == NULL) return -1; a = c->a; if ((c->flags & CTX_WRITE_KEYS)) { char *strp; if (NULL == (strp = SLang_create_nslstring ((char *)key.dptr, (unsigned int) key.dsize))) (void)SLang_push_null(); else { (void) SLang_push_string (strp); SLang_free_slstring(strp); } } if (c->flags & CTX_WRITE_VALUES) { char *strp2; value = gdbm_fetch(a->p, key); if (value.dptr == NULL) { SLfree(key.dptr); return -1; } if (NULL == (strp2 = SLang_create_nslstring((char *)value.dptr, (unsigned int)value.dsize))) (void)SLang_push_null(); else { (void) SLang_push_string(strp2); SLang_free_slstring(strp2); } SLfree(value.dptr); } c->key = gdbm_nextkey (a->p, key); SLfree(key.dptr); /* keep going */ return 1; } /*}}}*/ /*{{{ gdbm error */ static void slgdbm_error() { int error; if (SLang_Num_Function_Args ==1) { if (-1 == SLang_pop_integer(&error)) { SLang_verror (SL_INTRINSIC_ERROR, "Unable to validate arguments to: gdbm_error"); return; } } else error = gdbm_errno; (void) SLang_push_string((char *)gdbm_strerror(error)); } /*}}}*/ /*{{{ destructor */ static void destroy_gdbm (SLtype type, VOID_STAR f) { GDBM_Type *pt; (void) type; pt = (GDBM_Type *) f; free_gdbm_type (pt); } /*}}}*/ /*{{{ reorganize */ static int slgdbm_reorganize() { GDBM_Type *p; SLang_MMT_Type *mmt; int ret=-1; if (NULL == (mmt = SLang_pop_mmt (GDBM_Type_Id))) { SLang_free_mmt (mmt); return -1; } p = SLang_object_from_mmt (mmt); if (p->inuse) ret = gdbm_reorganize(p->p); SLang_free_mmt (mmt); return ret; } /*}}}*/ /*{{{ intrinsics */ #define DUMMY_GDBM_TYPE 255 #define P DUMMY_GDBM_TYPE #define I SLANG_INT_TYPE #define V SLANG_VOID_TYPE #define S SLANG_STRING_TYPE static SLang_Intrin_Fun_Type Module_Intrinsics [] = { MAKE_INTRINSIC_SII("gdbm_open", slgdbm_open, V), /*%+ *\function{gdbm_open} *\synopsis{open a gdbm database} *\usage{GDBM_Type gdbm_open(String_Type file, Int_Type flags, Int_Type mode)} *\description * The \var{gdbm_open} function opens a GDBM file and returns a GDBM_Type * object. On failure it returns NULL and sets \var{gdbm_errno}. * The flags are GDBM_READER for opening read-only, GDBM_WRITER for a * reader/writer, and GDBM_WRCREAT for creating the file if it does not * exist. There are other flags as well, see the info documentation for * gdbm. The mode specifies the file permissions of a newly created file. *\notes * Only one application at a time can open a dbf for writing. A dbf can * be opened by many readers, but not if it is opened for writing. *\seealso{gdbm_close, gdbm_store, gdbm_fetch, gdbm_exists, gdbm_delete} *%- */ MAKE_INTRINSIC_0("gdbm_close", slgdbm_close, V), /*%+ *\function{gdbm_close} *\synopsis{close a gdbm database} *\usage{gdbm_close(GDBM_Type dbf)} *\description * closes a gdbm database. *\notes * The database is also automatically closed when the \var{dbf} variable * goes out of scope. *%- */ MAKE_INTRINSIC_SSI("gdbm_store", slgdbm_store, I), /*%+ *\function{gdbm_store} *\synopsis{stores a key/value pair in a GDBM dbf} *\usage{Int_Type gdbm_store(GDBM_Type dbf, String_Type key, String_Type val, Int_Type flags)} *\description * Inserts or replaces records in the database. If the flag is GDBM_INSERT, * and the key is already in the database, it fails. If the flag is * GDBM_REPLACE, the old value is replaced. On success it returns 0. *\notes * You can also write \exmp{dbf[key] = value;} * This implies GDBM_REPLACE. *\seealso{gdbm_delete, gdbm_fetch, gdbm_exists} *%- */ MAKE_INTRINSIC_S("gdbm_fetch", slgdbm_fetch, V), /*%+ *\function{gdbm_fetch} *\synopsis{fetch a value from a gdbm database} *\usage{String_Type gdbm_fetch(GDBM_Type dbf, String_Type key)} *\description * Gets the value of the entry with key \var{key} from the GDBM file \var{dbf}. * If the key does not exist it returns NULL. *\notes * You can also fetch the value with the expression \exmp{dbf[key]} *\seealso{gdbm_exists} *%- */ MAKE_INTRINSIC_S("gdbm_exists", slgdbm_exists, I), /*%+ *\function{gdbm_exists} *\synopsis{test if a value is present in a database} *\usage{Integer_Type gdbm_exists(GDBM_Type dbf, String_Type key)} *\description * If the \var{key} exists in the database \var{dbf}, it returns 1. * Otherwise 0. *%- */ MAKE_INTRINSIC_S("gdbm_delete", slgdbm_delete, I), /*%+ *\function{gdbm_delete} *\synopsis{delete a record from a GDBM database} *\usage{Integer_Type gdbm_delete(GDBM_Type dbf, String_Type key)} *\description * \var{gdbm_delete} removes the keyed item and the \var{key} from the database * \var{dbf}. * The ret value is -1 if the item is not present or the requester is a * reader. The ret value is 0 if there was a successful delete. *%- */ MAKE_INTRINSIC_0("gdbm_get_keys", slgdbm_get_keys, V), /*%+ *\function{gdbm_get_keys} *\synopsis{get all keys in a GDBM dbf} *\usage{String_Type[] gdbm_get_keys(GDBM_Type dbf)} *\description * This function returns all the key names of \var{dbf} as an ordinary * one dimensional array of strings. If the \var{dbf} contains no records, * an empty array will be returned. *\notes * It is also possible to iterate over a dbf's records with * \exmp{foreach (dbf) using (keys)} etc. *\seealso{gdbm_get_values, gdbm_get_keys_and_values} *%- */ MAKE_INTRINSIC_0("gdbm_get_values", slgdbm_get_values, V), /*%+ *\function{gdbm_get_values} *\synopsis{get values from a gdbm} *\usage{String_Type[] gdbm_get_values(GDBM_Type)} *\description * This function returns all the values in \var{dbf} as an ordinary * one dimensional array of strings. If the \var{dbf} contains no records, * an empty array will be returned. *\seealso{gdbm_get_keys, gdbm_get_keys_and_values} *%- */ MAKE_INTRINSIC_0("gdbm_get_keys_and_values", slgdbm_get_keys_and_values, V), /*%+ *\function{gdbm_get_keys_and_values} *\synopsis{get keys and values from a gdbm} *\usage{(String_Typep[], String_Type[]) gdbm_get_keys_and_values(GDBM_Type)} *\description * This function returns all the keys and values of \var{dbf} as two * arrays of strings. If the \var{dbf} contains no records, two empty arrays * will be returned. *\seealso{gdbm_get_keys, gdbm_get_values} *%- */ MAKE_INTRINSIC_0("gdbm_error", slgdbm_error, V), /*%+ *\function{gdbm_error} *\synopsis{get the gdbm error string} *\usage{String_Type gdbm_error([Integer_Type code])} *\description * converts the gdbm error code \var{code} into English text. Without arguments * it returns the error string of \var{gdbm_errno}. *\seealso{gdbm_errno} *%- */ /*%+ *\function{gdbm_reorganize} *\synopsis{reorganize a gdbm} *\usage{Int_Type gdbm_reorganize(GDBM_Type)} *\description * If you have had a lot of deletions and would like to shrink the space * used by the \var{gdbm} file, this function will reorganize the database. * If an error is detected, the return value is negative. The value zero is * returned after a successful reorganization. *%- */ MAKE_INTRINSIC_0("gdbm_reorganize", slgdbm_reorganize, I), SLANG_END_INTRIN_FUN_TABLE }; static SLang_Intrin_Var_Type Module_Variables [] = { MAKE_VARIABLE("_gdbm_module_version_string", &Module_Version_String, SLANG_STRING_TYPE, 1), MAKE_VARIABLE("gdbm_errno", &gdbm_errno, SLANG_INT_TYPE, 1), /*%+ *\variable{gdbm_errno} *\synopsis{gdbm's error code} *\description * When a gdbm functions fails it sets this variable to a non-zero value. *\seealso{gdbm_error} *%- */ SLANG_END_INTRIN_VAR_TABLE }; static SLang_IConstant_Type Module_Constants [] = { MAKE_ICONSTANT("_gdbm_module_version", MODULE_VERSION_NUMBER), MAKE_ICONSTANT("GDBM_READER", GDBM_READER ), MAKE_ICONSTANT("GDBM_WRITER", GDBM_WRITER ), MAKE_ICONSTANT("GDBM_WRCREAT", GDBM_WRCREAT), MAKE_ICONSTANT("GDBM_NEWDB", GDBM_NEWDB), MAKE_ICONSTANT("GDBM_FAST", GDBM_FAST), MAKE_ICONSTANT("GDBM_REPLACE", GDBM_REPLACE), MAKE_ICONSTANT("GDBM_INSERT", GDBM_INSERT), SLANG_END_ICONST_TABLE }; #undef P #undef I #undef V #undef S /*}}}*/ /*{{{ register class */ static void patchup_intrinsic_table (SLang_Intrin_Fun_Type *table, unsigned char dummy, unsigned char type) { while (table->name != NULL) { unsigned int i, nargs; SLtype *args; nargs = table->num_args; args = table->arg_types; for (i = 0; i < nargs; i++) { if (args[i] == dummy) args[i] = type; } /* For completeness */ if (table->return_type == dummy) table->return_type = type; table++; } } static int register_gdbm_type (void) { SLang_Class_Type *cl; if (GDBM_Type_Id != 0) return 0; if (NULL == (cl = SLclass_allocate_class ("GDBM_Type"))) return -1; if ((-1 == SLclass_set_destroy_function (cl, destroy_gdbm)) || (-1 == SLclass_set_aget_function (cl, _SLgdbm_aget)) || (-1 == SLclass_set_aput_function (cl, _SLgdbm_aput))) return -1; #if SLANG_VERSION < 20000 cl->cl_foreach_open = cl_foreach_open; cl->cl_foreach_close = cl_foreach_close; cl->cl_foreach = cl_foreach; #else if (-1 == SLclass_set_foreach_functions(cl, cl_foreach_open, cl_foreach, cl_foreach_close)) return -1; #endif /* By registering as SLANG_VOID_TYPE, slang will dynamically allocate a * type. */ if (-1 == SLclass_register_class (cl, SLANG_VOID_TYPE, sizeof (GDBM_Type), SLANG_CLASS_TYPE_MMT)) return -1; GDBM_Type_Id = SLclass_get_class_id (cl); patchup_intrinsic_table (Module_Intrinsics, DUMMY_GDBM_TYPE, GDBM_Type_Id); return 0; } /*}}}*/ /*{{{ init module */ int init_gdbm_module_ns (char *ns_name) { SLang_NameSpace_Type *ns = SLns_create_namespace (ns_name); if (ns == NULL) return -1; if (-1 == register_gdbm_type ()) return -1; if ((-1 == SLns_add_intrin_fun_table (ns, Module_Intrinsics, "__GDBM__")) || (-1 == SLns_add_intrin_var_table (ns, Module_Variables, NULL)) || (-1 == SLns_add_iconstant_table (ns, Module_Constants, NULL))) return -1; return 0; } /*}}}*/ slgdbm-1.7.1/COPYING0000644000076400017500000004312710460000734012514 0ustar paulpaul GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.