display - print a tableorlist on the standard output
SYNOPSIS
DESCRIPTION
display
reads a row from
tableorlist
and prints it on the standard output.
The source code,
display.c,
is listed below and
is also located in the
lib
subdirectory of the
/rdb
home directory.
It serves as a simple example of how to
process tables and lists using the
librdb.a
C interface.
SOURCE
char Copyright []="display.c: Copyright 1993 Schaffer and Wright";
/*
display is a sample program which illustrates the use of common
librdb.a column routines. It reads tables from the standard input
and writes them on the standard output.
*/
#define USAGE "[-fc] < tableorlist"
#include "rdb.h"
int Debug; /* global for debugging */
char *Program; /* who am i? */
struct rowstruct row; /* row information */
int colgeth (), colgetr (); /* input functions */
int colputh (), colputr (); /* outputfunctions */
char *getenv(), *getprog();
main (argc, argv)
int argc;
char *argv [];
{
register columns; /* columns returned */
register i; /* index for loops */
char *FS; /* ptr to column separator */
/* establish my identity for printing error messages */
Program = getprog(argv[0]);
/* check environment for oddball column separator */
FS = getenv("FS");
row.fs = (FS && *FS) ? *FS : TAB;
/* handle command line arguments */
for (i = 1; i < argc; i++) {
if (argv [i][0] != '-') {
/* process non-option arguments, like files, here */
continue;
}
switch (argv [i][1]) {
case 'D':
Debug = TRUE;
break;
case 'f':
if (argv[i][2])
row.fs = argv[i][2];
break;
/* add other options here */
default:
fprintf(stderr, "usage: %s %s\\n",
Program, USAGE);
exit(NOT_OK);
}
}
/* get table or list headlines */
if ((columns = colgeth (&row)) == EOF)
exit (EOF);
colputh (&row); /* output headlines */
/* read in each row till end-of-file */
while ((columns = colgetr (&row)) != EOF) {
/* output each row, or do other row processing */
colputr (&row);
}
/* return status code for shell evaluation */
exit (OK);
}