another 4gltags program
Posted in 1999
Topics: Installation, Setup & Upgrades, Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
I wrote this 4gltags program this morning so it's not fully tested yet,
but it seems to work fine. It's written using flex (fast lex). If you
don't have flex you can download the source from ftp.gnu.org/gnu/flex
This is analagous to ctags, but for 4gl source. Below is a shell archive
containing the source and the makefile. Move to a file and execute
sh 4gltags.shar
Let me know if there are issues.
travish@etcscan.com
--- cut here ---
: "@(#)unshark.sh 0.2"
#
# Created by: travish@etcscan.com
# On: Thu May 6 13:57:47 PDT 1999
# Contents: an unknown package
#
# 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:
#
# 4gltags.l
# 4gltags.makefile
#
# 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 an unknown package
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
#
#
# begin 4gltags.l
#
if [ -f 4gltags.l -a $NOCHECK != true ]
then
echo $0: 4gltags.l already exists
else
if [ $QUIET != true ]
then
echo 4gltags.l \\(5400 characters\\)
fi
cat >4gltags.l <<'EOF-4gltags.l'
/*---
* An Informix 4gl source tags file generator.
*
* Uses flex (fast lex)
*
* To create useable compiler droppings:
*
* 1. flex -i -Cfe 4gltags.l -- creates
lex.yy.c
* 2. cc -o 4gltags lex.yy.c -- creates
4gltags binary
* or
* 1. make -f /source/installed/4gltags.makefile -- creates
4gltags binary
*
*
* Travis Hume (travish@etcscan.com)
* Thu May 6 13:54:40 PDT 1999
*
*---
*
* Modification History
*
* 05/06/99 tjh Initial release.
*
*---
*/
%{
#include <limits.h>
%}
struct tagLine
{
char* tagName;
char* fileName;
char* line;
};
struct tagLine *tags;
char *curFileName;
int numTags = 0;
short tagSQL = TRUE;
WS [ \\t\\v]
ID [a-z][a-z0-9_]*
TAGGABLE ^{WS}*function{WS}+{ID}.*$
TAGGABLE_SQL ^{WS}*(declare|prepare){WS}+{ID}.*$
%x COMMENT
%s DO_SQL
%%
if(tagSQL)
BEGIN(DO_SQL);
{TAGGABLE} {
char* yycopy = (char*) strdup( yytext);
char* delimiter = " \\t(";
if((numTags % 100) == 0)
tags = (struct tagLine*) realloc( tags, sizeof( struct
tagLine)*(numTags+100));
strtok( yycopy, delimiter);
tags[numTags].tagName = (char*) strdup( strtok( NULL, delimiter));
tags[numTags].fileName = (char*) strdup( curFileName);
tags[numTags].line = (char*) strdup( yytext);
++numTags;
free( yycopy);
}
<DO_SQL>{TAGGABLE_SQL} {
char* yycopy = (char*) strdup( yytext);
char* delimiter = " \\t(";
if((numTags % 100) == 0)
tags = (struct tagLine*) realloc( tags, sizeof( struct
tagLine)*(numTags+100));
strtok( yycopy, delimiter);
tags[numTags].tagName = (char*) strdup( strtok( NULL, delimiter));
tags[numTags].fileName = (char*) strdup( curFileName);
tags[numTags].line = (char*) strdup( yytext);
++numTags;
free( yycopy);
}
"(#.*$)|(--.*$)" /* eat up one line comments */
"{" BEGIN(COMMENT);
<COMMENT>[^}\\n]* /* eat anything that's not a '}' */
<COMMENT>"}" BEGIN(INITIAL);
.|\\n ;
%%
/*---
* Comparison function passed to qsort() to sort tags array.
*
*/
int compareTags(const struct tagLine *a, const struct tagLine *b)
{
return( strcmp( a->tagName, b->tagName));
}
/*---
* Prints a usage statement.
*
*/
void printUsage()
{
printf("\\n");
printf("4gltags -- generate a tags file for 4gl source code.\\n");
printf("Usage: 4gltags [-(a|h|o(filename)|s)] (*.4gl|-)\\n");
printf("\\n");
printf("Options:\\n");
printf(" -a -- append to exsisting tags file\\n");
printf(" -h -- display this message\\n");
printf(" -o -- output to supplied filename instead of tags\\n");
printf(" -s -- don't generate tags for DECLARE and PREPARE
statements\\n");
printf("\\n");
}
/*---
*
*/
void writeTagsFile( char *outputFile, char *mode)
{
int i;
FILE *outFile;
outFile = fopen( outputFile, mode);
/*
* need to sort the tags now
*/
qsort( tags, numTags, sizeof( struct tagLine), (void*) compareTags);
/*
* write the tags file.
*/
for(i=0; i < numTags; ++i)
{
fprintf( outFile, "%s\\t%s\\t/^%s$/\\n", tags[i].tagName,
tags[i].fileName, tags[i].line);
}
}
/*
*
*/
void appendCurrentTags( char *file)
{
FILE *f = fopen( file, "r");
char buf[LINE_MAX];
char *delimiter = "\\t";
while( fgets( buf, LINE_MAX, f))
{
if((numTags % 100) == 0)
tags = (struct tagLine*) realloc( tags, sizeof( struct
tagLine)*(numTags+100));
tags[numTags].tagName = (char*) strdup( strtok( buf, delimiter));
tags[numTags].fileName = (char*) strdup( strdup( NULL, delimiter));
tags[numTags].line = (char*) strdup( strdup( NULL, delimiter));
}
fclose(f);
}
/*--
*
*/
int yywrap()
{
return 1;
}
/*--
*
*
*/
int main( int argc, char** argv)
{
extern char *optarg;
extern int optind;@@NL
TH wrote: > > I wrote this 4gltags program this morning so it's not fully tested yet, > but it seems to work fine. It's written using flex (fast lex). If you > don't have flex you can download the source from ftp.gnu.org/gnu/flex > > This is analagous to ctags, but for 4gl source. Below is a shell archive > containing the source and the makefile. Move to a file and execute > sh 4gltags.shar If you email this as an attachement to: software@iiug.org it will be placed in the Software Repository where anyone interested can download it forever. Art S. Kagel