#!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # kw.c # # This shell archive created: Mon Mar 9 11:02:02 EST 1992 # echo "Extracting file kw.c" sed -e 's/^X//' <<\SHAR_EOF > kw.c X/* kw.c X** X** Reads stdin, writes to stdout. For use with vi !G X** or otherwise as a filter. X** X** Maps 4GL keywords to upper-case. X*/ X X#include X#include X#include X X#define HASHSIZE 101 X#define MAXCHARS 200 X Xstruct nlist *lookup(); Xchar * malloc(); Xvoid free(); X Xstruct nlist { /* table entry: */ X struct nlist *next; /* next entry in chain */ X char * name; /* defined name */ X char * defn; /* replacement text */ X}; X Xstatic struct nlist * hashtab[HASHSIZE]; /* pointer table */ X Xstatic char *initials[] = { /* these are 4GL keywords */ X "absolute", "ABSOLUTE", X "accept", "ACCEPT", X "add", "ADD", X "after", "AFTER", X "all", "ALL", X "allowing", "ALLOWING", X "alter", "ALTER", X "and", "AND", X "any", "ANY", X "arg_val", "ARG_VAL", X "argc", "ARGC", /* set to 1, extern int for cc */ X "array", "ARRAY", X "arr_count", "ARR_COUNT", X "arr_curr", "ARR_CURR", X "as", "AS", X "asc", "ASC", X "ascii", "ASCII", X "at", "AT", X "attribute", "ATTRIBUTE", X "attributes", "ATTRIBUTES", X "audit", "AUDIT", X "auto", "AUTO", X "autonext", "AUTONEXT", /* For Perform */ X "average", "AVERAGE", X "avg", "AVG", X "before", "BEFORE", X "begin", "BEGIN", X "between", "BETWEEN", X "blink", "BLINK", X "blue", "BLUE", X "bold", "BOLD", X "border", "BORDER", X "bottom", "BOTTOM", X "break", "BREAK", X "by", "BY", X "call", "CALL", X "case", "CASE", X "char", "CHAR", X "check", "CHECK", X "clear", "CLEAR", X "clipped", "CLIPPED", X "close", "CLOSE", X "cluster", "CLUSTER", X "column", "COLUMN", X "columns", "COLUMNS", X "command", "COMMAND", X "comment", "COMMENT", X "comments", "COMMENTS", /* for Perform */ X "commit", "COMMIT", X "committed", "COMMITTED", /* from esql manual */ X "composites", "COMPOSITES", X "connect", "CONNECT", X "construct", "CONSTRUCT", X "continue", "CONTINUE", X "control", "CONTROL", X "correct", "CORRECT", X "count", "COUNT", X "create", "CREATE", X "current", "CURRENT", X "cursor", "CURSOR", X "cyan", "CYAN", X "database", "DATABASE", X "date", "DATE", X "day", "DAY", X "dba", "DBA", X "dec_t", "DEC_T", /* from esql manual */ X "decimal", "DECIMAL", X "declare", "DECLARE", X "default", "DEFAULT", X "defaults", "DEFAULTS", X "defer", "DEFER", X "define", "DEFINE", X "delete", "DELETE", X "delimiter", "DELIMITER", X "desc", "DESC", X "describe", "DESCRIBE", X "descriptor", "DESCRIPTOR", /* from esql manual */ X "dim", "DIM", X "dirty", "DIRTY", /* from esql manual */ X "display", "DISPLAY", X "displayonly", "DISPLAYONLY", X "distinct", "DISTINCT", X "dos", "DOS", X "double", "DOUBLE", X "down", "DOWN", X "downshift", "DOWNSHIFT", X "drop", "DROP", X "else", "ELSE", X "end", "END", X "entry", "ENTRY", X "error", "ERROR", X "errorlog", "ERRORLOG", X "err_get", "ERR_GET", X "err_print", "ERR_PRINT", X "err_quit", "ERR_QUIT", X "esc", "ESC", X "escape", "ESCAPE", X "every", "EVERY", X "exclusive", "EXCLUSIVE", X "execute", "EXECUTE", X "exists", "EXISTS", X "exit", "EXIT", X "exitnow", "EXITNOW", X "extent", "EXTENT", /* from esql manual */ X "extern", "EXTERN", /* from esql manual */ X "external", "EXTERNAL", X "false", "FALSE", X "fetch", "FETCH", X "field", "FIELD", X "file", "FILE", X "finish", "FINISH", X "first", "FIRST", X "fixchar", "FIXCHAR", /* from esql manual */ X "float", "FLOAT", X "flush", "FLUSH", X "for", "FOR", X "foreach", "FOREACH", X "form", "FORM", X "form4gl", "FORM4GL", X "format", "FORMAT", X "formonly", "FORMONLY", /* not in keywords list */ X "free", "FREE", /* from esql manual */ X "from", "FROM", X "function", "FUNCTION", X "globals", "GLOBALS", X "goto", "GOTO", X "grant", "GRANT", X "green", "GREEN", X "group", "GROUP", X "having", "HAVING", X "header", "HEADER", /* Reports and ACE */ X "headings", "HEADINGS", X "help", "HELP", X "if", "IF", X "in", "IN", X "include", "INCLUDE", X "incorrect", "INCORRECT", X "index", "INDEX", X "initialize", "INITIALIZE", X "input", "INPUT", X "insert", "INSERT", X "instructions", "INSTRUCTIONS", X "int", "INT", /* from esql manual */ X "int_flag", "INT_FLAG", /* 4gl global var */ X "integer", "INTEGER", X "interrupt", "INTERRUPT", X "into", "INTO", X "invisible", "INVISIBLE", X "is", "IS", X "isolation", "ISOLATION", /* from esql manual */ X "joining", "JOINING", X "key", "KEY", X "label", "LABEL", X "last", "LAST", X "left", "LEFT", /* not in keyword list */ X "length", "LENGTH", X "let", "LET", X "level", "LEVEL", X "like", "LIKE", X "line", "LINE", X "lineno", "LINENO", X "lines", "LINES", X "load", "LOAD", X "lock", "LOCK", X "log", "LOG", X "long", "LONG", X "magenta", "MAGENTA", X "main", "MAIN", X "margin", "MARGIN", X "master", "MASTER", X "matches", "MATCHES", X "max", "MAX", X "mdy", "MDY", X "menu", "MENU", X "message", "MESSAGE", X "min", "MIN", X "mod", "MOD", X "mode", "MODE", X "modify", "MODIFY", X "money", "MONEY", X "month", "MONTH", X "name", "NAME", X "need", "NEED", X "netauf", "NETAUF", X "next", "NEXT", X "nextfield", "NEXTFIELD", X "no", "NO", X "noentry", "NOENTRY", X "normal", "NORMAL", X "not", "NOT", X "notfound", "NOTFOUND", X "noupdate", "NOUPDATE", X "null", "NULL", X "num_args", "NUM_ARGS", X "of", "OF", X "off", "OFF", /* from esql manual */ X "on", "ON", X "open", "OPEN", X "option", "OPTION", X "options", "OPTIONS", X "or", "OR", X "order", "ORDER", X "otherwise", "OTHERWISE", X "outer", "OUTER", X "output", "OUTPUT", X "page", "PAGE", X "pageno", "PAGENO", X "pause", "PAUSE", X "percent", "PERCENT", X "picture", "PICTURE", X "pipe", "PIPE", X "prepare", "PREPARE", X "previous", "PREVIOUS", X "print", "PRINT", X "printer", "PRINTER", X "prior", "PRIOR", X "privileges", "PRIVILEGES", X "program", "PROGRAM", X "prompt", "PROMPT", X "public", "PUBLIC", X "put", "PUT", X "query", "QUERY", X "queryclear", "QUERYCLEAR", X "quit", "QUIT", X "quit_flag", "QUIT_FLAG", /* 4gl global variable */ X "read", "READ", /* from esql manual */ X "record", "RECORD", X "recover", "RECOVER", /* not in keyword list */ X "red", "RED", X "register", "REGISTER", X "relative", "RELATIVE", X "remove", "REMOVE", X "rename", "RENAME", X "repeatable", "REPEATABLE", /* from esql manual */ X "report", "REPORT", X "required", "REQUIRED", X "reslog", "RESLOG", X "resource", "RESOURCE", X "return", "RETURN", X "returning", "RETURNING", X "reverse", "REVERSE", X "revoke", "REVOKE", X "right", "RIGHT", X "rollback", "ROLLBACK", X "rollforward", "ROLLFORWARD", X "row", "ROW", X "rowid", "ROWID", X "rows", "ROWS", X "run", "RUN", X "screen", "SCREEN", X "scroll", "SCROLL", X "scr_line", "SCR_LINE", X "section", "SECTION", /* from esql manual */ X "select", "SELECT", X "serial", "SERIAL", X "set", "SET", X "set_count", "SET_COUNT", X "share", "SHARE", X "short", "SHORT", /* from esql manual */ X "size", "SIZE", /* from esql manual */ X "skip", "SKIP", X "sleep", "SLEEP", X "smallfloat", "SMALLFLOAT", /* from esql manual */ X "smallint", "SMALLINT", X "some", "SOME", X "space", "SPACE", X "spaces", "SPACES", X "sqlawarn", "SQLAWARN", X "sqlca", "SQLCA", X "sqlcode", "SQLCODE", X "sqlerrd", "SQLERRD", X "stability", "STABILITY", /* from esql manual */ X "start", "START", X "startlog", "STARTLOG", X "static", "STATIC", /* from esql manual */ X "statistics", "STATISTICS", X "step", "STEP", X "stop", "STOP", X "string", "STRING", /* from esql manual */ X "struct", "STRUCT", /* from esql manual */ X "sum", "SUM", X "synonym", "SYNONYM", X "systables", "SYSTABLES", X "table", "TABLE", X "tables", "TABLES", X "temp", "TEMP", X "text", "TEXT", /* cannot use in forms */ X "then", "THEN", X "through", "THROUGH", X "thru", "THRU", X "time", "TIME", X "to", "TO", X "today", "TODAY", X "top", "TOP", X "trailer", "TRAILER", X "true", "TRUE", X "type", "TYPE", X "typedef", "TYPEDEF", X "underline", "UNDERLINE", X "union", "UNION", /* from esql manual */ X "unique", "UNIQUE", X "unix", "UNIX", X "unload", "UNLOAD", X "unlock", "UNLOCK", X "up", "UP", X "update", "UPDATE", X "upshift", "UPSHIFT", X "user", "USER", X "using", "USING", X "validate", "VALIDATE", X "value", "VALUE", X "values", "VALUES", X "verify", "VERIFY", X "view", "VIEW", X "wait", "WAIT", X "waiting", "WAITING", X "warning", "WARNING", X "wcolor", "WCOLOR", /* from esql manual */ X "weekday", "WEEKDAY", X "when", "WHEN", X "whenever", "WHENEVER", X "where", "WHERE", X "while", "WHILE", X "white", "WHITE", X "window", "WINDOW", X "with", "WITH", X "without", "WITHOUT", X "work", "WORK", X "wrap", "WRAP", X "year", "YEAR", X "yellow", "YELLOW", X "zerofill", "ZEROFILL", X NULL, NULL X}; X X Xunsigned Xhash(s) /* hash: form hash value for string s */ Xchar *s; X{ X unsigned hashval; X X for (hashval = 0; *s != '\0'; s++) X hashval = *s + 31 * hashval; X return hashval % HASHSIZE; X} X X/* lookup: look for s in hashtab */ Xstruct nlist * Xlookup(s) Xchar *s; X{ X struct nlist *np; X int hashval; X hashval = hash(s); X for (np = hashtab[hashval]; np != NULL;) X { X if (strcmp(s, np->name) == 0) X return np; /* found */ X np = np->next; X } X return NULL; /* not found */ X} X Xstruct nlist * Xinstall(name, defn) /* install: put (name, defn) in hashtab */ Xchar *name; Xchar *defn; X{ X struct nlist *np; X unsigned hashval; X X if ((np = lookup(name)) == NULL) /* not found */ X { X np = (struct nlist *) malloc(sizeof (*np)); X if (np == NULL || (np->name = strdup(name)) == NULL) X { X perror("malloc"); X return NULL; X } X hashval = hash(name); X np->next = hashtab[hashval]; X hashtab[hashval] = np; X } X else /* already there */ X free((char *) np->defn); /* free previous definition */ X X if ((np->defn = strdup(defn)) == NULL) X return NULL; /* malloc failed */ X return np; X} X X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X int c; X int gotword; /* flag - within "token" */ X int incomment; /* within comment, take literally */ X int i; X X char wordbuf[MAXCHARS]; /* temp storage for building words in */ X char lcbuf[MAXCHARS]; /* after mapped to lower case */ X char *cptr; /* pointer into string */ X char **aptr; /* pointer into array of keywords */ X X struct nlist *retval; X X aptr = initials; /* point to first keyword */ X X if (argc != 1) X { X fprintf(stderr, "\n%s: usage is\n\n %s outfile\n\n", X *argv, *argv); X exit (1); X } X X while (*aptr != 0) X { X install(*aptr, *(aptr + 1)); /* instal first pair of keywords */ X aptr += 2; /* step past them */ X } X X while ((c = getchar()) != EOF) /* now start working */ X { X if (c == '"') /* start of string */ X { X putchar(c); /* first double quote */ X X while((c = getchar()) != EOF && c != '"') /* read the rest */ X { X if (c == '\\') /* escape the next char */ X { X putchar(c); X if ((c = getchar()) == EOF) /* got end of file */ X ungetc(c, stdin); X } X putchar(c); X } X X if (c == '"') X putchar(c); /* end of string */ X else X ungetc(c, stdin); /* EOF */ X X continue; X } X X incomment = 0; X X if (c == '{') /* start of comment */ X { X putchar(c); /* opening brace */ X incomment++; X X while((c = getchar()) != EOF && incomment) /* read the rest */ X { X switch(c) X { X /* case '{': This is wrong, since the first closing X incomment++; brace ends the comment. X break; */ X case '}': X incomment--; X break; X default: X break; X } X putchar(c); X } X X ungetc(c, stdin); /* not a closing brace */ X continue; X } X X if (c == '#') /* start of comment */ X { X putchar(c); /* # */ X X while((c = getchar()) != EOF && c != '\n') /* read rest of line */ X putchar(c); X X if (c == '\n') X putchar(c); /* newline */ X else X ungetc(c, stdin); /* EOF */ X continue; X } X X if (isalnum(c) == NULL && c != '_') /* not part of token */ X { X putchar(c); X continue; X } X X ungetc(c, stdin); /* might be a token */ X X cptr = wordbuf; /* note posn of buffer start */ X X gotword = 0; /* may not be token: could be number */ X X while ((c = getchar()) != EOF) X { X if (isalnum(c) || c == '_') /* in token ? */ X { X *cptr++ = c; /* save the char */ X gotword = 1; /* token found */ X } X else X break; X } X *cptr = NULL; /* terminate */ X X if (gotword) X { X /* map to lower-case */ X for (i = 0; i < MAXCHARS && *(wordbuf + i); i++) X { X if (isupper( *(wordbuf + i))) X *(lcbuf + i) = tolower(*(wordbuf + i)); X else X *(lcbuf + i) = *(wordbuf + i); X } X X *(lcbuf + i) = NULL; /* terminate */ X X retval = lookup(lcbuf); /* get new text */ X X if (retval == NULL) X fputs(wordbuf, stdout); /* no substitute, use old text */ X else X fputs(retval->defn, stdout); /* substitute */ X } X X ungetc(c, stdin); /* last char was not alnum */ X } X} SHAR_EOF if [ `wc -c < kw.c` -ne 17027 ] then echo "Lengths do not match -- Bad Copy of kw.c" fi echo "Done."