Text File Splitter...

GFA BASIC-related articles in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2397
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Text File Splitter...

Postby charles » Mon Sep 17, 2018 8:14 pm

I got tired of cutting and pasting into google translate ....

prob an easier method
(restricted to max 5000 bytes per translate)

, but either way

since its Atari text files ive been translating a lot of lately.
went ahead a wrote this small program

Code: Select all

' sof
'
SAVE "b:\tfs.gfa"
LIST "d:\tfs.lst"
WHILE EXIST("b:\*.bak")
  KILL "b:\*.bak"
WEND
'
prg_size%=(500000 DIV 256)*256
'
IF FRE()>prg_size%
  '
  ' reserve space for program
  RESERVE prg_size%
  '
  ap_id&=APPL_INIT()
  '
  rez&=XBIOS(4)
  '
  IF rez&=2
    '
    REPEAT
      INPUT "Each Split Size(500 to 32767) : ";split_step&
    UNTIL split_step&>999 AND split_step&<32768
    '
    @variable.constants
    '
    screen%=MALLOC(32000+256)
    @my_program(split_step&)
    ~MFREE(screen%)
    '
  ENDIF
  '
  ~APPL_EXIT()
  '
  RESERVE
  '
ELSE
  PRINT "sorry NOT enough mem to run tfs.prg"
  PRINT "press key";
  ~INP(2)
ENDIF
'
END
'
> PROCEDURE variable.constants
  screen%=0
  button&=0
  myfile$=SPACE$(13)
  mypath$=SPACE$(64)
  step|=0
  step&=0
  file.len%=0
  a%=0
  d_div&=0
  r_mod&=0
RETURN
> PROCEDURE selectfile
  mypath$="C:\*.TXT"
  myfile$=""
  @fselect(mypath$,myfile$,button&)
  title$=myfile$
  WHILE RIGHT$(mypath$,1)<>"\"
    mypath$=LEFT$(mypath$,LEN(mypath$)-1)
  WEND
RETURN
> PROCEDURE fselect(VAR mypath$,myfile$,button&)
  BMOVE XBIOS(2),screen%,32000
  VOID FSEL_INPUT(mypath$,myfile$,button&)
  BMOVE screen%,XBIOS(2),32000
RETURN
> PROCEDURE my_program(step&)
  '
  @selectfile
  IF button& AND myfile$<>""
    OPEN "I",#1,mypath$+myfile$
    file.len%=LOF(#1)
    IF file.len%
      @split(step&)
    ENDIF
    CLOSE #1
  ENDIF
  '
RETURN
PROCEDURE split(step&)
  '
  LOCAL cnt&
  '
  PRINT "New File(s) :";
  SEEK #1,cnt&
  a%=MALLOC(step&)
  '
  d_div&=(file.len% DIV step&)
  WHILE d_div&>cnt&
    @filenamestep
    BGET #1,a%,step&
    BSAVE "D:\"+myfile$,a%,step&
    INC cnt&
    SEEK #1,MUL(step&,cnt&)
  WEND
  '
  r_mod&=(file.len% MOD step&)
  IF r_mod&>0
    @filenamestep
    BGET #1,a%,r_mod&
    BSAVE "D:\"+myfile$,a%,r_mod&
  ENDIF
  '
  ~MFREE(a%)
  '
RETURN
PROCEDURE filenamestep
  '
  LOCAL ext$,file$
  '
  INC step|
  ext$=RIGHT$(myfile$,4)
  file$=LEFT$(myfile$,SUB(INSTR(myfile$,".",1),1))
  MID$(file$,1)=STR$(step|)
  myfile$=file$+ext$
  '
  PRINT " "+myfile$+" ";
  '
RETURN
'
' eof





splits a file into 500 bytes to 32767 bytes partials and saves each chunk as own file .....

nice if I knew dos
maybe I could generate a batch file with gfa for all these little files to self execute .....
,but either way

nice to have ability to choose ....

Charles
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 4 guests