make_b: clean up whitespace

This commit is contained in:
Vince Weaver 2016-12-08 22:04:19 -05:00
parent 75bfb3c573
commit 2f482f68aa

View File

@ -7,56 +7,56 @@
#include "version.h" #include "version.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
int in_fd,out_fd,offset,write_result;
unsigned char buffer[256]; int in_fd,out_fd,offset,write_result;
int result,file_size;
struct stat file_info;
if (argc!=4) {
printf("MAKE_B version %s\b",VERSION);
printf(" Usage: %s in_file out_file offset\n\n",argv[0]);
printf("\tin_file : input file\n");
printf("\tout_file : output file\n");
printf("\toffset : offset which file should be loaded\n\n");
exit(1);
}
if (stat(argv[1],&file_info)<0) {
printf("Error! %s not found!\n",argv[1]);
exit(2);
}
file_size=(int)file_info.st_size;
if ((in_fd=open(argv[1],O_RDONLY))<0) {
printf("Error opening %s!\n",argv[1]);
exit(3);
}
if ((out_fd=open(argv[2],O_WRONLY|O_CREAT,0666))<0) { unsigned char buffer[256];
printf("Error opening %s\n",argv[2]); int result,file_size;
exit(4);
} struct stat file_info;
offset=strtol(argv[3],NULL,0); if (argc!=4) {
printf("MAKE_B version %s\b",VERSION);
buffer[0]=offset&0xff; printf(" Usage: %s in_file out_file offset\n\n",argv[0]);
buffer[1]=(offset>>8)&0xff; printf("\tin_file : input file\n");
buffer[2]=file_size&0xff; printf("\tout_file : output file\n");
buffer[3]=(file_size>>8)&0xff; printf("\toffset : offset which file should be loaded\n\n");
exit(1);
write_result=write(out_fd,&buffer,4); }
while( (result=read(in_fd,&buffer,256))>0) { if (stat(argv[1],&file_info)<0) {
write_result=write(out_fd,&buffer,result); printf("Error! %s not found!\n",argv[1]);
} exit(2);
}
if (write_result<0) fprintf(stderr,"Error writing\n"); file_size=(int)file_info.st_size;
close(in_fd); if ((in_fd=open(argv[1],O_RDONLY))<0) {
close(out_fd); printf("Error opening %s!\n",argv[1]);
exit(3);
return 0; }
if ((out_fd=open(argv[2],O_WRONLY|O_CREAT,0666))<0) {
printf("Error opening %s\n",argv[2]);
exit(4);
}
offset=strtol(argv[3],NULL,0);
buffer[0]=offset&0xff;
buffer[1]=(offset>>8)&0xff;
buffer[2]=file_size&0xff;
buffer[3]=(file_size>>8)&0xff;
write_result=write(out_fd,&buffer,4);
while( (result=read(in_fd,&buffer,256))>0) {
write_result=write(out_fd,&buffer,result);
}
if (write_result<0) fprintf(stderr,"Error writing\n");
close(in_fd);
close(out_fd);
return 0;
} }