home *** CD-ROM | disk | FTP | other *** search
- rem app FSort
- rem ext "XYZ"
- rem icon "A:\PIC\FSORT.PIC"
- rem enda
-
- proc FSort:
- global a$(901,32),path$(128)
- global bPath$(128),nr%,max%
- local p%,e%,id%
- giPrint swver$:
- init:
- max%=900
- while getFile:
- p%=1
- id%=progress:("Sorting data...",-1,0)
- first
- while not eof
- inSort:(valid$:,p%)
- next
- p%=p%+1
- if mod%:(p%,10)=0
- progress:("",p%,nr%*2)
- endif
- endwh
- copyFile:
- progress:("",nr%*2,nr%*2)
- progress:("",-2,id%)
- signal:
- dInit "Sort completed"
- dPosition 1,-1
- dText "Press:","ENTER to continue"
- dText " ","ESC to quit"
- lock on :e%=Dialog :lock off
- if e%=0 :stop :endif
- endwh
- endp
-
- proc copyFile:
- local p%,e%,tPath$(128),f%(6)
- progress:("Setting up new file...",nr%,nr%*3)
- trap close
- tPath$=left$(path$,len(path$)-1)+""
- trap delete tPath$
- compress path$,tPath$
- open path$,a,a$,b$,c$,d$,e$,f$,g$,h$,i$,j$,k$,l$,m$,n$,o$,p$
- open tPath$,b,a$,b$,c$,d$,e$,f$,g$,h$,i$,j$,k$,l$,m$,n$,o$,p$
- p%=nr% :e%=1
- while p%<>0
- last :erase :p%=p%-1 :e%=e%+1
- if mod%:(p%,10)=0
- progress:("",nr%+e%,nr%*3)
- endif
- endwh
- progress:("Writing sorted data",nr%*2,nr%*3)
- p%=1
- while p%<=nr%
- e%=val(left$(a$(p%),3))
- use a :position e%
- b.a$=a.a$ :b.b$=a.b$ :b.c$=a.c$
- b.d$=a.d$ :b.e$=a.e$ :b.f$=a.f$
- b.g$=a.g$ :b.h$=a.h$ :b.i$=a.i$
- b.j$=a.j$ :b.k$=a.k$ :b.l$=a.l$
- b.m$=a.m$ :b.n$=a.n$ :b.o$=a.o$
- b.p$=a.p$
- use b :append
- p%=p%+1
- if mod%:(p%,10)=0
- progress:("",(nr%*2)+p%,nr%*3)
- endif
- endwh
- trap use a :trap close
- trap use b :trap close
- trap delete bPath$
- rename path$,bPath$
- rename tPath$,path$
- endp
-
- proc init:
- gStyle 1+8+32
- gAT 15,19 :gPrint "F S o r t"
- gStyle 0
- gAT 140,16
- gPrint "Version",left$(swver$:,loc(swver$:," "))
- gAT 0,26
- gBorder $201,240,54
- gAT 8,38 :gPrint "Original file:"
- gAT 8,57 :gPrint "Backup file:"
- endp
-
- proc info:(s$)
- local b$(11)
- busy off
- b$="...empty..."
- dInit s$
- if a.a$="" :dText "",b$
- else :dText "",left$(a.a$,40) :endif
- if a.b$="" :dText "",b$
- else :dText "",left$(a.b$,40) :endif
- if a.c$="" :dText "",b$
- else :dText "",left$(a.c$,40) :endif
- if a.d$="" :dText "",b$
- else :dText "",left$(a.d$,40) :endif
- if a.e$="" :dText "",b$
- else :dText "",left$(a.e$,40) :endif
- lock on :Dialog :lock off
- endp
-
- proc getFile:
- local e%,r%,a%(6),s&
- START::
- lock off :s&=0 :trap close
- path$=parse$(path$,"\DAT\*.DBF",a%())
- dInit "File to sort"
- dFile path$,"",0
- dPosition 1,-1
- lock on
- if dialog
- rem Check file type, etc.
- trap openr path$,a,a$,b$,c$,d$,e$,f$,g$,h$,i$,j$,k$,l$,m$,n$,o$,p$
- if err
- giPrint err$(err)
- goto START::
- endif
- nr%=count
- if nr%>max%
- trap close
- giPrint "Too many records"
- goto START::
- endif
- busy "Checking file...",2,0
- onerr OUT::
- first
- while not eof
- rem If there's data in the 16th
- rem field, it's likely that the
- rem 17th does too. Better safe...
- if a.p$<>""
- info:("This record may be too large")
- goto START::
- endif
- s&=s&+recsize
- next
- endwh
- if s&+1000>space
- giPrint "Not enough space"
- goto START::
- endif
- onerr off :busy off :lock off
- bPath$=left$(path$,len(path$)-1)+"!"
- gAT 10,48 :gPrintB path$,220,3
- gAT 10,65 :gPrintB bPath$,220,3
- gAT 10,75 :gPrintB "Check original before deleting backup",220,3
- return 1
- else
- lock off :return 0
- endif
-
- OUT::
- onerr off
- trap close
- giPrint "Record too large"
- giprint err$(err)
- goto START::
- endp
-
- proc valid$:
- rem Returns a valid string (field)
- rem from the current record for
- rem sorting: upper case, 1..29
- rem characters in length
- if a.a$<>""
- return upper$(left$(a.a$,29))
- elseif a.b$<>""
- return upper$(left$(a.b$,29))
- elseif a.c$<>""
- return upper$(left$(a.c$,29))
- elseif a.d$<>""
- return upper$(left$(a.d$,29))
- elseif a.e$<>""
- return upper$(left$(a.e$,29))
- elseif a.f$<>""
- return upper$(left$(a.f$,29))
- elseif a.g$<>""
- return upper$(left$(a.g$,29))
- elseif a.h$<>""
- return upper$(left$(a.h$,29))
- elseif a.i$<>""
- return upper$(left$(a.i$,29))
- elseif a.j$<>""
- return upper$(left$(a.j$,29))
- elseif a.k$<>""
- return upper$(left$(a.k$,29))
- elseif a.l$<>""
- return upper$(left$(a.l$,29))
- elseif a.m$<>""
- return upper$(left$(a.m$,29))
- elseif a.n$<>""
- return upper$(left$(a.n$,29))
- elseif a.o$<>""
- return upper$(left$(a.o$,29))
- elseif a.p$<>""
- return upper$(left$(a.p$,29))
- endif
- endp
-
- proc inSort:(s$,index%)
- rem Given a string, its position in the master database and
- rem a pre-defined string array a$(900,32), will insert the
- rem string in the correct position and prepend the index:
- rem nnntheString
- local nld%,p%,x%,t$(29),n$(3)
- nld%=index%-1
- if nld%=0
- a$(1)="001"+s$
- return
- endif
- rem Build index string
- n$=gen$(index%,3)
- while len(n$)<3
- n$="0"+n$
- endwh
- p%=1 rem p% is general index
- rem Locate spot for insertion or appending
- if len(a$(p%))>3
- t$=mid$(a$(p%),4,29)
- else
- t$=""
- endif
- while s$>t$ and p%<=nld%
- p%=p%+1
- if len(a$(p%))>3
- t$=mid$(a$(p%),4,29)
- else
- t$=""
- endif
- endwh
- if p%>nld% rem Append string to list
- a$(nld%+1)=n$+s$
- else rem Shift everything up and insert string
- nld%=index%
- x%=nld%-1
- do
- a$(x%+1)=a$(x%)
- x%=x%-1
- until x%<p%
- a$(p%)=n$+s$
- endif
- endp
-
- proc mod%:(a%,b%) rem a% mod b%
- if b%
- return a%-(a%/b%)*b%
- endif
- endp
-
- proc progress:(t$,cur%,max%)
- rem cur% Current index
- rem -also used for control
- rem max% Maximum index (total)
- rem -also to pass window id
- rem t$ Window title
- local p,w,id,c,m
- c=flt(cur%) :m=flt(max%)
- if c>=0 rem progress
- w=146.0
- if c<=m
- gAT 22,17 :p=((c*100.0)/m)
- gPatt -1,(p*(w/100.0))-1,8-2,3
- endif
- if t$<>""
- gAT 3,10 :gPrintB t$,183,3
- endif
- elseif c=-1 rem create
- id=gCreate(25,26,190,29,0)
- gBorder $203
- gAT 0,13 :gLineTo 220,gY
- gAT 3,10 :gPrintB t$,183,3
- gAT 20,23 :gPrint chr$(18);
- gAT 164,gY :gPrint chr$(19);
- gAT 22,16 :gLineTo 164,gY
- gAT 22,23 :gLineTo 164,gY
- gVisible on :return id
- elseif c=-2 rem dispose
- gClose max%
- endif
- endp
-
- proc signal:
- local e%
- e%=0
- do
- beep 3,100 :beep 3,200
- e%=e%+1
- until e%>2
- endp
-
- proc swver$:
- return "1.01 - Jim Hoyt"
- endp
-
-
-