Re: File Operations in 4GL
Posted in 1998
This is a multi-part message in MIME format.
--------------617C6373A96F1C2F279AB2E8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Well, you'll have to make do with my stdio clone for 4gl, which boosts stdio
functinality and a couple of nifty additions, like line folding at word
boundaries (and you can even choose which word separator chars should be
returned at the end of a string and which at the beginning of the next!), the
ability to automatically prepend headers to input text (again with choice of
paragraph and folded lines text headers), the ability to drop text till the next
EOL mark, and even that to define your own IO streams (as a bonus, you also get
routines for a sockets client).
I never had the time to clean the documentation, so all you have are these quick
notes. The usage should be clear enough from the source code, though.
You basically open your streams with the xxx_open() routines, which return the
id of the newly opened stream, and do all the IO via the fd_xxxx routines, which
take as first parameter the stream id. Errors are normally returned via the
status global variable. Routines parameters in general match those of the
equivalent stdio routines: for instance file_open expects a file name and an IO
mode ("[rwa]\\+{0,1}"), pipe_open the name of an executable file and a mode
(either "r" or "w", this time).
User defined IO streams recipe: write your xxx_open routine, and have it call
fgw_addfd, passing it a stream identifier and read(), write() & close() function
pointers.
HTH,
Marco
_______________________________________________________________________________
Marco Greco, Catania, Italy marcog@linux.ctonline.it
rem radioterapia +39 95 447828 fax 446558
Informix faq http://www.iiug.org/techinfo/faq/informix.htm
4glworks http://www.ctonline.it/~marcog
Informix on Linux http://www.ctonline.it/~marcog/ifmxlinux.htm
ssoman@omm.com wrote:
>
> Hi all,
> Is there a way to do file operations ( like open, read, write to a file
> etc), apart from running a shell script or UNIX command in 4GL ( Informix ODS
> 7.23 UC1 on, 4GL 6.05 UD1 on IBM AIX 4.1.4.
>
> Sujata
> *****************************************
> Sujata Soman
>
>
> E-Mail: ssoman@omm.com
>
> O'Melveny & Myers, Los Angeles
>
> ******************************************
--------------617C6373A96F1C2F279AB2E8
Content-Type: application/x-sh; name="fglio.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="fglio.sh"
: "@(#)fglio.sh 1.0"
#
# Created by: marcog@ctonline.it
# On: Sat Feb 7 08:04:56 MET 1998
# Contents: A complete I/O system for Informix 4gl
#
# This shell script will install several files (and possibly
# directories) in your hard drive.
# It is suggested that it be run from an empty subdir, since
# failing to do so might result in partial file installation
# and / or disk cluttering.
# Be aware that its use and that of its contents may have
# limitations as set forth in the welcome screen and the archive
# contents itself.
# Possible switches:
#
# -n doesn't check for file presence
# -q for (almost) quiet operation
#
# Files in this archive:
#
# fglio/fgiusr.c
# fglio/fglcmn.c
# fglio/fglio.c
# fglio/is-osdep.h
# fglio/is-osdep.sco
# fglio/is-osdep.t32
# fglio/isokc.c
#
# Here's all the shell utilities usage that might cause problems.
# Edit appropriately if you are stuck.
#
AWK=${AWK:-awk}
filesize()
{
ls -l $1 | $AWK '{print $5}'
}
PG=`find /bin /usr/bin /usr/lbin -name pg -print`
if [ -z "$PG" ]
then
PG=more
fi
#
# get parms
#
QUIET=false
NOCHECK=false
while [ $# -ne 0 ]
do
case $1 in
-n)
NOCHECK=true
;;
-q)
QUIET=true
;;
*)
echo Usage: $0 [-c] [-q]
exit 1
;;
esac
shift
done
#
# display welcome text - it may not fit on the screen, so we need a paginator
#
tput clear
$PG <<'EOF-entry'
This shell script will install A complete I/O system for Informix 4gl
If you are not running it from a suitable directory
hit <DEL> now to abort installation
EOF-entry
#
# more does not wait for a key while displaying last screen
#
if [ $PG = more ]then
read a
unset a
fi
#
# create directories as needed
#
mkdir -p fglio
#
# begin fgiusr.c
#
if [ -f fglio/fgiusr.c -a $NOCHECK != true ]
then
echo $0: fglio/fgiusr.c already exists
else
if [ $QUIET != true ]
then
echo fglio/fgiusr.c \\(1184 characters\\)
fi
cat >fglio/fgiusr.c <<'EOF-fgiusr.c'
/*
fgiusr.c - sample fgiusr.c for fglio.c
Marco Greco (marcog@ctonline.it), Catania, Italy
Initial release: Nov 92
Current release: Jan 98
*/
#include "fgicfunc.h"
int file_open();
int pipe_open();
int fd_read();
int fd_write();
int fd_writeln();
int file_lock();
int file_unlock();
int file_tell();
int file_seek();
int fd_eof();
int fd_eol();
int fd_droptoeol();
int fd_close();
int fd_linelen();
int fd_crnl();
int fd_prewordsep();
int fd_postwordsep();
int fd_1stlineheader();
int fd_2stlineheader();
cfunc_t usrcfuncs[] =
{
"file_open", file_open, 2,
"pipe_open, pipe_open, 2,
"fd_read", fd_read, 1,
"fd_write, fd_write, 2,
"fd_writeln", fd_writeln, 2,
"file_lock, file_lock, 2,
"file_unlock, file_unlock, 1,
"file_tell, file_tell, 1,
"file_seek", file_seek, 2,
"fd_eof", fd_eof, 1,
"fd_eol", fd_eol, 1,
"fd_droptoeol", fd_droptoeol, 1,
"fd_close", fd_close, 1,
"fd_linelen", fd_linelen, 2,
"fd_crnl", fd_crnl, 2,
"fd_prewordsep", fd_prewordsep, 2,
"fd_postwordsep", fd_postwordsep, 2,
"fd_1stlineheader", fd_1stlineheader, 2,
"fd_2stlineheader", fd_2ndlineheader, 2,
0, 0, 0
};
EOF-fgiusr.c
if [ `filesize fglio/fgiusr.c` -ne 1184 ]
then
echo $0: fglio/fgiusr.c extracted with wrong size
fi
fi
#
# end fgiusr.c
#
# begin fglcmn.c
#
if [ -f fglio/fglcmn.c -a $NOCHECK != true ]
then
echo $0: fglio/fglcmn.c already exists
else
if [ $QUIET != true ]
then
echo fglio/fglcmn.c \\(1701 characters\\)
fi
cat >fglio/fglcmn.c <<'EOF-fglcmn.c'
/*
FGLCMNC.c - functions used by C functions only
Author: Marco Greco (marcog@ctonline.it), Catania, Italy
Initial release: Oct 92
Current release: Jan 98
No warranty expressed or implied. All risks connected to the use of
this fi