Sunteți pe pagina 1din 3

* * * * * * * * *

program bin2hex Copyright 2005, 1999, Kevin G. Rhoads. All Rights Reserved.

Permission for use and distribution in accordance with GNU General Public License 2.0 or later is granted. Source is F77 with MS/DVF extensions. integer*1 abyte(16) character*1 a_char(16) character*2 twochar(16),crlf character*127 arg,outfile character drive*1,path*64,file*8,ext*3 integer*4 nargs,argstat,offset integer*2 curarg,i,j logical*2 cmdline,endflag external nargs,getarg,fnovr

*--------print print print print print *,'Copyright 2005, Kevin G. Rhoads. All Rights Reserved. ' *,' ' *,'Permission for use and distribution in accordance with ' *,'GNU General Public License 2.0 or later is granted. ' *,' '

curarg = 1 cmdline = (nargs().gt.1) * change crlf to match system definition, what follows is right * for MS-DOS crlf = char(13)//char(10) *-------------------------------MAIN LOOP over file names 9000 continue if (cmdline) then call getarg(curarg,arg,argstat) print *,' arg is ',arg arg = arg(1:len_trim(arg)) print *,' Trimmed arg is ',arg curarg = curarg + 1 if ( curarg.gt.nargs() ) stop ' Bye - out of arguments' else stop ' Bye ' endif

* *

*---offset = 0 open (unit=10,file=arg,status='old',form='binary',err=9000) drive = ' ' path = ' ' file = ' '

ext = 'HEX' call fnovr(arg,outfile,drive,path,file,ext) open (unit=11,file=outfile,status='unknown',form='formatted', & err=9003) * print *,'-------------------------------------------------------' print *,'Doing file ',arg(1:len_trim(arg)) print *,'Doing file ',arg write (*,*) ' '

* * Use following for DVF command line build initial alignment, * that there are other problems with builb via FL32 compatibility * driver * write (*,'(a1\)') ' ' *-------------------------------MINOR LOOP over bytes in file 9002 continue * read up to 16 bytes, detect end of file j = 0 endflag = .true. do 1 i = 1,16 read (10,end=9001,err=9001) abyte(i) j = i 1 continue endflag = .false. 9001 continue * if read returned bytes, process them if (j.gt.0) then do 2 i = 1,j * not attempting to print control chars (ascii < 32) * * alternate "if" for designating over 126 as unprintable also * if (abyte(i).ge.32.and.abyte(i).lt.127) then if (abyte(i).ge.32) then a_char(i) = char(abyte(i)) else * using ~ for unprintables a_char(i) = '~' endif * use z2.2 for DVF and z2 for MS Fortran 5.1 * write (twochar(i),'(z2.2)') abyte(i) write (twochar(i),'(z2)') abyte(i) 2 continue

* blank out unused on last partial line, if such do 3 i = j+1,16 a_char(i) = ' ' twochar(i) = ' ' 3 continue * * write to HEX, set crlf to line terminator of your preference write (11,7001)offset,(twochar(i),i=1,16),(a_char(i),i=1,16), & crlf endif

offset = offset + j if (.not. endflag) goto 9002 *---9003 continue close (unit=11,status='keep',err=9004) 9004 continue close (unit=11,status='keep',err=9005) 9005 continue if ( curarg.lt.nargs() ) goto 9000 stop ' Bye' * Uncomment one of the formats -- the first gives decimal offsets * the second gives Hex offsets, your choice. In the second group * there is no blank separator in the character portion on the right *with 7001 *7001 *w/o *7001 *7001 blank format format blank format format end (1x,i8.8,3x,7(a2,1x),a2,'-',8(a2,1x),' |',8a1,' ',8a1,a2\) (1x,z8.8,3x,7(a2,1x),a2,'-',8(a2,1x),' |',8a1,' ',8a1,a2\) (1x,i8.8,3x,7(a2,1x),a2,'-',8(a2,1x),' |',8a1,8a1,a2\) (1x,z8.8,3x,7(a2,1x),a2,'-',8(a2,1x),' |',8a1,8a1,a2\)

S-ar putea să vă placă și