APPENDIX D C Routine to give a list of databases


This probably won't work with ESQL/C 4.10 unless you use the extra file missing.c which was provided by Hugh Grierson (hugh@nezsdc.icl.co.nz).

This is totally unsupported, and not guaranteed on any platform whatsoever!


#!/bin/sh
# shar: Shell Archiver (v1.22)
if test -f dbnames.ec; then echo "File dbnames.ec exists"; else
echo "x - dbnames.ec"
sed 's/^X//' << 'SHAR_EOF' > dbnames.ec &&
X/*
X@(#)File:            dbnames.ec
X@(#)Version:         1.1
X@(#)Last changed:    91/03/14
X@(#)Purpose:         Print list of visible databases
X@(#)Author:          John Cooke/Mark Jeske/Jonathan Leffler
X*/
X
X/*
X**********************************************************
X** This code is derived from two almost identical      **
X** programs with the identifications preserved below:  **
X**********************************************************
X** dbnames.ec                                          **
X** List all available database names.                  **
X** Mark J (Informix) 3-13-91                           **
X**********************************************************
X** From: johnc@obelix (John Cooke)                     **
X** Quite a coincidence ....  I wrote THIS program:     **
X** program to get the names of all visible databases   **
X**********************************************************
X** Compile using:                                      **
X** esql -o dbnames dbnames.ec $INFORMIXDIR/lib/librds.a       **
X**********************************************************
X*/
X
X#ifndef lint
Xstatic char     sccs[] = "@(#)dbnames.ec 1.1 91/03/14";
X#endif
X
X#include <stdio.h>
X
X#define MAXDBS    100
X#define FASIZ     (MAXDBS * 19)
X
Xmain()
X{
X int             ndbs;
X int             sqlcode;
X int             i;
X char           *dbsname[MAXDBS + 1];
X char            dbsarea[FASIZ];
X
X if ((sqlcode = sqgetdbs(&ndbs, dbsname, MAXDBS, dbsarea, FASIZ)) != 0)
X  fprintf(stderr, "error code %d from sqgetdbs\n", sqlcode);
X else
X {
X  for (i = 0; i < ndbs; ++i)
X   printf("%d %s\n", i, dbsname[i]);
X }
X
X return (0);
X}
SHAR_EOF
chmod 0444 dbnames.ec || echo "$0: failed to restore dbnames.ec"
fi
if test -f missing.c; then echo "File missing.c exists"; else
echo "x - missing.c"
sed 's/^X//' << 'SHAR_EOF' > missing.c &&
X
Xextern int strcmp();
X
X/*
X * the string compare function for qsort()
X */
Xint frmcmpr(p, q)
Xchar **p;
Xchar **q;
X{
X    return strcmp(*p, *q);
X}
X
X/*
X * remove duplicates from a sorted array of strings
X * return the number of elements in the compacted array
X */
Xint compact(list, n)
Xchar **list;
Xint n;
X{
X    char **s, **p;
X
X    s=list;
X    for (p=list+1; p<list+n; ++p) {
X if (strcmp(*s, *p) != 0) {
X     ++s;
X     *s = *p;
X }
X    }
X
X    return s-list+1;
X}
X
SHAR_EOF
chmod 0664 missing.c || echo "$0: failed to restore missing.c"
fi
echo All files extracted
exit 0