=0  A-Z  ,,,,,,,,T,SKIPPARS,F,SEARC, ,,N,P,P,P,P,P,,,T,T,(),(),(), SEARCHWOR(),SEARCHFIEL(),SKIPWOR(),LOOKFIEL(),D(),,F;N (N,) field #, num?, length, pad?TT$ ().(()())48 LS(),HS() lo and hi stacks&B ENTER HERE TO RE-SPECIFY L RV()""  (TT)  do here for recycle (erased below) `"SORT %e by Dan Dugan -- public domainOj"Arranges a selected set of records in numerical or alphabetical order.Ht"To quit this activity, enter 'x' in response to a 'y/n' question.#~ T T P"Shall the output include the records outside the range sorted? (n/y) ";)v() ( ) "n"!  "y" S "x" H M"Please define the key fields for sorting in '"".' The fields are: ^  showP"The file will be re-arranged according to the contents of the key fields.L"Enter the primary key field number first, then any others you wish to("be sorted within that order, etc.VSKLEKLENFLA  any alph field will change S6 to 0; key length  NT ;". "; "Enter field number of key field (0 when done) ";(,)  (,) ] (,) (,)N "Field"(,)"??? Enter again." O (,) |(((,)),)"n" (,)  S.( (if just one is alpha, do alpha sort)K2 "Number of characters in field to use (RETURN for all)";(,)!4 (,) 6  <x6 (,)"Do you want to pad shorter fields to that length? (n/y) "; v() ( ) "n"(7  "y" (,)Q< (,) F  "You want to sort on all characters of ";  PCF "You want to sort on the first"(,)"characters of ";RP x(((,)),)"? (y/n) "; v() ( ) "y"Z  "x" H Fd "y" "Entry cancelled; ready for key""again." Wn (,) KLEKLE(,)  KLEKLE KLENFLAx  N (,) H quit""Ascending order? (y/n) ";)v() ( ) "y"!  "n" S "x" H  OUTPUT SWITCH (P7) PJ"Shall the product of the sort overlay the original file? (y/n) ";)v() ( ) "y"  "x" H  "n" P @ "y"  YES, OVERLAY - (T T) S ^I""NOT ALLOWED - Overlaying part of file on file will erase records","outside of range."  6 NAME OUTPUT FILE @@"Name of sort product file (no prefix or suffix) ";FJ F"" 'TF PF  ucv^ SHOW SORT SET-UP h  csr"SETUP FOR SORTD| T T "Sort all records ("")" 4"Sorting range of records from"T"to"T" S ,= "The output will be the range of records only." J "The output will be the entire file with the selected range sorted.]"Records will be put in order by examining" "the contents of the sort key fields."  N> (); "##";; ". "x(((,)),);9 ((); (,) (,)  " all"  ! KLENFLA   Y"ESTIMATED string space needed for the key array is"KLE(TT) G"String space needed for the key array is"KLE(TT),"and the available space is"()".\"This program can't tell whether there is enough space on disk " D()" for tempo-%"rary storage of the key array.)"The records will be sorted in ";& S "ascending "; "descending ";) S "alphabetical "; 0&"numerical ";0"order."(: "The output of the sort will ";4D P "overlay the original file." X:N"create a new DIMS file "F" on disk "D()"."lX P (T T) S "You are aware that this process will erase records?] P b  lCb"The new file "F" will replace the safety copy of "".=d"You must then use PIP to move "F" to another disk,Bf"and use the DEDIT 'backup' command on "" to re-create ah"safety copy.l FINAL APPROVAL 0v"Is this exactly what you want? (y/n) ";)v() ( ) "y"   "x" H % "n" "Try again." B "y" v  >! SORT CONTROLS GUIDE G S() array holds key orders (field#, num? (1=num), length, pad?)% NK = number of keys specified S6 = 0 alpha sort 1 numeric sort% S7 = 0 don't rename dupe file( 1 rename dupe file as F2$.D S8 = 0 ascending order  1 descending order2 S9 = 0 output only sorted range of records:  1 output records above and below sorted range * P7 = 0 overlay main file#4 1 output to named file#> PUT KEYS IN TEMP FILE H R"SORTING '""'\"Extracting keys." f "O",,D()"KEYS.$$$"p T Tz    get recordF () (~)"(del)"   sorts deletes to end   parse  ""  NA (,)   ((,)) / x(((,)),(,)) ()z (,) ((,),(0))   pad num field with left 0's, (,)   "" > ((,),( )) spaces to pad right  = "" (~)   makes empties go later S   P ucv ,  ,$ . &8  LOAD INDEX AND KEY ARRAYS B "Loading key array:" L "I",,D()"KEYS.$$$"$V T()()` ()  j ,()t ()~  `   D()"KEYS.$$$"!  READY TO SORT ARRAY  "Sorting array."3  from QUICKSORT by Sylvan Rubin DDJ #33 p.42$ LNHNST  PARTITION   exit' LNHN ^  pop stackE (P);CT((LNHN))  use center for pivot< (CT),(HN) (CT),(HN) LLNHHN( PI(HN) (  scan-l  EXCHANGE 8 (L),(H) (L),(H)(  SCAN-L 32 LL S < ,F  alph, num%< S P ,Z  asc, descF S d ,n &P (L)PI 2  x &Z (L)PI 2  x .d &((L))&(PI) 2  x .n &((L))&(PI) 2  x x  SCAN-H & HH S  ,  S  ,  S  , & (H)PI    & (H)PI    . &((H))&(PI)    . &((H))&(PI)     LH    SWAP PIVOT : (L),(HN) (L),(HN)  PUSH STACK 9 (HLN)(HNL) ,  stack low  STACK HIGH  LHN  A STSTLS(ST)LHS(ST)HN  SHIFT HIGHEND $" HNH   partition,  STACK LOW +6 LNH T  shift lowend?@ STSTLS(ST)LNHS(ST)HJ  SHIFT LOWEND &T LNL   partition^  POP STACK h ST   done0r LNLS(ST)HNHS(ST)'| STST   partition "Array sorted.  OUTPUT 8 N  counts number of records in product file*  D()".DD"F  S  !  COPY BLOCK BELOW T1  T  ( "Outputting records below range.  T f output record *  MOVE RECORDS PER INDEX ARRAY _ "Now moving records from " D()" to "D()" in sorted order per index array."!   don't need strings  TT () f & 0  COPY BLOCK ABOVE 4: S T l  skip block copy'D "Outputting records above rangeN T X f  outputb &l  SAVE HEADER AND TIDY UP %v "Saving header;"N"records ""  ! ()(~)% x((),)"stop"   , "(N)(~)  NR at end N  for header   put it "!"# P  rename product $  copy dupe to main 4   RENAME OUTPUT FILE F  D()".DD"F D()F".D"F F "Product file "F" is now on disk "D()" (backup erased).J "After moving product to desired disk, use 'backup' command on "A* "to restore safety copy. Hit RETURN to continue. ";4 "Sort completed> (); beepH  RETURN TO DEDIT R "Re-loading DEDIT.\ D()"DEDIT",'f  (SUB) OUTPUT RECORD "I" p    get rec Iz   exit- NN  # records in prod. file  PUT RECORD NR  F  ,  (,) #,FN x(,) #,FN "  (SUB) PARSE STRING & w(,(~))  delimiter    ()(,,)(,)   =$ (SUB) ERASE ORIGINAL FILE AND COPY DUP TO ORIG .8B D()".D"F1L"Copying dupe, overlaying original file."V   open both files`  F()j #, t "&";~  #,  "*";   ERROR HANDLING  =   D "Sorry - process halted because there isn't enough disk space "for the key file.C "Hit return to recover."; D()"DIMS",       C "Sorry - process halted because key array needed more memoryF "than is available. Try again with shorter key specifications., "Hit return to try again."; B  :   F2 "Sorry - file named "F" already exists.< "Enter another name for the output file here: ";( "" 2 PF ucv <  FP (SUB) UCV Z""d  ()n " "x ((,,))= ` { (,,)( ) # (,,)(,,)+ (SUB) CLEAR SCREEN(TERM DEP)  ( )! (SUB) OPEN UP FILES $"R",,D()".D"F #, %"R",,D()".DD"F #, ) (SUB) GET RECORD "I" IN T$ """ F @,,&, #,F  latter half6 x(,)@ #,FJ T ^ (SUB) SHOW FIELDS h  Nr () | ();> "##";;". "x((),)" "|((),) (SUB) EXIT TEST u () ."Process paused by EXIT from keyboard.."Do you want to continue (y,n or x) ? ";(v() ( ) "y""  "x"  H  "y"  Be (y,n or x) ? ";(v() ( ) "y""