#!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # dbstruct.news # # This shell archive created: Fri Mar 6 09:41:35 EST 1992 # echo "Extracting file dbstruct.news" sed -e 's/^X//' <<\SHAR_EOF > dbstruct.news XFrom walt@mathcs.emory.edu Thu Mar 5 12:25:41 1992 XReceived: from emory.mathcs.emory.edu by X rmy.rmy.emory.edu (5.65/Emory_rmy.3.2.6) via SMTP X id AA21002 ; Thu, 5 Mar 92 12:25:41 -0500 XReceived: by X emory.mathcs.emory.edu (5.65/Emory_mathcs.3.3.3) via MAILPROG X id AA09999 ; Thu, 5 Mar 92 12:25:37 -0500 XReturn-Path: walt@mathcs.emory.edu XDate: Thu, 5 Mar 92 12:25:37 -0500 XFrom: walt@mathcs.emory.edu (Walt Hultgren {rmy}) XMessage-Id: <9203051725.AA09999@emory.mathcs.emory.edu> XTo: informix-news-gate@rmy XSubject: Re: INFORMIX schemas -> C header files XX-Informix-List-Id: X XPath: emory!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!think.com!wupost!uunet!ispd-newsserver!kodak!music!amiano XFrom: amiano@music.Kodak.COM (Mitch Amiano) XNewsgroups: comp.databases.informix XMessage-ID: <1992Mar5.132923.21047@kodak.kodak.com> XDate: 5 Mar 92 13:29:23 GMT XReferences: <1992Mar3.233906.8757@dbsm.oz.au> <1992Mar5.051017.17231@informix.com> XSender: amiano@music (Mitch Amiano) XOrganization: Eastman Kodak Co., Rochester, NY X XAnd now for something completely different. XThis is a ditty I recently wrote up. It is shell based, and is somewhat on the slow side, Xbut it gives just C structures and an appropriate typedef'ed synonym. Use at your own Xrisk. I thought it would be helpful to compare the ESQL/C to a shell implementation :-) X X X X#---- Cut here ----- X: X# dbstruct: dump database table schema and convert into C language structure X# this version is really RAW. use with trepidation. X# X# All Rights Deserved X# Copyright 1992 by Mitch C. Amiano. X# The contents of this file may not be shipped with X# a commercial product without this copyright message. X# No claim is made as to the appropriateness of this software to any task. X# Use at your own risk. No warranty is expressed or implied. X# X# Utilities used: dbschema, fgrep, egrep, sed X# X# Sugar Free dbstruct: No Temp Files; Never had 'em, never will. X# X# Version 0.0.0.1 Written for SCO-UNIX 3.2.2 ( OpenDeskTop ) X# X# Author: Mitch C. Amiano X# Software Contractor X# P O Box 215 Avon NY 14414 X# 716-226-2024 X# X Xcat >&2 <&2 < myfile.h Xwhere tablename is any table in the current database X and myfile.h is a file name you choose X XTable names may be left out, defaulting to ALL tables in the database. XSystem tables are excluded from the output. Xchar() field lengths are incremented to allow for a C null (\0) terminator XEOT Xexit 0 Xfi X Xif [ -z "$TABLES" ] Xthen X TABLES=`isql gateway </dev/null | egrep -v "tabname|row(s)|f[0-9]+" X select tabname from systables where tabname not like "sys%" XEOT` Xfi X Xfor table in $TABLES Xdo X X echo "" X X dbschema -d gateway -t $table | \ X fgrep -vy 'informix XCopyright XSoftware Xcreate unique Xcreate index X' | X sed "s/smallfloat/float/g; \ Xs/ integer/ long/g; \ Xs/ serial/ long/g; \ Xs/ smallint/ short/g; \ Xs/ float/ double/g; \ Xs/ datetime .*/ dtime_t/g; \ Xs/ date .*/ long/g; \ Xs/ decimal .*/ dec_t/g; \ Xs/ money .*/ dec_t/g; \ X/{.*}/d; \ Xs/create table \".*\"\.\(.*\)/\$struct S_\1/g; \ Xs/create view \".*\"\.\(.*\)/\$struct S_\1/g; \ Xs/,//g; \ Xs/not null//g; \ Xs/char(\(.*\))/char[\1]/g; \ Xs/^ *);/};/g; \ Xs/^ *(/{/g; \ X/($/d; \ X/^ *revoke /d; \ X/^$/d; \ X" | \ X sed "s/^\( *\)\(.*\) char\[\(.*\)\]/\1char \2[\3];/g; \ Xs/^\( *\)\(.*\) short/\1short \2;/g Xs/^\( *\)\(.*\) long/\1long \2;/g; \ Xs/^\( *\)\(.*\) double/\1double \2;/g; \ Xs/^\( *\)\(.*\) float/\1float \2;/g; \ Xs/^\( *\)\(.*\) dtime_t/\1dtime_t \2;/g; \ Xs/^\( *\)\(.*\) dec_t/\1dec_t \2;/g; \ X" | \ X sed -e '/^ *;/!{H; } X/^ *};/{ XG X/\$struct/!{d; } Xs/\n\$struct S_\([0-9a-zA-Z_]*\).*/$typedef struct S_\1 T_\1; /p X} X' | \ X while read Line X do X Num=`echo $Line | sed -n "s/[ a-zA-Z_0-9]*\[\(.*\)];/\1/p"` X if [ -n "$Num" ] X then X Num=`expr $Num + 1` X fi X echo "$Line" | sed "s/\([[ a-zA-Z_0-9]*\[\).*\(];\)/\1$Num\2/p" X X done X X echo "" Xdone X X#--- Cut here ---- X X---------------------------------------------------------------------------- X| Mitch Amiano Current Work Phone: 716-477-3506 | X| Software Contractor Address: amiano@music.kodak.com | X| Rochester, NY | X| 716-226-2024 | X---------------------------------------------------------------------------- SHAR_EOF if [ `wc -c < dbstruct.news` -ne 5320 ] then echo "Lengths do not match -- Bad Copy of dbstruct.news" fi echo "Done."