home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / cpmug / cpmug087.ark / MASORT.BAS < prev    next >
Encoding:
BASIC Source File  |  1986-10-20  |  2.9 KB  |  134 lines

  1.     rem This is the Mailing List Entry Sort Program
  2.  
  3.  
  4.     rem This program creates a backup file and copies all undeleted
  5.     rem records to that file. Simultaneously it creates a RAM resident
  6.     rem list of either tag numbers, account numbers, or reference numbers
  7.     rem -  S(xxxx) - and Relative Record KEYS - T(xxxx).
  8.  
  9.     rem The tag, account, or reference numbers are then sorted via a Shell
  10.     rem Metzler algorithm and the Relative Record KEYS carried along.
  11.  
  12.     rem When the sort is complete, the Relative Record KEYS are used to
  13.     rem restore the backed up records to the original file in sorted order.
  14.  
  15.  
  16. %INCLUDE ALL.BAS
  17.  
  18.     dim s(z2),t(z2),n(2,20)
  19. 1000    print clear$:print:
  20.  
  21.  
  22.     print "Enter file name of mailing list as no more than 4 characters"
  23.     print "i.e. - mail. Drive b: and 'back' or 'size' will be"
  24.     print "added by the program."
  25.  
  26.     input line mail$
  27.  
  28.     if len(mail$)>4 then 1000
  29.  
  30.  
  31.     z5$="b:"+mail$:z6$=z5$+"back":z7$=z5$+"size":RL=150
  32.  
  33. 8000    INPUT "SORT ON TAG OR REFERENCE # (T OR A)";LINE SORT.KEY$
  34.     IF SORT.KEY$="t" OR SORT.KEY$="T" THEN A9=1:GOTO 8020
  35.     IF SORT.KEY$="a" OR SORT.KEY$="A" THEN A9=2:GOTO 8020
  36.     GOTO 8000
  37.  
  38. 8020    PRINT clear$:PRINT
  39.     PRINT "*** BACKING UP FILE ***"
  40.     PRINT:PRINT "*** NOTE - BACKUP IGNORES DELETED RECORDS ***"
  41.  
  42.     open z5$ recl RL as 1
  43.     create z6$ recl RL as 2
  44.  
  45.  
  46.     Z1=0
  47.  
  48.     FOR Z=1 TO Z2-1
  49.     read #1,z;N(2,1),N(2,2),N$
  50.     IF N(2,1)=0 THEN 8065
  51.     IF N(2,2)=0 THEN 8070
  52.     Z1=Z1+1
  53.     print #2,z1;N(2,1),N(2,2),N$
  54.     T(Z1)=Z1:S(Z1)=N(2,A9)
  55. 8065        NEXT Z
  56. 8070            close 1
  57.             close 2
  58.  
  59.     PRINT clear$:PRINT
  60.     PRINT "*** SORTING ON";
  61.     IF A9=1 THEN PRINT " TAG ***"
  62.     IF A9=2 THEN PRINT " REFERENCE NUMBER ***":PRINT
  63.     PRINT "THIS SORT TAKES FROM 30 SECONDS FOR 100 RECORDS"
  64.     PRINT "TO 10 MINUTES FOR 1000 RECORDS":PRINT
  65.     PRINT "*** PLEASE WAIT ***":PRINT
  66.  
  67.  
  68.     rem This is the actual sort routine
  69.  
  70.     N9=Z1
  71.     M9=N9
  72. 8515    M9=INT(M9/2)
  73.     IF M9=0 THEN 8580
  74.         J9=1:K9=N9-M9
  75.  
  76. 8530    I9=J9
  77. 8535    L9=I9+M9
  78.     IF S(I9)<S(L9) THEN 8565
  79.  
  80.         Z=S(I9):S(I9)=S(L9):S(L9)=Z
  81.         Z=T(I9):T(I9)=T(L9):T(L9)=Z
  82.         I9=I9-M9
  83.  
  84.     IF I9<1 THEN 8565
  85.  
  86.     GOTO 8535
  87.  
  88. 8565    J9=J9+1
  89.     IF J9>K9 THEN 8515
  90.     GOTO 8530
  91.  
  92.  
  93. 8580    PRINT clear$:PRINT
  94.     PRINT "SORT COMPLETED - YOU MAY STILL ABORT":PRINT
  95.     PRINT "IF YOU WISH TO ABORT - JUST TYPE ABORT":PRINT
  96.     PRINT "OTHERWISE TYPE A CARRIAGE RETURN TO CONTINUE !"
  97.     PRINT
  98.         INPUT LINE TEMP$
  99.         IF TEMP$="abort" OR TEMP$="ABORT" THEN 10000
  100.  
  101.             if T(1)=0 then 10000
  102.  
  103.     open z5$ recl RL as 1
  104.     open z6$ recl RL as 2
  105.         open z7$ as 3:read #3;z2,z3:close 3
  106.  
  107.  
  108.     Z2=Z1+1
  109.  
  110.     FOR Z=1 TO Z2-1
  111.     READ #2,T(Z);N(2,1),N(2,2),N$
  112.     PRINT #1,Z;N(2,1),N(2,2),N$
  113.     NEXT Z
  114.  
  115.         N(2,1)=0:N(2,2)=0:N$=""
  116.  
  117.     FOR Z=Z2 TO Z3+2
  118.  
  119.     read #1,z;N(2,1),N(2,2),N$
  120.         if N(2,2)=0 then 8995
  121.  
  122.     print #1,z;N(2,1),N(2,2),N$
  123.     NEXT Z
  124. 8995        close 1
  125.         delete 2
  126.         open z7$ as 3:print #3;z2,z3:close 3
  127.  
  128. chain "maentry"
  129.  
  130.  
  131. 10000 open z6$ recl RL as 1
  132.     delete 1
  133.     chain "maentry"
  134.