| 59 | ****************************************************************************/ |
| 60 | |
| 61 | int main(int argc, char **argv) |
| 62 | { |
| 63 | FILE *instream; |
| 64 | FILE *outstream; |
| 65 | bool delimited; |
| 66 | bool inhex; |
| 67 | int ret = 1; |
| 68 | int i; |
| 69 | int j; |
| 70 | |
| 71 | if (argc != 3) |
| 72 | { |
| 73 | fprintf(stderr, "ERROR: Two arguments expected\n"); |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | /* Open the source file read-only */ |
| 78 | |
| 79 | instream = fopen(argv[1], "r"); |
| 80 | if (instream == NULL) |
| 81 | { |
| 82 | fprintf(stderr, "ERROR: Failed to open %s for reading\n", argv[1]); |
| 83 | return 1; |
| 84 | } |
| 85 | |
| 86 | /* Open the destination file write-only */ |
| 87 | |
| 88 | outstream = fopen(argv[2], "w"); |
| 89 | if (outstream == NULL) |
| 90 | { |
| 91 | fprintf(stderr, "ERROR: Failed to open %s for reading\n", argv[2]); |
| 92 | goto errout_with_instream; |
| 93 | } |
| 94 | |
| 95 | /* Process each line in the file */ |
| 96 | |
| 97 | while ((fgets(g_line, LINESIZE, instream) != NULL)) |
| 98 | { |
| 99 | /* Search for a '0x' that preceding some delimiting character */ |
| 100 | |
| 101 | delimited = true; |
| 102 | inhex = false; |
| 103 | |
| 104 | for (i = 0; |
| 105 | i < LINESIZE && g_line[i] != '\n' && g_line[i] != '\0'; |
| 106 | i++) |
| 107 | { |
| 108 | if (inhex) |
| 109 | { |
| 110 | if (isxdigit(g_line[i])) |
| 111 | { |
| 112 | g_line[i] = tolower(g_line[i]); |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | inhex = false; |
| 117 | } |
| 118 | } |