dbm_t.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2007-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#include <shell.h>
#include <ast_ndbm.h>
static const char dbm_usage[] =
"[-?@(#)$Id: Dbm_t (AT&T Research) 2008-05-09 $\n]"
"[+NAME?Dbm_t - create an associative array containing contents of a dbm file]"
"[+DESCRIPTION?\bDbm_t\b is a declaration command that creates an associative "
"array corresponding to the dbm file whose name is the value of the "
"variable \avname\a. The variable \avname\a becomes an associative "
"array with subscripts corresponding to keys in the dbm file.]"
"[+?Unless hte \b-T\b option is specified, the keys in the file cannot contain "
"the NUL character, \b\\0\b, except as the last character. In this "
" case all keys must have \b\\0\b as the last characer. The \b-z\b "
"option adds a trailing NUL to each key.]"
"[+?If no options are specified, \bDbm_t\b defaults to \b-r\b.]"
"[T]:[tname?The type of each element will be \atname\a.]"
"[c:create?Clear the dbm file if it already exists or create it.]"
"[e:exclusive?Open for exclusive access.]"
"[r:read?Open for read access only. \avname\a becomes a readonly variable.]"
"[w:write?Open for read and write access.]"
"[z:zero?When used with \b-c\b, a \b\\0\b byte is appended to each key.]"
"\n"
"\nvarname\n"
"\n"
"[+EXIT STATUS]"
"{"
"[+0?Successful completion.]"
"[+>0?An error occurred.]"
"}"
"[+SEE ALSO?\bksh\b(1), \bdbm\b(3)]"
;
struct dbm_array
{
char *val;
char *name;
char addzero;
char modified;
char init;
};
#ifndef NV_ASETSUB
# define NV_ASETSUB 8
#endif
{
return(dp);
}
{
{
if(olds)
{
}
else
}
return(olds);
}
{
{
}
else
}
{
char *val;
{
{
*val = '(';
}
else
{
}
}
else
{
int err;
{
}
}
}
{
{
}
else
{
*val = 0;
}
}
{
register int keylen;
switch(mode)
{
case NV_AINIT:
{
{
if(fp)
{
}
}
return((void*)ap);
}
case NV_ADELETE:
return((void*)ap);
case NV_AFREE:
{
}
return((void*)ap);
case NV_ANEXT:
{
}
else
{
}
else
return((void*)0);
case NV_ASETSUB:
if(sp)
{
}
/* FALL THROUGH*/
case NV_ACURRENT:
case NV_ANAME:
return((void*)0);
default:
if(sp)
{
{
return(0);
}
{
{
}
}
{
}
{
sfprintf(sfstderr,"subshell=%d subscript=%s will be modified, need to save \n",ap->shp->subshell,sp);
{
}
}
}
{
}
else
}
}
{
int fds[10],n=0;
#if _use_ndbm
for (;;)
{
{
case 'T':
continue;
case 'c':
continue;
case 'e':
continue;
case 'r':
continue;
case 'w':
continue;
case 'z':
zflag = 1;
continue;
case '?':
break;
case ':':
break;
}
break;
}
{
return 1;
}
if(oflags==0)
n++;
if (!error_info.errors && !(db=dbm_open(dbfile, oflags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)))
{
return 1;
}
while(n>0)
else
if(tname)
{
if(!tp)
}
return error_info.errors != 0;
#else
return 1;
#endif
}
{
if (!flag &&
}