dbu.c revision 04c1be97edc6cf31d47066b9020737c1d9e4d138
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* This file came from the SDBM package (written by oz@nexus.yorku.ca).
* That package was under public domain. This file has been ported to
* APR, updated to ANSI C and other, newer idioms, and added to the Apache
* codebase under the above copyright and license.
*/
#include "apr.h"
#include "apr_general.h"
#include "apr_pools.h"
#include "apr_errno.h"
#include "apr_getopt.h"
#include "apr_time.h"
#if APR_HAVE_STDIO_H
#include <stdio.h>
#endif
#include <unistd.h>
#include <stdlib.h> /* for atexit(), malloc() */
#include <string.h>
#include "apr_dbm.h"
static const char *progname;
static int rflag;
static const char *usage = "%s [-R] cat | look |... dbmname";
#define DERROR 0
#define DLOOK 1
#define DINSERT 2
#define DDELETE 3
#define DCAT 4
#define DBUILD 5
#define DPRESS 6
#define DCREAT 7
#define LINEMAX 8192
typedef struct {
const char *sname;
int scode;
int flags;
} cmd;
#if 0
#endif
};
{
char optch;
const char *optarg;
(void) apr_initialize();
switch (optch) {
case 'R': /* raw processing */
rflag++;
break;
default:
break;
}
return 0;
}
{
char *op;
int n;
char *line;
#ifdef TIME
long start;
extern long time();
#endif
case DLOOK:
line[n] = 0;
if (rv == APR_SUCCESS) {
putchar('\n');
continue;
}
}
break;
case DINSERT:
break;
case DDELETE:
line[n] = 0;
}
}
break;
case DCAT:
putchar('\t');
putchar('\n');
}
break;
case DBUILD:
#ifdef TIME
#endif
line[n] = 0;
*op++ = 0;
}
else
}
}
#ifdef TIME
#endif
break;
case DPRESS:
break;
case DCREAT:
break;
}
}
{
int i;
if (progname)
for (i = 0; i < (int)CTABSIZ; i++)
((i + 1) % 6 == 0) ? '\n' : ' ');
exit(1);
/*NOTREACHED*/
}
{
int i = CTABSIZ;
const cmd *p;
for (p = cmds; i--; p++)
return p;
return NULL;
}
{
int c;
const char *p = d.dptr;
int n = d.dsize;
while (n--) {
c = *p++ & 0377;
if (c & 0200) {
c &= 0177;
}
if (c == 0177 || c < ' ')
else
}
}
{
if (progname)
exit(1);
}