dos33fs: whitespace cleanup

This commit is contained in:
Vince Weaver 2018-10-10 13:26:31 -04:00
parent fa718b2451
commit 558c454957

View File

@ -972,103 +972,103 @@ got_a_dentry:
/* load a file. fts=entry/track/sector */ /* load a file. fts=entry/track/sector */
static int dos33_load_file(int fd,int fts,char *filename) { static int dos33_load_file(int fd,int fts,char *filename) {
int output_fd; int output_fd;
int catalog_file,catalog_track,catalog_sector; int catalog_file,catalog_track,catalog_sector;
int file_type,file_size=-1,tsl_track,tsl_sector,data_t,data_s; int file_type,file_size=-1,tsl_track,tsl_sector,data_t,data_s;
unsigned char data_sector[BYTES_PER_SECTOR]; unsigned char data_sector[BYTES_PER_SECTOR];
int tsl_pointer=0,output_pointer=0; int tsl_pointer=0,output_pointer=0;
int result; int result;
/* Fix me! Warn if overwriting file! */ /* FIXME! Warn if overwriting file! */
output_fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666); output_fd=open(filename,O_WRONLY|O_CREAT|O_TRUNC,0666);
if (output_fd<0) { if (output_fd<0) {
fprintf(stderr,"Error! could not open %s for local save\n",filename); fprintf(stderr,"Error! could not open %s for local save\n",
return -1; filename);
} return -1;
}
catalog_file=fts>>16; catalog_file=fts>>16;
catalog_track=(fts>>8)&0xff; catalog_track=(fts>>8)&0xff;
catalog_sector=(fts&0xff); catalog_sector=(fts&0xff);
/* Read in Catalog Sector */ /* Read in Catalog Sector */
lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET); lseek(fd,DISK_OFFSET(catalog_track,catalog_sector),SEEK_SET);
result=read(fd,sector_buffer,BYTES_PER_SECTOR); result=read(fd,sector_buffer,BYTES_PER_SECTOR);
tsl_track=sector_buffer[CATALOG_FILE_LIST+ tsl_track=sector_buffer[CATALOG_FILE_LIST+
(catalog_file*CATALOG_ENTRY_SIZE)+FILE_TS_LIST_T]; (catalog_file*CATALOG_ENTRY_SIZE)+FILE_TS_LIST_T];
tsl_sector=sector_buffer[CATALOG_FILE_LIST+ tsl_sector=sector_buffer[CATALOG_FILE_LIST+
(catalog_file*CATALOG_ENTRY_SIZE)+FILE_TS_LIST_S]; (catalog_file*CATALOG_ENTRY_SIZE)+FILE_TS_LIST_S];
file_type=dos33_file_type(sector_buffer[CATALOG_FILE_LIST+ file_type=dos33_file_type(sector_buffer[CATALOG_FILE_LIST+
(catalog_file*CATALOG_ENTRY_SIZE) (catalog_file*CATALOG_ENTRY_SIZE)+FILE_TYPE]);
+FILE_TYPE]);
// printf("file_type: %c\n",file_type); // printf("file_type: %c\n",file_type);
keep_saving: keep_saving:
/* Read in TSL Sector */ /* Read in TSL Sector */
lseek(fd,DISK_OFFSET(tsl_track,tsl_sector),SEEK_SET); lseek(fd,DISK_OFFSET(tsl_track,tsl_sector),SEEK_SET);
result=read(fd,sector_buffer,BYTES_PER_SECTOR); result=read(fd,sector_buffer,BYTES_PER_SECTOR);
tsl_pointer=0; tsl_pointer=0;
/* check each track/sector pair in the list */ /* check each track/sector pair in the list */
while(tsl_pointer<TSL_MAX_NUMBER) { while(tsl_pointer<TSL_MAX_NUMBER) {
/* get the t/s value */ /* get the t/s value */
data_t=sector_buffer[TSL_LIST+(tsl_pointer*TSL_ENTRY_SIZE)]; data_t=sector_buffer[TSL_LIST+(tsl_pointer*TSL_ENTRY_SIZE)];
data_s=sector_buffer[TSL_LIST+(tsl_pointer*TSL_ENTRY_SIZE)+1]; data_s=sector_buffer[TSL_LIST+(tsl_pointer*TSL_ENTRY_SIZE)+1];
if ((data_s==0) && (data_t==0)) { if ((data_s==0) && (data_t==0)) {
/* empty */ /* empty */
} }
else { else {
lseek(fd,DISK_OFFSET(data_t,data_s),SEEK_SET); lseek(fd,DISK_OFFSET(data_t,data_s),SEEK_SET);
result=read(fd,&data_sector,BYTES_PER_SECTOR); result=read(fd,&data_sector,BYTES_PER_SECTOR);
/* some file formats have the size in the first sector */ /* some file formats have the size in the first sector */
/* so cheat and get real file size from file itself */ /* so cheat and get real file size from file itself */
if (output_pointer==0) { if (output_pointer==0) {
switch(file_type) { switch(file_type) {
case 'A': case 'A':
case 'I': case 'I':
file_size=data_sector[0]+(data_sector[1]<<8)+2; file_size=data_sector[0]+(data_sector[1]<<8)+2;
break; break;
case 'B': case 'B':
file_size=data_sector[2]+(data_sector[3]<<8)+4; file_size=data_sector[2]+(data_sector[3]<<8)+4;
break; break;
default: default:
file_size=-1; file_size=-1;
} }
} }
/* write the block read in out to the output file */ /* write the block read in out to the output file */
lseek(output_fd,output_pointer*BYTES_PER_SECTOR,SEEK_SET); lseek(output_fd,output_pointer*BYTES_PER_SECTOR,SEEK_SET);
result=write(output_fd,&data_sector,BYTES_PER_SECTOR); result=write(output_fd,&data_sector,BYTES_PER_SECTOR);
} }
output_pointer++; output_pointer++;
tsl_pointer++; tsl_pointer++;
} }
/* finished with TSL sector, see if we have another */ /* finished with TSL sector, see if we have another */
tsl_track=sector_buffer[TSL_NEXT_TRACK]; tsl_track=sector_buffer[TSL_NEXT_TRACK];
tsl_sector=sector_buffer[TSL_NEXT_SECTOR]; tsl_sector=sector_buffer[TSL_NEXT_SECTOR];
// printf("Next track/sector=%d/%d op=%d\n",tsl_track,tsl_sector, // printf("Next track/sector=%d/%d op=%d\n",tsl_track,tsl_sector,
// output_pointer*BYTES_PER_SECTOR); // output_pointer*BYTES_PER_SECTOR);
if ((tsl_track==0) && (tsl_sector==0)) { if ((tsl_track==0) && (tsl_sector==0)) {
} }
else goto keep_saving; else goto keep_saving;
/* Correct the file size */ /* Correct the file size */
if (file_size>=0) { if (file_size>=0) {
// printf("Truncating file size to %d\n",file_size); // printf("Truncating file size to %d\n",file_size);
result=ftruncate(output_fd,file_size); result=ftruncate(output_fd,file_size);
} }
if (result<0) fprintf(stderr,"Error on I/O\n"); if (result<0) fprintf(stderr,"Error on I/O\n");
return 0; return 0;
} }