??? 06/09/07 08:03 Modified: 06/09/07 08:13 Read: times |
#140475 - Here is one way to do it Responding to: ???'s previous message |
Step 1. Make a file similar to this. Call it SYMBOLS.TXT.
First_Scr Second_Scr This_Scr That_Scr NextToLast_Scr Last_ScrStep 2. Write a program similar to this one that will run on your PC. If you know AWK, that would be a good language choice. Otherwise, use whatever you are familiar with. /* //////////////////////////////////////////////////////////////////////////// x.c /////////////////////////////////////////////////////////////////////////////// DESCRIPTION: This program reads a list of symbols from SYMBOLS.TXT and automatically generates a corresponding set of #defines in SYMBOLS.H and a corresponding set of EQUs in SYMBOLS.INC. Adjust to suit if you don't like the hard coded filenames. REVISIONS: 9 Jun 07 - RAC - Genesis //////////////////////////////////////////////////////////////////////////// */ #include <stdio.h> /* //////////////////////////////////////////////////////////////////////////// Names for Numbers //////////////////////////////////////////////////////////////////////////// */ #define BUF_SIZE 200 void main() { FILE *pIn; // Pointer to input file FILE *pH; // Pointer to .H output file FILE *pI; // Pointer to .INC output file char symbol[BUF_SIZE]; // A gigantic input buffer int symbolCount; // Count symbols here /* Open all the input files, or die trying */ if (((pIn = fopen("SYMBOLS.TXT", "rt")) == NULL) || ((pH = fopen("SYMBOLS.H", "wt")) == NULL) || ((pI = fopen("SYMBOLS.INC", "wt")) == NULL)) { printf("File open error\n"); return; } /* Write a line to each output file for every line in the input file */ symbolCount = 0; // No symbols yet while (fgets(symbol, BUF_SIZE, pIn)) { // For each input line symbol[strlen(symbol) - 1] = '\0'; // Zap the newline character fprintf(pI, "%s\tEQU\t%d\n", // Make ASM include file entry symbol, symbolCount); fprintf(pH, "#define\t%s\t%d\n", // Make C header file entry symbol, symbolCount); symbolCount++; // Count symbol just processed } // End 'for each input line' /* Close all the files */ fclose(pIn); fclose(pI); fclose(pH); } // End main()Step 3. Run the program. It will make two files like this: #define First_Scr 0 #define Second_Scr 1 #define This_Scr 2 #define That_Scr 3 #define Penultimate_Scr 4 #define Last_Scr 5and this: First_Scr EQU 0 Second_Scr EQU 1 This_Scr EQU 2 That_Scr EQU 3 Penultimate_Scr EQU 4 Last_Scr EQU 5Step 4. Include these files with the rest of your program. Step 5. Make the whole process automatic by creating a batch file or a make file that runs the program above whenever there is a change in SYMBOLS.TXT. Step 6. Relax with a root beer. -- Russ |
Topic | Author | Date |
Constants as extern | 01/01/70 00:00 | |
Insufficient Information | 01/01/70 00:00 | |
tool-independent approach | 01/01/70 00:00 | |
Preprocessing | 01/01/70 00:00 | |
Example | 01/01/70 00:00 | |
RTFM? | 01/01/70 00:00 | |
Here is one way to do it | 01/01/70 00:00 | |
Thanks a lot![]() | 01/01/70 00:00 |