home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 April / PCWorld_2000-04_cd.bin / Software / TemaCD / winedit / ctrlines.wb_ < prev    next >
Text File  |  1999-10-04  |  4KB  |  50 lines

  1. _Centre                                                     ; v1.00 18/09/1999 
  2.     lmax=106                                                ; max screen width 
  3.     if wgetselstate() then                                  ; anything selected
  4.         xxcurl2=wgetlineno()                                ; get end of selection line number
  5.         wcut()                                              ; yes, copy it to clipboard
  6.         xxcurl1=wgetlineno()                                ; get start of selection line number
  7.         else                                                ;  
  8.         xxcurl1=1                                           ; line # 1 for all
  9.         wSelectAll()                                        ; no, get the lot
  10.         xxcurl2=wgetlineno()                                ; get end of selection line number
  11.         wcut()                                              ; now
  12.         endif                                               ;  
  13.     afiles=2000000                                          ; way too much, but...
  14.     rbuf=binaryalloc(afiles)                                ; buf for current file
  15.     nbuf=binaryalloc(afiles+1000000)                        ; buf for modified lines
  16.     binaryclipget(rBuf, 1)                                  ; and stick it in the buffer
  17.     ls=0                                                    ; starting point for unmodified lines
  18.     Brk = binaryeodget(rBuf)                                ; max buffer
  19.     while ls < Brk                                          ; go through input buffer
  20.         rc=0                                                ; no @crlf required
  21.         le = binaryindexex(rbuf,ls,@crlf,@fwdscan,0)        ; find end of line
  22.         if le < 0 then le = brk                             ; end of buffer; last line
  23.             else rc=1                                       ; @crlf required 
  24.         ll=le-ls                                            ; ll is length of current line 
  25.         dataline=binarypeekstr(rbuf,ls,ll)                  ; process i/p record
  26.         ls=ls+ll                                            ; add length of old data
  27.         gosub centre                                        ; centre subroutine
  28.         if rc then binarypokestr(nbuf,binaryeodget(nbuf),strcat(dataline,@crlf)) ; add to new buffer with @crlf
  29.             else binarypokestr(nbuf,binaryeodget(nbuf),dataline) ; add to new buffer data only
  30.         if rc then ls=ls+2                                  ; minimum increase in rbuf size
  31.         endwhile                                            ;  
  32.     binaryeodset(nbuf,binaryeodget(nbuf))                   ; set length of restore 
  33.     binaryclipput(nBuf, 1)                                  ; text format
  34.     wpaste()                                                ; stick back in edit file
  35.     wgotoline(xxcurl1)                                      ; point back at original location
  36.     binaryfree(nbuf)                                        ; free output buffer
  37.     binaryfree(rbuf)                                        ; free input buffer
  38.     mouseclick(@lclick,0)                                   ; regain focus
  39.     drop(lmax,xxcurl1,xxcurl2,afiles,brk,nbuf)              ; drop 'em
  40.     drop(rbuf,ls,le,ll,dataline,rc,a,dl)                    ; drop 'em
  41.     exit                                                    ; 
  42.     :centre                                                 ; 
  43.     dataline=strtrim(dataline)                              ; get bare data
  44.     dl=strlen(dataline)                                     ; and its length
  45.     a=lmax-dl                                               ; how about a fit
  46.     if a<2 then return                                      ; too fat, display all
  47.     dataline=strcat(strfill(" ",a/2),dataline)              ; that'll do nicely
  48.     return                                                  ; 
  49.     
  50.