char *read_dir(char *p) /* get next file name from opened directory, NULL if no more entries */ { struct Dir *d = (struct Dir *)p; if (d->err == E_OK) { strncpy(d->name,d->dta.d_fname,MAX_PATH_LEN); d->err = Fsnext(); return d->name; } return NULL; }
void GetLDVLanguages(LDV_MODULE *ldv, char *buf) { DTA dta, *old_dta ; char name[PATH_MAX] ; char ini_name[PATH_MAX] ; char ldv_nameextini[50] ; char *dot ; int ret ; if ( ldv->FileName ) strcpy( ldv_nameextini, ldv->FileName ) ; else return ; dot = strrchr( ldv_nameextini, '.' ) ; if ( dot ) { *dot = 0 ; strcat( ldv_nameextini, ".INI" ) ; } sprintf( ini_name, "%s\\%s", config.path_ldv, ldv_nameextini ) ; if ( FileExist( ini_name ) ) sprintf( buf, "English " ) ; else buf[0] = 0 ; sprintf( name, "%s\\*.*", config.path_ldv ) ; old_dta = Fgetdta() ; Fsetdta( &dta ) ; ret = Fsfirst( name, FA_SUBDIR ) ; while ( ret == 0 ) { if ( ( dta.d_fname[0] != '.' ) && ( dta.d_attrib & FA_SUBDIR ) ) { sprintf( ini_name, "%s\\%s\\%s", config.path_ldv, dta.d_fname, ldv_nameextini ) ; if ( FileExist( ini_name ) ) { strlwr( &dta.d_fname[1] ) ; strcat( buf, dta.d_fname ) ; strcat( buf, " " ) ; } } ret = Fsnext() ; } Fsetdta( old_dta ) ; }
/** * Process all files in the directory. * * @param dirpath path to directory to traverse. * @param callback function called back for each file found. * @return True if and only if everything was ok. */ bool ReadDir_ProcessAllFiles(const char * dirpath, bool (*callback)(const char *name, const char *path, uint32 size)) { _DTA dta; char searchpath[256]; char path[256]; long r; snprintf(searchpath, sizeof(searchpath), "%s*.*", dirpath); Fsetdta(&dta); if(Fsfirst(searchpath, FA_RDONLY | FA_HIDDEN) != 0) { return false; } else do { /* Skip directories */ if (dta.dta_attribute & FA_DIR) continue; snprintf(path, sizeof(path), "%s%s", dirpath, dta.dta_name); Debug("Found file %-17s %7ld bytes\n", path, dta.dta_size); if (!callback(dta.dta_name, path, (uint32)dta.dta_size)) { return false; } } while((r = Fsnext()) == 0); return (r == -ENMFILES); }
int countFoundItems(char *dta, char *fspec, WORD attribs, BYTE startNotCont, int stopAfter) { int res, found = 0; if(startNotCont) { // on start clean DTA memset(dta, 0, 44); } Fsetdta(dta); // set DTA if(startNotCont) { // if should start search, not continue res = Fsfirst(fspec, attribs); if(res) { // file not found? return 0; } found++; } while(1) { if(found == stopAfter) { // if we found all we needed, stop return found; } res = Fsnext(); if(res) { // if file not found, quit return found; } found++; } return found; // this should never happen }
/******************************************************************************* BALAYAGE D'UN DOSSIER *******************************************************************************/ static int Balaie_Path(char *directory,int wx,int wy,int ww,int wh) { char old_path[FILENAME_MAX]; int old_drv; char pfn[FILENAME_MAX]; DTA *mydta; int i,Fin=0; int cnt,pos; /* long count;*/ t2=0; old_drv=Dgetdrv(); Dgetpath(old_path,1+old_drv); mydta=Fgetdta(); if (directory[1]==':') Dsetdrv((int)directory[1]-65); strcpy(pfn,directory); strcat(pfn,"\\*.*"); if (glb.opt.sl_rec) i=Fsfirst(pfn,FA_READONLY|FA_SUBDIR|FA_ARCHIVE); else i=Fsfirst(pfn,FA_READONLY|FA_ARCHIVE); pos=0; loop1: cnt=0; while (!i) { cnt+=1; if (mydta->d_fname[0]!='.' && cnt>pos) { strcpy(pfn,directory); strcat(pfn,"\\"); strcat(pfn,mydta->d_fname); if (mydta->d_attrib&FA_SUBDIR) { pos=cnt; if (Balaie_Path(pfn,wx,wy,ww,wh)) return TRUE; strcpy(pfn,directory); strcat(pfn,"\\*.*"); if (glb.opt.sl_rec) i=Fsfirst(pfn,FA_READONLY|FA_SUBDIR|FA_ARCHIVE); else i=Fsfirst(pfn,FA_READONLY|FA_ARCHIVE); goto loop1; } } if (Kbshift(-1)!=shift) return TRUE; i=Fsnext(); /* if (i!=0) { time(&t1); if(glb.opt.sl_pause) { count=1000L*max( 0 , (long)glb.opt.sl_ptime - (t1-t2) ); evnt_timer( (int)(count&0xFFFFUL),(int)(count>>16) ); } else count=0; } */ } strcpy(pfn,directory); strcat(pfn,"\\"); strcat(pfn,glb.opt.sl_name); if (glb.opt.sl_rec) i=Fsfirst(pfn,FA_READONLY|FA_SUBDIR|FA_ARCHIVE); else i=Fsfirst(pfn,FA_READONLY|FA_ARCHIVE); pos=0; cnt=0; while (!i) { cnt+=1; if (mydta->d_fname[0]!='.' && cnt>pos) { strcpy(pfn,directory); strcat(pfn,"\\"); strcat(pfn,mydta->d_fname); if (!(mydta->d_attrib&FA_SUBDIR)) affiche(pfn,wx,wy,ww,wh); } if (Kbshift(-1)!=shift) return TRUE; i=Fsnext(); /* if (i!=0) { time(&t1); if(glb.opt.sl_pause) count=1000L*max( 0 , (long)glb.opt.sl_ptime - (t1-t2) ); else count=0; evnt_timer( (int)(count&0xFFFFUL),(int)(count>>16) ); } */ } Dsetdrv(old_drv); Dsetpath(old_path); return Fin; }
WORD countrec( VOID ) { /* char *saved; */ DMABUFFER *dumb, *saved; REG int retmsg; dumb = (DMABUFFER *)malloc( (LONG)sizeof(DMABUFFER) ); if ( !dumb ) { do1_alert( STFO8DEE ); return( FALSE ); } retmsg = TRUE; saved = (DMABUFFER *)Fgetdta(); /* save the current dta */ Fsetdta( dumb ); if (!Fsfirst(curall, 0x37)) { do { if (dumb->d_fname[0] != HOME) { if (SUBDIR & dumb->d_fattr) { /* setpath to one more down */ if (Dsetpath(dumb->d_fname)) { retmsg = FALSE; goto endrec; } numdirs++; if ( ++f_level > COPYMAXDEPTH ) { do1_alert( STFO8DEE ); retmsg = FALSE; goto endrec; } if (!countrec()) /* to the recursion setpath to one back */ { retmsg = FALSE; goto endrec; } f_level--; if (Dsetpath(baklvl)) { retmsg = FALSE; goto endrec; } } else { numfiles++; /* add up the file count and size */ tolsize += dumb->d_fsize; } } } while (!Fsnext()); } endrec: Fsetdta( saved ); /* reset the dta */ free( dumb ); return(retmsg); }
int doact( VOID ) { /* char *saved; */ DMABUFFER *dumb, * saved; REG int ret, retmsg; int error; if ( f_level >= ( COPYMAXDEPTH + 1 ) ) { act_1: do1_alert( STFO8DEE ); return( FALSE ); } /* changed CHAR * to DMABUFFER * in expression below - JTT */ if ( !( dumb = (DMABUFFER *)malloc( (LONG)sizeof( DMABUFFER ) ) ) ) goto act_1; f_level++; retmsg = TRUE; saved = (DMABUFFER *)Fgetdta(); Fsetdta( dumb ); strcat(getall, fixsrc); if ( !( error = Fsfirst(fixsrc, 0x37) ) ) { do { if ( !ch_undo( ) || f_cancel ) /* user want to abort */ { f_abort = 1; retmsg = FALSE; goto mvend; } if (dumb->d_fname[0] != HOME) { if (SUBDIR & dumb->d_fattr) { chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); /* add a dir into the path */ strcat(bckslsh, fixsrc); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ strcat(dumb->d_fname, fixdst); } else goto dorec; updatbox(dumb->d_fname); rechkd1: /* update check the dir existing or not */ switch( chkdf( dumb->d_fname, CPDIR ) ) { case QUIT: f_abort = 1; retmsg = FALSE; goto mvend; case SKIP: backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ retmsg = TRUE; continue; case FALSE: goto mvend; case CHECK: goto rechkd1; case OK: recrtd: if (Dcreate(fixdst)) { if ( write_save ) goto kk_1; switch( fill_string( fixdst, CNTCRTDR ) ) { case 1: /* skip */ backdir(fixsrc); backdir(fixdst); updatnum(NUMDIR, --numdirs); srclen -= FILE_LEN; /* subtract the add lenth */ dstlen -= FILE_LEN; /* subtract the add lenth */ continue; case 2: /* retry */ goto recrtd; default: /* quit */ f_abort = 1; retmsg = FALSE; goto mvend; }/* switch */ }/* if recrtd */ break; } kk_1: updatnum(NUMDIR, --numdirs); strcat(bckslsh, fixdst); dorec: if (!doact()) /* do the recursion */ { retmsg = FALSE; goto mvend; } if (opcode == OP_COPY) goto clndir; rmstarb(fixsrc); /* after call, -> c:\d1\ */ if (opcode == OP_DELETE) { getlastpath(filestr, fixsrc); updatbox(filestr); } remvd: if (Ddelete(fixsrc)) { /* delete a dir */ if ( ( ret = fill_string( fixsrc, CNTDELD ) ) == 2 ) goto remvd; /* retry */ else if (ret == 3) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else /* No error */ upfdesk( fixsrc, (BYTE*)0 ); clndir: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMDIR, --numdirs); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } else { getlastpath(filestr, fixdst); updatname(CPDIR, filestr); /* update the dir */ updatname( CPFILE, dumb->d_fname ); /* update the file */ chkbuf(srclen, srcbuf, &fixsrc); /* check buf size */ addfile(fixsrc, dumb->d_fname); if (opcode != OP_DELETE) { chkbuf(dstlen, dstbuf, &fixdst); /* check buf size */ addfile(fixdst, dumb->d_fname); rename = 0; if (!(retmsg = wrfile(dumb->d_fname))) goto mvend; if ((rename) || (retmsg == SKIP)) goto clnfile; } if (opcode == OP_COPY) goto clnfile; remvf: if (ret = (WORD)(Fdelete(fixsrc))) /* rm the file from source */ { /* seek error or drive not ready */ /* if ((ret == E_SEEK) || (ret == EDRVNR)) { retmsg = FALSE; goto mvend; } */ /* retry */ if ( ( ret = fill_string( fixsrc, CNTDELF ) ) == 2 ) goto remvf; else if ( ret == 3 ) { /* abort */ f_abort = 1; retmsg = FALSE; goto mvend; } } else upfdesk( fixsrc, (BYTE*)0 ); clnfile: backdir(fixsrc); /* back one dir */ srclen -= FILE_LEN; /* subtract the add lenth */ if (opcode == OP_DELETE) updatnum(NUMFILE, --numfiles); else { backdir(fixdst); /* back one dir */ dstlen -= FILE_LEN; /* subtract the add lenth */ } } } } while (!Fsnext()); } else { if ( error != EFILNF ) /* if not file not found */ retmsg = FALSE; /* then return error */ } mvend: Fsetdta( saved ); f_level--; free( dumb ); return( retmsg ); }
/* GetCDrivers() * ==================================================================== * Go thru the list of .sys files and try to load them. * Those that we can load, get the header and see if they are of the * new driver type. Get the filenames of those that are printer drivers * and store them in cdriver. Store their index into the driver array * into our cdriver array position. */ void GetCDrivers( void ) { DTA thedta, *saved; int fd; int *DataPtr; long EndIndex; int error; saved = Fgetdta(); Fsetdta( &thedta ); cdriver_count = 0; get_bitpath(); strcpy( FPath, epath ); strcat( FPath, "\\*.SYS"); error = Fsfirst( FPath, 0 ); /* Normal file search for 1st file */ if( error != E_OK ) /* No such files! */ { return; } do { sprintf( line_buf, "%s\\%s", epath, thedta.d_fname ); DataBuf = calloc( 1, thedta.d_length * 2L ); if( DataBuf ) { fd = Fopen( line_buf, 0 ); if( fd > 0 ) { Buffer = ( long )DataBuf; Buffer = ( Buffer + 15L ) & 0xFFFFFFF0L; DataHdr = ( int *)Buffer; Fread( fd, thedta.d_length, DataHdr ); Fclose( fd ); EndIndex = thedta.d_length; DataPtr = FindString( DataHdr, DataHdr + EndIndex - 8 ); if( DataPtr ) /* Look only for new drivers with headers*/ { hdr = ( HEADER *)DataPtr; hdr_buffer = ( HEADER )*hdr; hdr = &hdr_buffer; /* want only those drivers with real page sizes */ if( hdr->config_map & 0x3E ) { /* then get the name...*/ strcpy( cdrivers[ cdriver_count ], hdr->fname ); strcpy( drivers[ cdriver_count ], thedta.d_fname ); cdriver_count++; } } } free( DataBuf ); } else { /* memory error - break out of loop and exit routine */ form_alert( 1, alert4 ); break; } } while ( ( Fsnext() == E_OK ) && ( cdriver_count < MAX_DRIVERS ) ); SortCDriverNames(); Fsetdta( saved ); }
copy_dir () /* source und dest sind global; bei Fehler: return (1) */ { int source_len, dest_len, fd_source, fd_dest, error; char dta[44]; long old_dta, fail, size, count; error=0; source_len=strlen(source); dest_len=strlen(dest); old_dta=Fgetdta(); Fsetdta(dta); strcat(source,"\\*.*"); fail=Fsfirst(source,16); source[source_len]=0; while (!fail) { strcat(source,"\\"); strcat(source,dta+30); strcat(dest,"\\"); strcat(dest,dta+30); if (dta[21]==16) /* Directory */ { if (strcmp(dta+30,".")&&strcmp(dta+30,"..")) if (Dcreate(dest)) { printf("Ordner %s l„žt sich nicht anlegen.\n",dest); error=1; } else error|=copy_dir(source,dest); } else /* File */ { printf("%s nach %s\n",source,dest); if ((fd_source=Fopen(source,0))<0) { printf("Datei %s l„žt sich nicht ”ffnen.\n",source); error=1; } else if ((fd_dest=Fcreate(dest,dta[21]&~1))<0) { printf("Datei %s l„žt sich nicht einrichten.\n",dest); error=1; } else { size=*(long*)(dta+26); while (size) { count=(size<buf_size)?size:buf_size; size-=count; if (Fread(fd_source,count,buffer)!=count) { printf("Fehler beim Lesen von %s .\n",source); error=1; break; } if (Fwrite(fd_dest,count,buffer)!=count) { printf("Fehler beim Schreiben von %s .\n",dest); error=1; break; } } Fclose(fd_source); Fclose(fd_dest); fd_dest=Fopen(dest,1); Fdatime(fd_dest,dta+22,1); Fclose(fd_dest); } } source[source_len]=0; dest[dest_len]=0; fail=Fsnext(); } if (fail!=-49l) { printf("Ordner %s nicht gefunden.\n",source); error=1; } Fsetdta(old_dta); return (error); }
long x_xreaddir(XDIR *dir, char *buffer, int len, XATTR *attrib) { #if _MINT_ if (mint) /* HR 151102 */ { if (dir->type) { /* * DOS file system. */ int error; if (dir->data.gdata.first != 0) { char *fspec; if ((fspec = x_makepath(dir->path, "*.*", &error)) != NULL) { #if USE_gemdos error = xerror((int) gemdos(78, fspec, 0x37)); #else error = xerror(Fsfirst(fspec, 0x37)); #endif free(fspec); dir->data.gdata.first = 0; } } else #if USE_gemdos error = xerror((int) gemdos(79)); #else error = xerror(Fsnext()); #endif if (error == 0) { if (strlen(dir->data.gdata.dta.d_fname) + 1 > len) error = EFNTL; else { strupr(dir->data.gdata.dta.d_fname); /* HR 151102: arrogant MiNT tampering with filenames. */ strncpy(buffer, dir->data.gdata.dta.d_fname, len); dta_to_xattr(&dir->data.gdata.dta, attrib); } } return (long) error; } else { /* * File system with long filenames. * HR 130203: Use Dxreaddir in stead of Dreaddir, * handle links correctly. */ int h; char str[260]; long error, rep; if ((error = Dxreaddir(len, dir->data.handle, str, (long)attrib, &rep)) == 0) strcpy(buffer, &str[4]); if (error == 0) return error; return (long) xerror((int) error); } } else #endif { int error; if (dir->data.gdata.first != 0) { char *fspec; if ((fspec = x_makepath(dir->path, "*.*", &error)) != NULL) { #if USE_gemdos error = xerror((int) gemdos(78, fspec, 0x37)); #else error = xerror(Fsfirst(fspec, 0x37)); #endif free(fspec); dir->data.gdata.first = 0; } } else #if USE_gemdos error = xerror((int) gemdos(79)); #else error = xerror(Fsnext()); #endif if (error == 0) { if (strlen(dir->data.gdata.dta.d_fname) + 1 > len) error = EFNTL; else { strncpy(buffer, dir->data.gdata.dta.d_fname, len); dta_to_xattr(&dir->data.gdata.dta, attrib); } } return (long) error; } }
/******************************************************************************* Multi FileSelect FileSelect �volu� permettant de traiter un ensemble de fichiers en une seule passe. S�lection des fichiers avec Selectric; ou � l'aide de joker. On appelle ensuite en boucle la fonction (*call) avec comme unique param�tre le nom complet du fichier. De plus; le joker # permet de remplacer un num�ro de fichier. Par exemple le masque TOTO####.TXT cherchera le fichier TOTO0001.TXT puis les suivants. *******************************************************************************/ int _multifsel(char *pfname,char *pname,char *fname,char *ext,char *title,int cdecl (*call)(char *name)) { DTA *dta; long k,n,m; char path[FILENAME_MAX]; char mask[20]; char *p; int drvold=-1; int is_slct_da,num=0; int i,j=1,Break; p=glb.div.buf; is_slct_da=_slctMoreNames(1,512,glb.div.buf); i=_fselect(pfname,pname,fname,ext,title); if (i) { Break=FALSE; if (is_slct_da) { while (*p && j && !Break) { num+=1; strcpy(path,pname); fname[0]=0; while (*p && *p!=' ') strncat(fname,p++,1L); strcat(path,"\\"); strcat(path,fname); p++; if (call) j=(*call)(path); } } if (num==0) { if (pname[1]==':') { drvold=Dgetdrv(); Dsetdrv((int)pfname[0]-65); } p=strchr(pfname,'#'); if (p) /* Gestion du masque # */ { n=0L; while (*p++=='#') n+=1L; p=strchr(pfname,'#'); /* pfname=C:\TOTO\TITI.EXT\TATA##O.JPG" n=2 */ *p='\0'; strcpy(path,pfname); /* path=C:\TOTO\TITI.EXT\TATA */ sprintf(mask,"%%s%%0%lili%%s",n); /* mask='%s%02li%s' */ m=1L; for (k=0;k<n;k++) m*=10L; for (k=0;k<m;k++) { sprintf(path,mask,pfname,k,&p[n]); if (!_fexist(path,NULL)) k=m; else if (call) j=(*call)(path); if (!j) k=m; } } else if (!Fsfirst(pfname,FA_READONLY+FA_HIDDEN+FA_SYSTEM+FA_ARCHIVE)) { dta=Fgetdta(); do { strcpy(path,pname); strcat(path,"\\"); strcat(path,dta->d_fname); if (call) j=(*call)(path); } while (!Fsnext() && j && !Break); } if (drvold!=-1) Dsetdrv(drvold); } Break=FALSE; } return num; }
static void check_files( const char *file_name ) { int fd; int is_mot; long file_size; int nch; long x; int coff_size, hoff_size; register int i; if (Fsfirst( file_name, 0) == 0) { do { if( (fd = open( dtap->dta_name, 2, 0 )) < 0) { sprintf( errstr, "can't open %s", dtap->dta_name ); perror( errstr ); continue; } /* if */ /* read file header */ if( read(fd, &hdr, sizeof(hdr) ) != sizeof(hdr) ) { sprintf( errstr, "error reading %s", dtap->dta_name ); perror( errstr ); close( fd ); continue; } /* if */ is_mot = (hdr.flags&MOT_FLAG) != 0; if (!is_mot) { /* swap header words and longs */ Swapw(hdr.font_id); Swapw(hdr.size); Swapw(hdr.first_ade); Swapw(hdr.last_ade); Swapw(hdr.top); Swapw(hdr.ascent); Swapw(hdr.half); Swapw(hdr.descent); Swapw(hdr.bottom); Swapw(hdr.max_char_width); Swapw(hdr.max_cell_width); Swapw(hdr.loffset); Swapw(hdr.roffset); Swapw(hdr.thicken); Swapw(hdr.ul_size); Swapw(hdr.flags); Swapl(hdr.hoff_base); Swapl(hdr.coff_base); Swapl(hdr.form_base); Swapw(hdr.form_width); Swapw(hdr.form_height); hdr.flags |= MOT_FLAG; } /* if */ printf( "%s: \"%.32s\" at %d pts, id is %d\n", dtap->dta_name, hdr.name, hdr.size, hdr.font_id ); if( hdr.max_char_width > hdr.max_cell_width ) { printf( "error: max char width is larger than max cell width\n" ); } /* if */ nch = hdr.last_ade - hdr.first_ade + 1; if( nch <= 0 ) printf( "warning: last ADE <= first ADE\n" ); if( hdr.last_ade > 255 ) printf( "warning: last ade is %d\n", hdr.last_ade ); if( hdr.first_ade < 32 ) printf( "warning: first ade is %d\n", hdr.first_ade ); /* read & check char offset tbl */ coff_size = sizeof(int)*(nch+1); if( lseek( fd, hdr.coff_base, SEEK_SET ) > 0 ) { if( read(fd, coff_tbl, coff_size) != coff_size ) { sprintf( errstr, "error reading character offset table in %s", dtap->dta_name ); perror( errstr ); } else { if( !is_mot ) { for( i=0; i<=nch; i++ ) { Swapw(coff_tbl[i]); } /* for */ } /* if */ if( coff_tbl[nch] > (hdr.form_width*8) ) { printf( "error: last char offset extends past form Width\n" ); printf( "offset for last character is %d, formWidth is %d\n", coff_tbl[nch], hdr.form_width*8 ); } else if( coff_tbl[nch]+15 < (hdr.form_width*8) ) { printf( "warning: form Width too large\t" ); printf( "offset for last character is %d, formWidth is %d\n", coff_tbl[nch], hdr.form_width*8 ); } /* if */ if( coff_tbl[0] != 0 ) { printf( "font format error: char offset table must start with zero entry\n" ); } /* if */ for( i=hdr.first_ade; i<=hdr.last_ade; i++ ) { int cell_wid = coff_tbl[i-hdr.first_ade+1] - coff_tbl[i-hdr.first_ade]; if( cell_wid < 0 ) { printf( "font format error: character %c (%d) has -ve width\n", i, i ); } /* if */ if( cell_wid > hdr.max_cell_width ) { printf( "font format error: character %c (%d) has width (%d) greater than max cell width (%d)\n", i, i, cell_wid, hdr.max_cell_width ); } /* if */ } /* for */ } /* if */ } /* if */ file_size = dtap->dta_size; if( hdr.coff_base < sizeof(GFont) ) { printf( "warning: character offset table overlaps header\n" ); } /* if */ if( hdr.form_base < sizeof(GFont) ) { printf( "warning: font data table overlaps header\n" ); } /* if */ if( (hdr.flags&HOR_FLAG) != 0 ) { printf( "this font has a horizontal offset table\n" ); if( hdr.hoff_base < sizeof(GFont) ) { printf( "warning: horizontal offset table overlaps header\n" ); } /* if */ /* read & check char hoffset tbl */ hoff_size = sizeof(int)*nch; if( lseek( fd, hdr.hoff_base, SEEK_SET ) > 0 ) { if( read(fd, hoff_tbl, hoff_size) != hoff_size ) { sprintf( errstr, "error reading horizontal offset table in %s", dtap->dta_name ); perror( errstr ); } else { if( !is_mot ) { for( i=0; i<nch; i++ ) { Swapw(hoff_tbl[i]); } /* for */ } /* if */ for( x = 0, i=hdr.first_ade; i<=hdr.last_ade; i++ ) { x |= hoff_tbl[i-hdr.first_ade]; } /* for */ if( x==0 ) { printf( "warning: horizontal offset table is all zeros\n" ); } /* if */ } /* if */ } /* if */ if( (hdr.coff_base > hdr.form_base) && (hdr.coff_base > hdr.hoff_base) ) { if( hdr.coff_base + coff_size >= file_size ) printf( "warning: character offset table extends beyond end of file\n" "coff_base is %ld\n", hdr.coff_base ); if( hdr.hoff_base > hdr.form_base ) { if( hdr.form_base + (long)hdr.form_width*hdr.form_height > hdr.hoff_base ) printf( "warning: data table extends into horizontal offset table\n" "data table starts at %ld, size is %ld, form width is %d, form height is %d\n", hdr.form_base, (long)hdr.form_width*hdr.form_height, hdr.form_width, hdr.form_height ); } else { if( hdr.hoff_base + hoff_size > hdr.form_base ) printf( "warning: horizontal offset table extends into font data\n" "data table starts at %ld, size is %ld, form width is %d, form height is %d\n", hdr.form_base, (long)hdr.form_width*hdr.form_height, hdr.form_width, hdr.form_height ); } /* if */ } else if( (hdr.form_base > hdr.coff_base) && (hdr.form_base > hdr.hoff_base) ) { if( hdr.form_base + (long)hdr.form_width*hdr.form_height > file_size ) printf( "warning: data table extends beyond end of file\n" "file size is %ld, data table starts at %ld, size is %ld, form width is %d, form height is %d\n", file_size, hdr.form_base, (long)hdr.form_width*hdr.form_height, hdr.form_width, hdr.form_height ); if( hdr.coff_base > hdr.hoff_base ) { if( hdr.coff_base + coff_size > hdr.form_base ) printf( "warning: character offset table extends into font data\n" "coff_base is %ld, length is %d, data starts at %ld\n", hdr.coff_base, coff_size, hdr.form_base ); if( hdr.hoff_base + hoff_size > hdr.coff_base ) printf( "warning: horizontal offset table extends into character offset table\n" "coff_base is %ld, length is %d, data starts at %ld\n", hdr.coff_base, coff_size, hdr.form_base ); } else { /* horizontal offset table follows char offset table */ if( hdr.hoff_base + hoff_size > hdr.form_base ) printf( "warning: horizontal offset table extends into font data\n" "hoff_base is %ld, length is %d, data starts at %ld\n", hdr.hoff_base, hoff_size, hdr.form_base ); if( hdr.coff_base + coff_size > hdr.hoff_base ) printf( "warning: character offset table extends into horizontal offset table\n" "coff_base is %ld, length is %d, hoff_base is %ld\n", hdr.coff_base, coff_size, hdr.hoff_base ); } /* if */ } /* if */ } else { /* no horizontal offset table ... */ if( hdr.coff_base > hdr.form_base ) { if( hdr.coff_base + coff_size >= file_size ) printf( "warning: character offset table extends beyond end of file\n" "coff_base is %ld\n", hdr.coff_base ); if( hdr.form_base + (long)hdr.form_width*hdr.form_height > hdr.coff_base ) printf( "warning: data table extends into character offset table\n" "data table starts at %ld, size is %ld, form width is %d, form height is %d\n", hdr.form_base, (long)hdr.form_width*hdr.form_height, hdr.form_width, hdr.form_height ); } else { if( hdr.form_base + (long)hdr.form_width*hdr.form_height > file_size ) printf( "warning: data table extends beyond end of file\n" "file size is %ld, data table starts at %ld, size is %ld, form width is %d, form height is %d\n", file_size, hdr.form_base, (long)hdr.form_width*hdr.form_height, hdr.form_width, hdr.form_height ); if( hdr.coff_base + coff_size > hdr.form_base ) printf( "warning: character offset table extends into font data\n" "coff_base is %ld, length is %d, data starts at %ld\n", hdr.coff_base, coff_size, hdr.form_base ); } /* if */ } /* if */ close(fd); } while (Fsnext() == 0); } else { printf( "no '%s' font files found\n", file_name ); } /* if */ } /* check_files() */