Re: Help converting ESQL/C from Informix 2.10 to 4.x/5.x
Posted in 1993
Date: Wed, 13 Oct 93 09:28:02 MDT From: alan@po.den.mmc.com (Alan Popiel) To: inbladt@autelca.ascom.ch Subject: Re: Help converting ESQL/C from Informix 2.10 to 4.x/5.x ->From: nbladt@autelca.ascom.ch (Norbert Bladt) ->Subject: Help converting ESQL/C from Informix 2.10 to 4.x/5.x ->Date: Wed, 13 Oct 1993 09:46:07 GMT ->Reply-To: nbladt@autelca.ascom.ch (Norbert Bladt) ->Organization: Ascom Autelca AG, Guemligen, Switzerland -> ->Hello Informix users ! -> ->In the past I got very good answers to my questions I did ask here. ->Thanks a lot for those answers ! So I am asking you for help, again. -> ->We did use, and in fact are still using, Informix Version 2.10 on the ->NCR-Tower to develop applications for our customer. -> ->A co-worker wrote all the database related stuff in C using ESQL/C. ->He used a mix of upper and lower-case characters for the host variables. ->Now, the ESQL preprocessor which came with 2.10 converts all host-variables ->to lower case characters. Therefore, he had to use the lower-case variant ->of the host variables whenever he is using simple C (i.e. no ESQL involved). ->Why he didn't use all lower-case every time ? I don't know ! -> ->Now, the ESQL preprocessor which comes with 4.x/5.x does not do this conversion ->and I couldn't find neither a tool nor an option of ESQL to do this ->upper-case to lower-case conversion. The preprocessor, of course, complains ->about undefined variables (in the C part of the code, that is). -> ->Because there are a lot of files containing this type of ESQL/C code I would ->like to get a tool (or an - undocumented - option for ESQL) to do the ->conversion of all host-variables in an ESQL statement (declaration or ->usage in a select, update, etc.) to all lower-case. -> ->I can't use a mix of upper and lower-case characters because the same code ->must run (and compiled) under the old (2.10) and the new (4.x/5.x) version ->of Informix. -> ->Here is an example of the code, so you can see what my problem is: -> ->[...] ->$string DatabaseError; /* defining the host variable */ ->[...] -> databaseerror = GermanDatabaseErrorText; /* host variable in C */ ->[...] -> databaseerror = FrenchDatabaseErrorText; /* host variable in C */ ->[...] ->$select from ... into ... where text = $DatabaseError; /* host var. in esql */ ->[...] -> ->If somebody has a tool to do the conversion (sed, awk, etc. is fine, perhaps ->even perl, although I have to port it to Interactive UNIX, first) ->please mail (or post) information about it to me. -> ->Many thanks in advance, -> ->Norbert. ->-- ->Norbert Bladt, Ascom Autelca AG, Worbstr. 201, CH-3073 Guemligen, Switzerland ->Phone: +41 31 999 65 52 FAX: +41 31 999 65 44 ->Mail: nbladt@autelca.ascom.ch UUCP: ..!uunet!mcsun!chsun!hslrswi!aut!nbladt -> It seems to me the simplest (maybe not the most efficient, but simple is good) answer is a sed script something like this: script fixup: ------------- sed 's/VarOne/varone/g\\ s/VarTwo/vartwo/g\\ s/VarLast/varlast/g' $1 >$2 The above is csh syntax. Omit the \\ for sh. I don't know what syntax changes are needed for ksh, tsh, bash, etc. The script's usage would be: fixup filein fileout As new undefined variables are reported by the C compiler add lines like: s/AnotherVar/anothervar/g\\ to your script, after 'vartwo' and before 'varlast'. Advantages: 1. sed is generally available in most UNIXs, while perl, awk, nawk, etc. may not be. However, there are shell differences, as noted above. 2. sed is somewhat simpler to use than awk, perl, etc. 3. This type of script is easy to maintain and update. Disadvantages: 1. You may need to use several steps, since the length of the sed command, between the quotes, may quickly exceed whatever the limit is, assuming you need to convert a lot of variables. 2. You may change things you don't want to, unless you construct your substitute strings VERY carefully. For example, the (partial) sed command s/DatabaseError/databaseerror/g\\ would also change 'GermanDatabaseErrorText' to 'GermandatabaseerrorText'. Of course, you can use s/(\\[^a-z]\\)DatabaseError(\\[^a-z]\\)/\\1databaseerror\\2/g\\ but this starts to be *NOT simple*, and makes disadvantage 1 even worse. Now that I have written this all out, it doesn't seem quite as great a solution as it did at first. Thus, I am just sending it directly to you, instead of posting to the net. However, it is at least something, and this technique should work, if you don't receive some better solution. I would be interested to hear of the improved techniques you receive. Regards, Alan ___________________________ ______________________| R. Alan Popiel |__________________________ \\ Internet: | Martin Marietta, Tech Ops | / \\ alan@den.mmc.com | P.O. Box 179, M/S 5422 | Std disclaimers apply. / )Voice: | Denver, CO 80201-0179 USA | ( / 303-977-9998 |___________________________| (But you knew that!) \\ /________________________) (____________________________\\ P.S. I tried sending this direct, but the mail bounced. So I am posting it, in hopes of getting it to Norbert, even tho' my solution isn't as good as it first seemed to be. -Alan