Re: Any indent tools for Informix-4GL?
Posted in 1994
In article <1994Jul20.170856.106@mixcom.mixcom.com>, amby <amby@mixcom.mixcom.com> wrote: > What I need is something like the GNU indent tool (for C code) that will > correct the indenting of 4GL code. > > Does such a tool exist? Ummm, kind-of: I wrote a C program to do this because a bunch of AUSTRALIANS thought it would be way-cool to destroy all indentation in our source, and to remove all the comments (you've gotta worry!). This program is not perfect. It screws up on DISPLAY ARRAYs and PROMPTs which have matching ENDs, and doesn't get END RECORDs quite perfect, but it's close enough considering that it's hardly ever used: If it's of use, great, if not - I guess you haven't lost anything. PS: I'm (quite clearly) NOT a C programmer: ---------------------------- CUT HERE -------------------------------- /* reform.c - Program to reformat indentation of .4gl source code */ /* 07/10/93 Kerry S - Written 08/10/93 Kerry S - Add FORM, so that OPTIONS line up OK 14/10/93 Kerry S - Upper case input line when checking for keyword match (so that we recognize if and If as though they were IF) 26/10/93 Kerry S - Fix so that "where_part" not recongised as "where" */ #include <stdio.h> #include <string.h> void main(argc, argv) int argc; char *argv[]; { static struct keywords{ char word[15]; char type; /* Y=Normal hard-NL. T=Column 40 (Not implemented!) */ char out; /* Y=Indent right */ char in; /* Y=Indent left */ } words[200] = { {"#", 'Y', 'Y', 'Y'}, {"{", 'Y', 'Y', 'Y'}, {"AFTER", 'Y', 'Y', 'Y'}, {"ALTER", 'Y', 'N', 'N'}, {"AND", 'Y', 'N', 'N'}, {"ARRAY", 'T', 'N', 'N'}, {"BEFORE", 'Y', 'Y', 'Y'}, {"BEGIN", 'Y', 'N', 'N'}, {"BOTTOM", 'Y', 'N', 'N'}, {"BYTE", 'T', 'N', 'N'}, {"CALL", 'Y', 'N', 'N'}, {"CASE", 'Y', 'Y', 'N'}, {"CHAR", 'T', 'N', 'N'}, {"CHARACTER", 'T', 'N', 'N'}, {"CLEAR", 'Y', 'N', 'N'}, {"CLOSE", 'Y', 'N', 'N'}, {"COMMAND", 'Y', 'Y', 'Y'}, {"COMMENT", 'Y', 'N', 'N'}, {"COMMIT", 'Y', 'N', 'N'}, {"CONSTRUCT", 'Y', 'N', 'N'}, {"CONTINUE", 'Y', 'N', 'N'}, {"CREATE", 'Y', 'N', 'N'}, {"CURRENT", 'Y', 'N', 'N'}, {"DATABASE", 'Y', 'N', 'N'}, {"DATE", 'T', 'N', 'N'}, {"DATETIME", 'T', 'N', 'N'}, {"DECLARE", 'Y', 'N', 'N'}, {"DEC", 'T', 'N', 'N'}, {"DECIMAL", 'T', 'N', 'N'}, {"DEFER", 'Y', 'N', 'N'}, {"DEFINE", 'Y', 'Y', 'Y'}, {"DELETE", 'Y', 'N', 'N'}, {"DISPLAY", 'Y', 'N', 'N'}, {"DOUBLE", 'T', 'N', 'N'}, {"DROP", 'Y', 'N', 'N'}, {"ELSE", 'Y', 'Y', 'Y'}, {"END", 'Y', 'N', 'Y'}, {"ERROR", 'Y', 'N', 'N'}, {"EVERY", 'Y', 'Y', 'Y'}, {"EXECUTE", 'Y', 'N', 'N'}, {"EXIT", 'Y', 'N', 'N'}, {"FETCH", 'Y', 'N', 'N'}, {"FINISH", 'Y', 'N', 'N'}, {"FIRST", 'Y', 'Y', 'Y'}, {"FLOAT", 'T', 'N', 'N'}, {"FLUSH", 'Y', 'N', 'N'}, {"FOREACH", 'Y', 'Y', 'N'}, {"FORM", 'Y', 'N', 'N'}, {"FORMAT", 'Y', 'Y', 'Y'}, {"FOR", 'Y', 'Y', 'N'}, {"FREE", 'Y', 'N', 'N'}, {"FROM", 'Y', 'N', 'N'}, {"FUNCTION", 'Y', 'Y', 'N'}, {"GLOBALS", 'Y', 'Y', 'N'}, {"GOTO", 'Y', 'N', 'N'}, {"GRANT", 'Y', 'N', 'N'}, {"HELP", 'Y', 'N', 'N'}, {"IF", 'Y', 'Y', 'N'}, {"INITIALIZE", 'Y', 'N', 'N'}, {"INPUT", 'Y', 'Y', 'N'}, {"INSERT", 'Y', 'N', 'N'}, {"INTO", 'Y', 'N', 'N'}, {"INTERVAL", 'T', 'N', 'N'}, {"INTEGER", 'T', 'N', 'N'}, {"INT", 'T', 'N', 'N'}, {"LABEL", 'Y', 'Y', 'Y'}, {"LEFT", 'Y', 'N', 'N'}, {"LET", 'Y', 'N', 'N'}, {"LIKE", 'T', 'N', 'N'}, {"LOAD", 'Y', 'N', 'N'}, {"LOCATE", 'Y', 'N', 'N'}, {"LOCK", 'Y', 'N', 'N'}, {"LONG", 'T', 'N', 'N'}, {"MAIN", 'Y', 'Y', 'N'}, {"MENU", 'Y', 'Y', 'N'}, {"MESSAGE", 'Y', 'N', 'N'}, {"MONEY", 'T', 'N', 'N'}, {"NEED", 'Y', 'N', 'N'}, {"NEXT", 'Y', 'N', 'N'}, {"NUMERIC", 'T', 'N', 'N'}, {"ON", 'Y', 'Y', 'Y'}, {"OPEN", 'Y', 'N', 'N'}, {"OPTIONS", 'Y', 'N', 'N'}, {"OR", 'Y', 'N', 'N'}, {"ORDER", 'Y', 'N', 'N'}, {"OTHERWISE", 'Y', 'Y', 'Y'}, {"OUTPUT", 'Y', 'N', 'N'}, {"PAGE", 'Y', 'Y', 'Y'}, {"PAUSE", 'Y', 'N', 'N'}, {"PREPARE", 'Y', 'N', 'N'}, {"PRINT", 'Y', 'N', 'N'}, {"PROMPT", 'Y', 'N', 'N'}, {"PUT", 'Y', 'N', 'N'}, {"REAL", 'T', 'N', 'N'}, {"RECORD", 'T', 'Y', 'N'}, {"RECOVER", 'Y', 'N', 'N'}, {"RENAME", 'Y', 'N', 'N' }, {"REPORT", 'Y', 'Y', 'N'}, {"RETURN", 'Y', 'N', 'N'}, {"REVOKE", 'Y', 'N', 'N'}, {"RIGHT", 'Y', 'N', 'N'}, {"ROLLBACK", 'Y', 'N', 'N'}, {"RUN", 'Y', 'N', 'N'}, {"SCROLL", 'Y', 'N', 'N'}, {"SELECT", 'Y', 'N', 'N'}, {"SERIAL", 'T', 'N', 'N'}, {"SET", 'Y', 'N', 'N'}, {"SKIP", 'Y', 'N', 'N'}, {"SLEEP", 'Y', 'N', 'N'}, {"SMALLFLOAT", 'T', 'N', 'N'}, {"SMALLINT", 'T', 'N', 'N'}, {"START", 'Y', 'N', 'N'}, {"TEXT", 'T', 'N', 'N'}, {"THEN", 'Y', 'Y', 'Y'}, {"TOP", 'Y', 'N', 'N'}, {"UNLOAD", 'Y', 'N', 'N'}, {"UNLOCK", 'Y', 'N', 'N'}, {"UPDATE", 'Y', 'N', 'N'}, {"VALIDATE", 'Y', 'N', 'N'}, {"VARCHAR", 'T', 'N', 'N'}, {"WHENEVER", 'Y', 'N', 'N'}, {"WHEN", 'Y', 'Y', 'Y'}, {"WHERE", 'Y', 'N', 'N'}, {"WHILE", 'Y', 'Y', 'N'}, {"!LAST!", 'Y', 'Y', 'N'}}; int i, j, lth, spos, indent, found, last_keylth; FILE *fin, *fout; char inline[500], outline[500]; char first[15]; indent = 0; last_keylth = 0; if (argc != 2) {@@N