Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 2.15 KB | None | 0 0
  1. #COMPILE EXE
  2. #DIM ALL
  3.  
  4. FUNCTION PBMAIN () AS LONG
  5.  
  6.     DIM lastbyte$
  7.     lastbyte$ = " "
  8.     DIM infile$
  9.     DIM outfile$
  10.     IF COMMAND$ = "" THEN
  11.         INPUT "INPUT FILE?", infile$
  12.         INPUT "OUTPUT FILE?", outfile$
  13.     ELSE
  14.     infile$ = COMMAND$(1)
  15.     outfile$ = COMMAND$(2)
  16.     END IF
  17.         DIM tempcount AS INTEGER
  18.         lastbyte = ""
  19.     DIM buffer$
  20.     buffer$ = " "
  21.    
  22.     KILL outfile$
  23.     OPEN infile$ FOR BINARY AS #1
  24.     OPEN outfile$ FOR BINARY AS #2
  25.     tempcount = 0
  26.     DIM temp$
  27.     temp$ = " "
  28.     PUT #2, , temp$                            ' FILLER FOR FILE SIZE
  29.     PUT #2, , temp$                            ' FILLER FOR FILE SIZE
  30.     DIM init&
  31.     init& = 1
  32.     WHILE NOT EOF(1)
  33.         GET #1, , buffer$
  34.                
  35.         IF buffer$ = lastbyte THEN
  36.             tempcount = tempcount + 1
  37.         ELSE
  38.            
  39.             IF tempcount = 1 THEN
  40.                 temp$ = CHR$(0)
  41.                 PUT #2, , lastbyte$
  42.                 PUT #2, , temp$
  43.                 lastbyte = buffer$
  44.                 tempcount = 0
  45.             ELSEIF tempcount = 0 THEN
  46.                
  47.              IF init& = 1 THEN
  48.                  init& = 0
  49.                  lastbyte = buffer$
  50.                  tempcount = 0
  51.              ELSE
  52.                 PUT #2, , buffer$
  53.                 lastbyte = buffer$
  54.                 tempcount = 0
  55.              END IF
  56.             ELSEIF tempcount > 1 THEN
  57.            
  58.                 temp$ = CHR$(tempcount - 1)
  59.                 PUT #2, , lastbyte$
  60.                 PUT #2, , lastbyte$
  61.                 PUT #2, , temp$
  62.                 lastbyte = buffer$
  63.                 tempcount = 0
  64.        
  65.                
  66.             END IF
  67.         END IF
  68.     WEND
  69.        
  70.     CLOSE #1
  71.     CLOSE #2
  72.    
  73.     OPEN outfile FOR BINARY AS #2           ' WRITE FILESIZE (1xWORD)
  74.     DIM temp2$
  75.     temp2$ = SPACE$(LOF(2))
  76.     GET #2, , temp2$
  77.     CLOSE #2
  78.     OPEN outfile FOR BINARY AS #2
  79.    
  80.     temp$=CHR$(INT(LOF(2) / 256))
  81.     MID$(temp2$,1,1) = temp$
  82.     temp$ = CHR$(LOF(2) MOD 256)
  83.    
  84.     MID$(temp2$,2,1) = temp$
  85.     PUT #2, ,temp2$
  86.     CLOSE #2
  87.    
  88.    
  89. END FUNCTION
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement