I would appreciate getting suggestions on how to approach the following situation.
As mentioned in previous messages to this group, I am porting code from SPARC/Sun_OS/Sun_compilers (development and runtime) to Intel/Solaris_7/GNU_compilers (also development and runtime). Source code are in C, C++, and Pascal. One requirement is to keep the source code so that it can be built in either platforms. I have used #ifdef/#else/#endif with asmname and wrapper functions/ subroutines to handle this.
My problem is with several global variables. For example, I have one called "emulator_error" and it is used in 250 files with around 100 in C and 150 in Pascal source files. Is there a way to avoid editing all 150 Pascal files to put the #ifdef/#else/#endif with asmname directive? I believe writing a script to do this will be complicated since the variable names can be declared in a line where several variables are declared. For example: Var test_val, emulator_error, sum : integer; and only emulator_error is used in both C and Pascal; test_val and sum are referenced in Pascal source code only.
Regards,
Jing Gloria Texas Instruments Sherman, Texas
"Gloria, Jing" wrote:
I would appreciate getting suggestions on how to approach the following situation.
As mentioned in previous messages to this group, I am porting code from SPARC/Sun_OS/Sun_compilers (development and runtime) to Intel/Solaris_7/GNU_compilers (also development and runtime). Source code are in C, C++, and Pascal. One requirement is to keep the source code so that it can be built in either platforms. I have used #ifdef/#else/#endif with asmname and wrapper functions/ subroutines to handle this.
My problem is with several global variables. For example, I have one called "emulator_error" and it is used in 250 files with around 100 in C and 150 in Pascal source files. Is there a way to avoid editing all 150 Pascal files to put the #ifdef/#else/#endif with asmname directive? I believe writing a script to do this will be complicated since the variable names can be declared in a line where several variables are declared. For example: Var test_val, emulator_error, sum : integer; and only emulator_error is used in both C and Pascal; test_val and sum are referenced in Pascal source code only.
Regards,
Jing Gloria Texas Instruments Sherman, Texas
PLEASE do not use html or mime types in messages. It is extremely annoying, not to mention rude.
I am copying this to both the GPC maillist and to you directly. That way it will reach you even if the mailling list absorbs attachments.
You can bodily alter identifiers in a set of files with the attached utility, which runs under MsDos. It can handle both Pascal, C, and Intel style assembly syntax (in recognition of comments). For C I believe it knows nothing about \ comments. You simply prepare an idpairs file which consists of a list of changes, of the form:
oldidentifier newidentifier
one per line. The files will be revised in a single pass. Such things as making a newidentifier that originally appeared in the source will be flagged.
To reverse, reverse the order of columns in the idpairs file.
For help, run id2id with no parameters.
You can apply the same list of changes to multiple files by a simple DOS batch file, or with an entry in your makefile. The added facilities of 4dos in batch files will be useful here.
Unfortunately I have lost the source (ISO 7185 standard Pascal) in a disk crash. Someday I hope I can find it again on some floppy or other, but that may never happen. I no longer remember whether or not it treats strings correctly in all cases. I believe it does for Pascal, where there is no possibility of escaped quote marks etc.
It has two phases, the first of which reads idpairs and forms a couple of binary AVL trees (thus allowing any alphabetization of the idpairs file), and then scans the input file in one pass, extracting identifiers and searching the AVL tree for a replacement.
It will also flag replacements that were never executed because the oldid was never found.