Changeset b164303 in rtems
- Timestamp:
- 11/25/14 21:55:49 (9 years ago)
- Branches:
- 4.11, 5, master
- Children:
- 038faca1
- Parents:
- d4ec0a2
- git-author:
- Josh Oguin <josh.oguin@…> (11/25/14 21:55:49)
- git-committer:
- Joel Sherrill <joel.sherrill@…> (11/26/14 13:52:00)
- Location:
- tools/build
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/build/binpatch.c
rd4ec0a2 rb164303 1 2 #include <stdio.h>3 #include <stdlib.h>4 5 1 /* 6 2 * This function will patch binary file 7 3 */ 8 4 5 #include <stdio.h> 6 #include <stdlib.h> 7 #include <assert.h> 9 8 10 9 static char buf[512]; … … 26 25 printf("<byte2> - byte 1 of patch\n"); 27 26 printf("<byte3> - byte 1 of patch\n"); 28 29 return;30 27 } 31 28 … … 33 30 main(int argc, char **argv) 34 31 { 35 int c;32 int c; 36 33 FILE *ofp, *ifp; 37 char patch[4], *end; 38 int patchLen, tmp, i, off, cnt, patched, len, reloc; 39 34 char *patch, *end; 35 int patchLen, tmp, i, off, cnt, patched, len, reloc; 40 36 41 37 /* parse command line options */ 42 while ((c = getopt(argc, argv, "h")) >= 0) 43 { 44 switch (c) 45 { 46 case 'h': 47 usage(); 48 return 0; 49 default: 50 usage(); 51 return 1; 52 } 53 } 38 while ((c = getopt(argc, argv, "h")) >= 0) { 39 switch (c) { 40 case 'h': 41 usage(); 42 return 0; 43 default: 44 usage(); 45 return 1; 46 } 47 } 54 48 55 if(argc < 6) 56 { 49 if(argc < 6) { 57 50 usage(); 58 51 return 1; 59 52 } 60 53 61 54 /* Let us get offset in file */ 62 55 reloc = strtol(argv[3], &end, 0); 63 if(end == argv[3] || off < 0) 64 { 56 if (end == argv[3] || reloc < 0) { 65 57 fprintf(stderr, "bad reloc value %s\n", argv[3]); 66 58 return 1; 67 59 } 68 60 69 61 off = strtol(argv[4], &end, 0); 70 if(end == argv[4] || off < 0 || off < reloc) 71 { 62 if (end == argv[4] || off < 0 || off < reloc) { 72 63 fprintf(stderr, "bad offset value %s\n", argv[4]); 73 64 return 1; 74 65 } 75 66 76 67 off -= reloc; … … 78 69 /* Let us get patch */ 79 70 patchLen = argc - 5; 71 patch = calloc( patchLen, sizeof(char) ); 72 assert( patch ); 80 73 81 for(i=0; i<patchLen; i++) 82 { 74 for (i=0; i<patchLen; i++) { 83 75 tmp = strtol(argv[5+i], &end, 0); 84 76 85 if(end == argv[4+i] || tmp < 0 || tmp > 0xff) 86 { 87 fprintf(stderr, "bad byte value %s\n", argv[5+i]); 88 return 1; 89 } 90 patch[i] = tmp; 91 } 77 if (end == argv[4+i]) { 78 fprintf(stderr, "bad byte value %s\n", argv[5+i]); 79 free(patch); 80 return 1; 81 } 82 if (tmp < 0 || tmp > 0xff) { 83 fprintf(stderr, "not a byte value %s\n", argv[5+i]); 84 free(patch); 85 return 1; 86 } 87 patch[i] = (tmp & 0xff); 88 } 92 89 93 90 ifp = fopen(argv[2], "r"); 94 if(ifp == NULL) 95 { 91 if (ifp == NULL) { 96 92 fprintf(stderr, "unable to open file %s\n", argv[2]); 93 free(patch); 97 94 return 1; 98 95 } 99 96 100 97 ofp = fopen(argv[1], "w"); 101 if(ofp == NULL) 102 { 98 if (ofp == NULL) { 103 99 fprintf(stderr, "unable to open file %s\n", argv[1]); 100 fclose(ifp); 101 free(patch); 104 102 return 1; 105 103 } 106 104 107 105 cnt = 0; 108 106 patched = 0; 109 for(;;) 110 { 107 for(;;) { 111 108 len = fread(buf, 1, sizeof(buf), ifp); 112 109 113 if(len == 0) 114 { 115 break; 116 } 110 if(len == 0) { 111 break; 112 } 117 113 118 if(cnt <= off && (cnt + len) > off) 119 { 120 /* Perform patch */ 121 for(i=0; i<patchLen && (off+i)<(cnt+len); i++) 122 { 123 buf[off-cnt+i] = patch[i]; 124 } 125 patched = 1; 126 } 127 else if(cnt > off && cnt < (off + patchLen)) 128 { 129 /* Perform patch */ 130 for(i=cnt-off; i<patchLen; i++) 131 { 132 buf[off-cnt+i] = patch[i]; 133 } 134 patched = 1; 135 } 114 if (cnt <= off && (cnt + len) > off) { 115 /* Perform patch */ 116 for(i=0; i<patchLen && (off+i)<(cnt+len); i++) 117 { 118 buf[off-cnt+i] = patch[i]; 119 } 120 patched = 1; 121 } else if(cnt > off && cnt < (off + patchLen)) { 122 /* Perform patch */ 123 for(i=cnt-off; i<patchLen; i++) { 124 buf[off-cnt+i] = patch[i]; 125 } 126 patched = 1; 127 } 136 128 137 129 fwrite(buf, 1, len, ofp); 138 130 139 131 cnt += len; 140 132 } 141 133 142 134 fclose(ifp); 143 135 fclose(ofp); 136 free(patch); 144 137 145 if(!patched) 146 { 138 if (!patched) { 147 139 fprintf(stderr, "warning: offset is beyond input file length\n"); 148 140 fprintf(stderr, " no patch is performed\n"); 149 141 } 150 142 151 143 return 0; -
tools/build/cklength.c
rd4ec0a2 rb164303 126 126 opterr = 0; /* we'll report all errors */ 127 127 while ((c = getopt(argc, argv, GETOPTARGS)) != EOF) 128 switch (c) 129 { 128 switch (c) { 130 129 case 'l': /* line length */ 131 130 line_length = atoi( optarg ); … … 151 150 } 152 151 153 if (showusage) 154 { 152 if (showusage) { 155 153 (void) fprintf(stderr, "%s", USAGE); 156 154 exit(1); … … 161 159 */ 162 160 163 for ( ; argv[optind]; optind++)161 for ( ; optind < argc; optind++) { 164 162 if (Failed(process(argv[optind]))) 165 163 rc = FAILURE; 164 } 166 165 167 166 return rc; … … 269 268 (void) fflush(stderr); 270 269 271 if (error_flag & (ERR_FATAL | ERR_ABORT)) 272 { 273 if (error_flag & ERR_FATAL) 274 { 270 if (error_flag & (ERR_FATAL | ERR_ABORT)) { 271 if (error_flag & ERR_FATAL) { 275 272 error(0, "fatal error, exiting"); 276 273 exit(local_errno ? local_errno : 1); 277 } 278 else 279 { 274 } else { 280 275 error(0, "fatal error, aborting"); 281 276 abort(); … … 292 287 long val; 293 288 294 if ( ! strchr("0123456789-", *s)) 295 { 289 if ( !strchr("0123456789-", *s) ) { 296 290 error(ERR_FATAL, "'%s' is not a number", s); 297 return min;291 /* does not return */ 298 292 } 299 293 300 294 val = strtol(s, (char **) NULL, 0); 301 if ((val < min) || (val > max)) 302 { 295 if ((val < min) || (val > max)) { 303 296 if (min == max) 304 297 error(ERR_FATAL, "%s can only be %ld", s, min); 305 298 else 306 299 error(ERR_FATAL, "%s must be between %ld and %ld", msg, min, max); 300 /* does not return */ 307 301 } 308 302 -
tools/build/eolstrip.c
rd4ec0a2 rb164303 190 190 * Don't count the carriage return. 191 191 */ 192 193 length = strlen( buffer ) - 1; 192 length = 0; 193 if ( *buffer != '\0' ) 194 length = strnlen( buffer, BUFFER_SIZE ) - 1; 194 195 195 196 if ( buffer[ length ] != '\n' ) 196 197 error(ERR_ERRNO|ERR_FATAL, "Line %d too long in %s\n", line_number, arg); 197 198 198 while ( isspace( (unsigned char) buffer[ length ] ) )199 while ( length && isspace( (unsigned char) buffer[ length ] ) ) 199 200 buffer[ length-- ] = '\0'; 200 201 … … 209 210 fclose( in ); 210 211 if ( !test_only ) { 211 fclose( out ); 212 rename( outname, arg ); 212 if (out) fclose( out ); 213 rc = rename( outname, arg ); 214 if ( rc != 0 ) { 215 fprintf( stderr, "Unable to rename %s to %s\n", outname, arg ); 216 } 213 217 } 214 218 return rc; -
tools/build/rtems-bin2c.c
rd4ec0a2 rb164303 56 56 { 57 57 FILE *ifile, *ocfile, *ohfile; 58 char buf[PATH_MAX ], *p;59 char obasename[PATH_MAX ];60 char ocname[PATH_MAX ];61 char ohname[PATH_MAX ];58 char buf[PATH_MAX+1], *p; 59 char obasename[PATH_MAX+1]; 60 char ocname[PATH_MAX+1]; 61 char ohname[PATH_MAX+1]; 62 62 const char *cp; 63 63 size_t len; 64 65 ocfile = NULL; 66 ohfile = NULL; 64 67 65 68 /* Error check */ … … 101 104 102 105 if ( createC ) { 103 ocfile = fopen(ocname, "wb");104 if (ocfile == NULL) {105 fprintf(stderr, "cannot open %s for writing\n", ocname);106 exit(1);107 }106 ocfile = fopen(ocname, "wb"); 107 if (ocfile == NULL) { 108 fprintf(stderr, "cannot open %s for writing\n", ocname); 109 exit(1); 110 } 108 111 } 109 112 110 113 if ( createH ) { 111 ohfile = fopen(ohname, "wb");112 if (ohfile == NULL) {113 fprintf(stderr, "cannot open %s for writing\n", ohname);114 exit(1);115 }114 ohfile = fopen(ohname, "wb"); 115 if (ohfile == NULL) { 116 fprintf(stderr, "cannot open %s for writing\n", ohname); 117 exit(1); 118 } 116 119 } 117 120 118 121 /* find basename */ 119 122 char *ifbasename = strdup(ifname); 123 if ( ifbasename == NULL ) { 124 fprintf(stderr, "cannot allocate memory\n" ); 125 fclose(ifile); 126 if ( createC ) { fclose(ocfile); } 127 if ( createH ) { fclose(ohfile); } 128 exit(1); 129 } 130 120 131 ifbasename = basename(ifbasename); 121 132 122 133 strcpy(buf, ifbasename); 123 for (p = buf; *p != '\0'; ++p) 124 if (!isalnum( *p))134 for (p = buf; *p != '\0'; ++p) { 135 if (!isalnum((unsigned char)*p)) /* cast to avoid negative indexing */ 125 136 *p = '_'; 137 } 126 138 127 139 if ( createC ) { 128 /* print C file header */129 fprintf(130 ocfile,131 "/*\n"132 " * Declarations for C structure representing binary file %s\n"133 " *\n"134 " * WARNING: Automatically generated -- do not edit!\n"135 " */\n"136 "\n"137 "#include <sys/types.h>\n"138 "\n",139 ifbasename140 );141 142 /* print structure */143 fprintf(144 ocfile,145 "%s%sunsigned char %s[] = {\n ",146 ((usestatic) ? "static " : ""),147 ((useconst) ? "const " : ""),148 buf149 );150 int c, col = 1;151 while ((c = myfgetc(ifile)) != EOF) {152 if (col >= 78 - 6) {153 fprintf(ocfile, "\n ");154 col = 1;155 }156 fprintf(ocfile, "0x%.2x, ", c);157 col += 6;158 159 }160 fprintf(ocfile, "\n};\n");161 162 /* print sizeof */163 fprintf(164 ocfile,165 "\n"166 "%s%ssize_t %s_size = sizeof(%s);\n",167 ((usestatic) ? "static " : ""),168 ((useconst) ? "const " : ""),169 buf,170 buf171 );140 /* print C file header */ 141 fprintf( 142 ocfile, 143 "/*\n" 144 " * Declarations for C structure representing binary file %s\n" 145 " *\n" 146 " * WARNING: Automatically generated -- do not edit!\n" 147 " */\n" 148 "\n" 149 "#include <sys/types.h>\n" 150 "\n", 151 ifbasename 152 ); 153 154 /* print structure */ 155 fprintf( 156 ocfile, 157 "%s%sunsigned char %s[] = {\n ", 158 ((usestatic) ? "static " : ""), 159 ((useconst) ? "const " : ""), 160 buf 161 ); 162 int c, col = 1; 163 while ((c = myfgetc(ifile)) != EOF) { 164 if (col >= 78 - 6) { 165 fprintf(ocfile, "\n "); 166 col = 1; 167 } 168 fprintf(ocfile, "0x%.2x, ", c); 169 col += 6; 170 171 } 172 fprintf(ocfile, "\n};\n"); 173 174 /* print sizeof */ 175 fprintf( 176 ocfile, 177 "\n" 178 "%s%ssize_t %s_size = sizeof(%s);\n", 179 ((usestatic) ? "static " : ""), 180 ((useconst) ? "const " : ""), 181 buf, 182 buf 183 ); 172 184 } /* createC */ 173 185 … … 177 189 178 190 if ( createH ) { 179 /* print H file header */180 char hbasename[PATH_MAX];181 char* p;182 /* Clean up the file name if it is an abs path */183 strcpy(184 hbasename,185 obasename186 );187 p = hbasename;188 while (*p != '\0') {189 if (*p < '0' || *p > 'z')190 *p = '_';191 ++p;192 }193 fprintf(194 ohfile,195 "/*\n"196 " * Extern declarations for C structure representing binary file %s\n"197 " *\n"198 " * WARNING: Automatically generated -- do not edit!\n"199 " */\n"200 "\n"201 "#ifndef __%s_h\n"202 "#define __%s_h\n"203 "\n"204 "#include <sys/types.h>\n"205 "\n",206 ifbasename, /* header */207 hbasename, /* ifndef */208 hbasename /* define */209 );210 211 /* print structure */212 fprintf(213 ohfile,214 "extern %s%sunsigned char %s[];",215 ((usestatic) ? "static " : ""),216 ((useconst) ? "const " : ""),217 buf218 );219 /* print sizeof */220 fprintf(221 ohfile,222 "\n"223 "extern %s%ssize_t %s_size;\n",224 ((usestatic) ? "static " : ""),225 ((useconst) ? "const " : ""),226 buf227 );228 229 fprintf(230 ohfile,231 "\n"232 "#endif\n"233 );191 /* print H file header */ 192 char hbasename[PATH_MAX]; 193 char* p; 194 /* Clean up the file name if it is an abs path */ 195 strcpy( 196 hbasename, 197 obasename 198 ); 199 p = hbasename; 200 while (*p != '\0') { 201 if (*p < '0' || *p > 'z') 202 *p = '_'; 203 ++p; 204 } 205 fprintf( 206 ohfile, 207 "/*\n" 208 " * Extern declarations for C structure representing binary file %s\n" 209 " *\n" 210 " * WARNING: Automatically generated -- do not edit!\n" 211 " */\n" 212 "\n" 213 "#ifndef __%s_h\n" 214 "#define __%s_h\n" 215 "\n" 216 "#include <sys/types.h>\n" 217 "\n", 218 ifbasename, /* header */ 219 hbasename, /* ifndef */ 220 hbasename /* define */ 221 ); 222 223 /* print structure */ 224 fprintf( 225 ohfile, 226 "extern %s%sunsigned char %s[];", 227 ((usestatic) ? "static " : ""), 228 ((useconst) ? "const " : ""), 229 buf 230 ); 231 /* print sizeof */ 232 fprintf( 233 ohfile, 234 "\n" 235 "extern %s%ssize_t %s_size;\n", 236 ((usestatic) ? "static " : ""), 237 ((useconst) ? "const " : ""), 238 buf 239 ); 240 241 fprintf( 242 ohfile, 243 "\n" 244 "#endif\n" 245 ); 234 246 } /* createH */ 235 247 … … 241 253 if ( createC ) { fclose(ocfile); } 242 254 if ( createH ) { fclose(ohfile); } 255 free(ifbasename); 243 256 } 244 257 -
tools/build/unhex.c
rd4ec0a2 rb164303 37 37 #include <stdarg.h> 38 38 #include <errno.h> 39 #include <assert.h> 39 40 40 41 #include "config.h" … … 72 73 */ 73 74 74 #define B0(x) (( x) & 0xff)75 #define B1(x) B0(( x) >> 8)76 #define B2(x) B0(( x) >> 16)77 #define B3(x) B0(( x) >> 24)75 #define B0(x) (((u32)x) & 0xff) 76 #define B1(x) B0(((u32)x) >> 8) 77 #define B2(x) B0(((u32)x) >> 16) 78 #define B3(x) B0(((u32)x) >> 24) 78 79 79 80 typedef struct buffer_rec { … … 120 121 long getNbytes(char **p, int n); 121 122 void badformat(char *s, char *fname, char *msg); 122 123 #define get1bytes(p) ((int) getbyte(p)) 124 #define get2bytes(p) ((int) getNbytes(p, 2)) 123 void fix_string_from_gets(char *s, size_t max); 124 125 #define get1bytes(p) (getbyte(p)) 126 #define get2bytes(p) getNbytes(p, 2) 125 127 #define get3bytes(p) getNbytes(p, 3) 126 128 #define get4bytes(p) getNbytes(p, 4) … … 141 143 ) 142 144 { 143 registerint c;145 int c; 144 146 bool showusage = FALSE; /* usage error? */ 145 147 int rc = 0; 146 148 FILE *outfp, *infp; 149 long base_long = 0; 147 150 148 151 /* 149 152 * figure out invocation leaf-name 150 153 */ 151 152 154 if ((progname = strrchr(argv[0], '/')) == (char *) NULL) 153 155 progname = argv[0]; … … 160 162 * Check options and arguments. 161 163 */ 162 163 164 progname = argv[0]; 164 while ((c = getopt(argc, argv, "F:a:o:vl")) != EOF) 165 switch (c) 166 { 165 while ((c = getopt(argc, argv, "F:a:o:vl")) != EOF) { 166 switch (c) { 167 167 case 'a': /* base address */ 168 base = stol(optarg); 168 base_long = stol(optarg); 169 if (base_long < 0) { 170 (void) fprintf(stderr, "%s", USAGE); 171 (void) fprintf(stderr, "\n*** base is an illegal value\n" ); 172 exit(1); 173 } 174 base = (u32) base_long; 175 169 176 break; 170 177 … … 188 195 showusage = TRUE; 189 196 } 190 191 if (showusage) 192 {197 } 198 199 if (showusage) { 193 200 (void) fprintf(stderr, "%s", USAGE); 194 201 exit(1); 195 202 } 196 203 197 if (linear && (base != 0)) 198 { 204 if (linear && (base != 0)) { 199 205 error(0, "-l and -a may not be specified in combination"); 200 206 exit(1); 201 207 } 202 208 203 if (STREQ(outfilename, "-")) 204 { 209 if (STREQ(outfilename, "-")) { 205 210 outfp = stdout; 206 211 outfilename = "stdout"; 207 } 208 else 209 if ((outfp = fopen(outfilename, "w")) == (FILE *) NULL) 210 { 211 error(-1, "couldn't open '%s' for output", outfilename); 212 exit(1); 213 } 212 } else if ((outfp = fopen(outfilename, "w")) == (FILE *) NULL) { 213 error(-1, "couldn't open '%s' for output", outfilename); 214 exit(1); 215 } 214 216 215 217 /* 216 218 * Now process the input files (or stdin, if none specified) 217 219 */ 218 219 if (argv[optind] == (char *) NULL) /* just stdin */ 220 if (argc == optind) /* just stdin */ 220 221 exit(unhex(stdin, "stdin", outfp, outfilename)); 221 222 else 222 for (; (optarg = argv[optind]); optind++)223 {224 if (STREQ(optarg, "-")) 223 for (; optind < argc ; optind++) { 224 optarg = argv[optind]; 225 if (STREQ(optarg, "-")) { 225 226 rc += unhex(stdin, "stdin", outfp, outfilename); 226 else 227 { 228 if ((infp = fopen(optarg, "r")) == (FILE *) NULL) 229 { 227 } else { 228 if ((infp = fopen(optarg, "r")) == (FILE *) NULL) { 230 229 error(-1, "couldn't open '%s' for input", optarg); 231 230 exit(1); 232 231 } 233 232 rc += unhex(infp, optarg, outfp, outfilename); 233 fclose(infp); 234 234 } 235 235 } 236 236 237 fclose(outfp); 237 238 return(rc); 238 239 } … … 261 262 */ 262 263 263 if (FFfill) 264 { 264 if (FFfill) { 265 265 (void) fseek(ofp, 0, 0); 266 266 for (c = FFfill; c > 0; c--) … … 272 272 */ 273 273 274 if ((c = getc(ifp)) != EOF) 275 { 274 if ((c = getc(ifp)) != EOF) { 276 275 ungetc(c, ifp); 277 switch(c) 278 { 276 switch(c) { 279 277 case 'S': 280 278 convert_S_records(ifp, inm, ofp, onm); … … 293 291 { 294 292 char tmp[2]; 295 tmp[0] = c; tmp[1] = 0; 293 tmp[0] = (char) (c & 0x7f); 294 tmp[1] = 0; 296 295 badformat(tmp, inm, BADFMT); 297 296 } … … 318 317 int c; 319 318 int rectype; /* record type */ 320 intlen; /* data length of current line */319 long len; /* data length of current line */ 321 320 u32 addr; 322 321 u32 base_address = 0; 323 322 bool endrecord = FALSE; 324 323 buffer_rec tb; 325 326 while ( ! endrecord && (fgets(buff, sizeof(buff), ifp))) 327 {324 long getBytesStatus; 325 326 while ( !endrecord && (fgets(buff, sizeof(buff), ifp)) ) { 328 327 p = &buff[0]; 329 328 330 if (p[strlen(p)-1] == '\n') /* get rid of newline */ 331 p[strlen(p)-1] = '\0'; 332 333 if (p[strlen(p)-1] == '\r') /* get rid of any CR */ 334 p[strlen(p)-1] = '\0'; 329 fix_string_from_gets(p, sizeof(buff)); 335 330 336 331 tb.dl_count = 0; … … 343 338 badformat(buff, inm, BADLEN); 344 339 345 if (( addr= get2bytes(&p)) == -1L) /* record addr */340 if ((getBytesStatus = get2bytes(&p)) == -1L) /* record addr */ 346 341 badformat(buff, inm, BADADDR); 342 addr = (u32) getBytesStatus; 347 343 348 344 rectype = getbyte(&p); … … 350 346 cksum = len + B0(addr) + B1(addr) + rectype; 351 347 352 switch (rectype) 353 { 348 switch (rectype) { 354 349 case 0x00: /* normal data record */ 355 tb.dl_destaddr = base_address + addr;350 tb.dl_destaddr = (u32) base_address + addr; 356 351 while (len--) 357 352 { … … 370 365 371 366 case 0x02: /* new base */ 372 if ((base_address = get2bytes(&p)) == -1L) 367 { 368 long blong; 369 if ((blong = get2bytes(&p)) == -1L) 373 370 badformat(buff, inm, BADBASE); 371 base_address = (u32) blong; 374 372 cksum += B0(base_address) + B1(base_address); 375 373 base_address <<= 4; 376 374 break; 377 375 } 378 376 case 0x03: /* seg/off execution start address */ 379 377 { 380 u32seg, off;378 long seg, off; 381 379 382 380 seg = get2bytes(&p); … … 424 422 int incksum; 425 423 int c; 426 intlen; /* data length of current line */424 long len; /* data length of current line */ 427 425 int rectype; /* record type */ 428 u32addr;426 long addr; 429 427 bool endrecord = FALSE; 430 428 buffer_rec tb; 431 429 432 while ( ! endrecord && (fgets(buff, sizeof(buff), ifp))) 433 { 430 while ( !endrecord && (fgets(buff, sizeof(buff), ifp)) ) { 434 431 p = &buff[0]; 435 432 436 if (p[strlen(p)-1] == '\n') /* get rid of newline */ 437 p[strlen(p)-1] = '\0'; 438 439 if (p[strlen(p)-1] == '\r') /* get rid of any CR */ 440 p[strlen(p)-1] = '\0'; 433 fix_string_from_gets(p, sizeof(buff)); 441 434 442 435 tb.dl_count = 0; … … 453 446 cksum = len; 454 447 455 switch (rectype) 456 { 448 switch (rectype) { 457 449 case 0x00: /* comment field, ignored */ 458 450 goto write_it; … … 477 469 cksum += B0(addr) + B1(addr) + B2(addr) + B3(addr); 478 470 479 tb.dl_destaddr = addr; 480 while (len--) 481 { 471 tb.dl_destaddr = (u32) addr; 472 while (len--) { 482 473 if ((c = getbyte(&p)) == -1) 483 474 badformat(buff, inm, BADDATA); … … 544 535 buffer_rec tb; 545 536 546 while ( ! endrecord && (fgets(buff, sizeof(buff), ifp))) 547 { 537 while ( ! endrecord && (fgets(buff, sizeof(buff), ifp))) { 548 538 p = &buff[0]; 549 if (p[strlen(p)-1] == '\n') /* get rid of newline */ 550 p[strlen(p)-1] = '\0'; 551 552 if (p[strlen(p)-1] == '\r') /* get rid of any CR */ 553 p[strlen(p)-1] = '\0'; 539 fix_string_from_gets(p, sizeof(buff)); 554 540 555 541 tb.dl_count = 0; 556 542 557 543 eol = FALSE; 558 while ( ! eol && ! endrecord) 559 { 560 switch (*p++) 561 { 544 while ( ! eol && ! endrecord) { 545 switch (*p++) { 562 546 case '9': 563 547 if (tb.dl_count) 564 548 write_record(&tb, ofp); 565 tb.dl_destaddr = get2bytes(&p);549 tb.dl_destaddr = (u32) get2bytes(&p); 566 550 break; 567 551 568 552 case 'B': 569 553 c = getbyte(&p); 554 assert( c != -1 ); 570 555 filesum += c; 571 556 tb.dl_buf[tb.dl_count++] = c; 557 572 558 c = getbyte(&p); 559 assert( c != -1 ); 573 560 filesum += c; 574 561 tb.dl_buf[tb.dl_count++] = c; … … 597 584 FILE *fp) 598 585 { 599 if ( ! linear) 600 { 586 if ( ! linear) { 601 587 if (tb->dl_destaddr < base) 602 588 error(ERR_FATAL, "record at address 0x%x precedes base of 0x%x", … … 616 602 617 603 **p = toupper(**p); 618 switch (**p) 619 { 604 switch (**p) { 620 605 case '0': case '1': case '2': case '3': case '4': 621 606 case '5': case '6': case '7': case '8': case '9': … … 652 637 int n) 653 638 { 654 intt;639 long t; 655 640 u32 val = 0; 656 641 657 while (n--) 658 { 642 while (n--) { 659 643 if ((t = getbyte(p)) == -1) 660 644 return(-1L); 661 645 val <<= 8; 662 val += t;646 val += (u32) t; 663 647 } 664 648 … … 671 655 char *msg) 672 656 { 673 if (s[strlen(s)-1] == '\n') /* get rid of newline */ 657 if ( *s != '\0' ) { 658 if (s[strlen(s)-1] == '\n') /* get rid of newline */ 674 659 s[strlen(s)-1] = '\0'; 660 } 675 661 error(0, "line '%s'::\n\tfrom file '%s'; %s", s, fname, msg); 676 662 exit(1); … … 720 706 (void) fflush(stderr); 721 707 722 if (error_flag & (ERR_FATAL | ERR_ABORT)) 723 { 724 if (error_flag & ERR_FATAL) 725 { 708 if (error_flag & (ERR_FATAL | ERR_ABORT)) { 709 if (error_flag & ERR_FATAL) { 726 710 error(0, "fatal error, exiting"); 727 711 exit(local_errno ? local_errno : 1); 728 } 729 else 730 { 712 } else { 731 713 error(0, "fatal error, aborting"); 732 714 abort(); … … 734 716 } 735 717 } 718 719 void fix_string_from_gets(char *s, size_t max) 720 { 721 size_t len; 722 assert( s ); 723 724 if ( *s == '\0' ) 725 return; 726 727 len = strnlen( s, max ); 728 729 if ( s[len - 1] == '\n') /* get rid of newline */ 730 s[len - 1] = '\0'; 731 732 if ( s[len - 1] == '\r') /* get rid of any CR */ 733 s[len - 1] = '\0'; 734 735 }
Note: See TracChangeset
for help on using the changeset viewer.