$ if "''p1'" .nes. "" then goto open_infile
$ inquire p1 "Vstupni soubor"
$open_infile:
$ open/read/error=openerr infile 'p1'
$
$ if "''p2'" .nes. "" then goto open_outfile
$ inquire p2 "Vystupni soubor"
$open_outfile:
$ open/write outfile 'p2'
$
$ if "''p3'" .nes. "" then goto get_num
$ inquire p3 "Pocet znaku"
$get_num:
$ n = p3
$
$ rest :=
$
$file_loop:
$  read/end_of_file=loop_end infile line
$  i = 0
$  j = 0
$
$  line = f$edit(rest+" "+line, "TRIM,COMPRESS")
$  if f$length(line) .eq. f$length(rest) .and. f$length(rest) .gt. 0
$    then write outfile rest
$    write outfile ""
$    rest = ""
$    goto file_loop
$  endif
$
$  line_loop:
$    if f$extract(i, 1, line) .eqs. " " then j=i
$    i = i+1
$    if i .le. f$length(line) .and. i .le. n then goto line_loop
$
$    if j .eq. 0 .or. i .le. n then j=f$length(line)
$    outline = f$extract(0, j, line)
$    rest = f$extract(j+1, f$length(line)-(j+1), line)
$    write outfile outline
$
$    if f$length(rest) .ge. n
$      then line = rest
$      i = 0
$      j = 0
$      goto line_loop
$    endif
$
$  goto file_loop
$
$loop_end:
$
$  if f$length(rest) .gt. 0 then write outfile rest
$
$  close infile
$  close outfile
$
$exit
$
$
$openerr:
$ write sys$output "Vstupni soubor se nepovedlo otevrit"

