Re: reserved word check pgm needed
Posted in 1993
In article <1993Mar24.165640.21140@techmpc.csg.mot.com> zuck@DCMPC.csg.gss.mot.com (Zuck Zuckerbrot) writes: } } anybody got a program that can scan my source for keywords? } Sure do... here 'tis! BTW, if you don't have ESQL/C loaded on your system, replace "esql" with "c4gl" in the makefile. Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh to create the files: # README # dbreserved.ec # dbvcs.h # keyword.h # makefile # 4. To overwrite existing files type: "sh file -c" # This archive created: Sun Sep 29 00:31:11 1991 export PATH; PATH=/bin:$PATH if test -f 'README' -a "${1}" != "-c" then echo shar: will not over-write existing file "'README'" else echo shar: extracting "'README'" '(325 characters)' sed 's/^X//' << \\SHAR_EOF > 'README' XDBRESERVED will scan an Informix-SQL table and print all reserved words to Xstdout. There are currently 400+ words that are checked. X XBefore typing "make", edit the dbvcs.h file and provide your ESQL/C serial and Xversion numbers on the appropriate lines. X XUsage can be obtained by typing "dbreserved" with out any arguments. SHAR_EOF if test 325 -ne "`wc -c < 'README'`" then echo shar: error transmitting "'README'" '(should have been 325 characters)' fi fi # end of overwriting check if test -f 'dbreserved.ec' -a "${1}" != "-c" then echo shar: will not over-write existing file "'dbreserved.ec'" else echo shar: extracting "'dbreserved.ec'" '(4608 characters)' sed 's/^X//' << \\SHAR_EOF > 'dbreserved.ec' X/* X***************************************************** X* X* Copyright(c) 1990 by David A. Snyder. X* X* This document contains information that is X* the property of David A. Snyder. X* X* INFORMIX -- Informix Software Inc. X* X* Title: dbreserved.ec X* X***************************************************** X*/ X X#include <ctype.h> X#include <stdio.h> X#include <string.h> X#include <search.h> X#include "dbvcs.h" X#include "keyword.h" X$include sqlca; X$include sqltypes; X X#define SUCCESS 0 X Xchar *database = NULL, *table = NULL; Xvoid exit(); X X$struct _systables { X char tabname[19]; X char owner[9]; X char dirpath[65]; X long tabid; X short rowsize; X short ncols; X short nindexes; X long nrows; X long created; X long version; X char tabtype[2]; X char audpath[65]; X} systables; X X$struct _syscolumns { X char colname[19]; X long tabid; X short colno; X short coltype; X short collength; X} syscolumns; X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X X $char exec_stmt[32], qry_stmt[72]; X extern char *optarg; X extern int optind, opterr; X int c, dflg = 0, errflg = 0, tflg = 0; X X /* Print copyright message */ X (void)fprintf(stderr, "\\n%-49.49s %29.29s\\n", "DBRESERVED Database Information Utility", SQVERSNUMBER); X (void)fprintf(stderr, "%s\\n", SQCOPYRIGHT); X (void)fprintf(stderr, "%s\\n\\n", SQSERIAL); X X /* get command line options */ X while ((c = getopt(argc, argv, "d:t:")) != EOF) X switch (c) { X case 'd': X dflg++; X database = optarg; X break; X case 't': X tflg++; X table = optarg; X break; X default: X errflg++; X break; X } X X /* validate command line options */ X if (errflg || !dflg) { X (void)fprintf(stderr, "USAGE:\\n\\n"); X (void)fprintf(stderr, "\\tdbreserved -d dbname [-t tabname]\\n\\n\\n"); X (void)fprintf(stderr, "\\t-d database name\\n\\n"); X (void)fprintf(stderr, "\\t-t table name\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n\\n"); X exit(1); X } X X /* locate the database in the system */ X sprintf(exec_stmt, "database %s", database); X $prepare db_exec from $exec_stmt; X $execute db_exec; X if (sqlca.sqlcode != SUCCESS) { X (void)fprintf(stderr, "Database not found or no system permission.\\n\\n"); X exit(1); X } X X /* build the select statement */ X if (tflg) X sprintf(qry_stmt, "select tabname, tabid from systables where tabname = \\"%s\\"", table); X else X sprintf(qry_stmt, "select tabname, tabid from systables order by tabname"); X X /* declare some cursors */ X $prepare tab_query from $qry_stmt; X $declare tab_cursor cursor for tab_query; X $declare col_cursor cursor for X select colname, colno from syscolumns X where tabid = $systables.tabid order by colno; X X /* read the database for the table(s) and create some output */ X $open tab_cursor; X $fetch tab_cursor into $systables.tabname, $systables.tabid; X if (sqlca.sqlcode == SQLNOTFOUND) X fprintf(stderr, "Table %s not found.\\n", table); X while (sqlca.sqlcode == SUCCESS) { X rtrim(systables.tabname); X if (systables.tabid >= 100 && X (strcmp(systables.tabname, "sysmenus") && X strcmp(systables.tabname, "sysmenuitems") && X strcmp(systables.tabname, "syscolatt") && X strcmp(systables.tabname, "sysvalatt") || tflg)) X read_syscolumns(); X $fetch tab_cursor into $systables.tabname, $systables.tabid; X } X $close tab_cursor; X X exit(0); X} X X Xread_syscolumns() X{ X char *bsearch(), tmp_column[19]; X int i, node_compare(); X struct node *node_ptr, node; X X node.string = tmp_column; X X $open col_cursor; X $fetch col_cursor into $syscolumns.colname, $syscolumns.colno; X while (sqlca.sqlcode == SUCCESS) { X rtrim(syscolumns.colname); X strcpy(node.string, syscolumns.colname); X node_ptr = (struct node *)bsearch((char *)(&node), X (char *)word_table, WORD_TABSIZE, X sizeof(struct node ), node_compare); X if (node_ptr != NULL) X (void)printf("Reserved: %s.%s\\n", systables.tabname, node_ptr->string); X $fetch col_cursor into $syscolumns.colname, $syscolumns.colno; X } X $close col_cursor; X} X X X/******************************************************************************* X* This function will trim trailing spaces from s. * X*******************************************************************************/ X Xrtrim(s) Xchar *s; X{ X int i; X X for (i = strlen(s) - 1; i >= 0; i--) X if (!isgraph(s[i]) || !isascii(s[i])) X s[i] = '\\0'; X else X break; X} X X X/******************************************************************************* X* This routine does the actual comparing for bsearch(). * X*******************************************************************************/ X Xnode_compare(node1, node2) Xstruct nod