home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR19 / SNIP0693.ZIP / FILEOUT.PRG < prev    next >
Text File  |  1993-03-13  |  3KB  |  138 lines

  1. /***************************************************************************
  2.  
  3.     FILEOUT.PRG
  4.  
  5.     EXAMPLE SYNTAX: CAPFIRST.OBJ CAPFIRST.HEX
  6.  
  7.     FILEOUT takes a file, any file, (OBJ, LIB, EXE, COM) and creates
  8.     an output hex dump file that can be read by FILEIN.PRG to
  9.     recreate the original file.
  10.  
  11.     This should allow you to transfer any DOS file as a text file
  12.     over any E-MAIL system and then re-create it on the receiving
  13.     end.  Keep in mind that your HEX dump file will be TWICE as
  14.     big as the original file.  I wouldn't recommend transfering
  15.     Clipper EXE's to Germany with this util.
  16.  
  17.     My apologies to SYSOPS all over the world!
  18.  
  19.     Compile with: -m -n
  20.     Link With   : whatever
  21.  
  22.     Kirby L. Wallace
  23.     120 N. Sandusky Ave.
  24.     Tulsa, OK.  74115
  25.  
  26.     RELEASED TO THE PUBLIC DOMAIN: March 1993
  27.  
  28. ***************************************************************************/
  29.  
  30. #include "fileio.ch"
  31. #define  LF CHR(13)+CHR(10)
  32.  
  33. ****************************************************************************
  34. FUNCTION FileOut( cInFile, cOutFile )
  35.  
  36. LOCAL   nIHandle, nOHandle
  37. LOCAL   nInputEnd
  38. LOCAL   cByte := ' ', i
  39.  
  40. BEGIN SEQUENCE
  41.  
  42.     if !file(cInFile)
  43.         ?
  44.         ? 'Input File Not Found: '+cInFIle
  45.         BREAK
  46.  
  47.     endif
  48.  
  49.     nOHandle = fcreate(cOutFile)
  50.  
  51.     if ferror() != 0
  52.         ?
  53.         ? 'Output File Create Error: '+cOutFile
  54.         BREAK
  55.     endif
  56.  
  57.     nIHandle = fopen(cInFile)
  58.  
  59.     if ferror() != 0
  60.         ?
  61.         ? 'Input File Open Error: '+cInFile
  62.         BREAK
  63.     endif
  64.  
  65.     nInputEnd = fseek(nIHandle,0,FS_END) ; fseek(nIHandle,0,FS_SET)
  66.  
  67.     i = 0
  68.  
  69.     while .t.
  70.  
  71.         if fread(nIHandle,@cByte,1) != 1
  72.             ? 'Done...'
  73.             BREAK
  74.         endif
  75.  
  76.  
  77.         fwrite(nOHandle,_IToH(asc(cByte)),2)
  78.         i++
  79.  
  80.         if i = 35
  81.             fwrite(nOHandle,LF,2)
  82.             i = 0
  83.         endif
  84.  
  85.     end
  86.  
  87. END SEQUENCE
  88.  
  89. fclose(nIHandle) ; fclose(nOHandle)
  90.  
  91. RETURN(NIL)
  92.  
  93. ****************************************************************************
  94. FUNCTION _IToH(nInteger)
  95. LOCAL    i
  96. LOCAL    j
  97. LOCAL    cHexOut := ""
  98. LOCAL    aHexPosVal := {1,16,256}
  99. LOCAL    cHex := repl('0',len(aHexPosVal))
  100.  
  101.  
  102. // indenting reduced to fit message base size
  103. // you may want to re-indent to suit your needs
  104.  
  105. for i = len(aHexPosVal) to 1 STEP -1
  106.  
  107.  for j = 16 to 1 STEP -1
  108.  
  109.    if aHexPosVal[i] * j <= nInteger
  110.  
  111.      cHex = stuff(cHex,i,1,iif(j > 9, substr('ABCDEF',j-9,1),ltrim(str(j))))
  112.      nInteger -= (aHexPosVal[i] * j)
  113.  
  114.      exit
  115.  
  116.    endif
  117.  
  118.  next
  119.  
  120. next
  121.  
  122. for i = len(cHex) to 1 STEP -1
  123.     if substr(cHex,i,1) != '0'
  124.         j = i
  125.         exit
  126.     endif
  127.  
  128. next
  129.  
  130. for i = j to 1 STEP -1
  131.     cHexOut += substr(cHex,i,1)
  132. next
  133.  
  134.  
  135. cHexOut = repl('0',2-len(cHexOut))+cHexOut
  136.  
  137. RETURN(cHexOut)
  138.