home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / CPMUG / CPMUG080.ARK / UTILITY.STB < prev    next >
Text File  |  1984-04-29  |  4KB  |  151 lines

  1.  
  2.    10   @"Basic Text File Manipulations."
  3.    20   @"Copyright"
  4.    30   @"David E. Trachtenbarg"
  5.    40   @"07/28/80"
  6.    50   Set 0,-1
  7.    60   Dim Command2$(0),Line$(4),Basicfile1$(13),Basicfile2$(13)
  8.    70   Dim Buffer1$(127),Buffer2$(127),Line'number$(4),Eof$(1)
  9.    80   Integer I,J,K,Rec1,Rec2,Line
  10.    85   Eof$=Chr$(26)+Chr$(27)
  11.    90 *Menu
  12.   100   @ : @
  13.   110   @"1. Create a new text file without numbers."
  14.   120   @"2. Add numbers to a text file without numbers."
  15.   140   @"3. Leave Program."
  16.   150   @
  17.   160   Input"Enter the number of your choice. ",Command$
  18.   170   If Command$="" Then Goto Menu
  19.   180   I=Val(Command$)
  20.   190   On I Goto No'numbers,Add'numbers,New
  21.   200   Goto 160
  22.   210 *No'numbers
  23.   220   Gosub Enter'input
  24.   230   If Basicfile1$="" Then Goto Menu
  25.   240   Gosub Enter'output
  26.   250   If Basicfile2$="" Then Goto Menu
  27.   260   @ : @"Deleting numbers........"
  28.   270   On Error Goto Error'report
  29.   280   On Esc Goto Escape
  30.   290   Open\1,128,1\Basicfile1$(-1)
  31.   300   Open\2,128,2\Basicfile2$(-1)
  32.   310   Rec1=0
  33.   320   Rec2=0
  34.   330   J=0
  35.   340     Repeat
  36.   350     Get\1,Rec1\Buffer1$(-1)
  37.   360       For I=0 To 127
  38.   370       Buffer2$(J,J)=Buffer1$(I,I)
  39.   380       J=J+1
  40.   390       If J=128 Then Gosub Output'record
  41.   400       If Asc(Buffer1$(I,I))=10 Then  Do
  42.   410         I=I+6
  43.   420         If I>127 Then  Do
  44.   430           Rec1=Rec1+1
  45.   440           Get\1,Rec1\Buffer1$(-1)
  46.   450           I=I-128
  47.   460           Enddo
  48.   470         Enddo
  49.   480       Next I
  50.   490     Rec1=Rec1+1
  51.   500     Until Iostat(1,0)>0
  52.   510   Close\1\
  53.   520   Buffer2$(J,J)=Chr$(27)
  54.   530   Put\2,Rec2\Buffer2$(-1)
  55.   540   @ Buffer2$(-1)
  56.   550   Close\2\
  57.   560   On Esc Stop
  58.   570   On Error Stop
  59.   580   Goto Menu
  60.   590 *Add'numbers
  61.   600   Gosub Enter'input
  62.   610   If Basicfile1$="" Then Goto Menu
  63.   620   Gosub Enter'output
  64.   630   If Basicfile2$="" Then Goto Menu
  65.   640   @ : @"Adding numbers......."
  66.   650   On Error Goto Error'report
  67.   660   On Esc Goto Escape
  68.   670   Open\1,128,1\Basicfile1$(-1)
  69.   680   Open\2,128,2\Basicfile2$(-1)
  70.   690   Line=0
  71.   700   Rec1=0
  72.   710   Rec2=0
  73.   720   J=0
  74.   730     Repeat
  75.   740     Get\1,Rec1\Buffer1$(-1)
  76.   750       For I=0 To 127
  77.   760       Buffer2$(J,J)=Buffer1$(I,I)
  78.   770       J=J+1
  79.   780       If J=128 Then Gosub Output'record
  80.   790       If Asc(Buffer1$(I,I))=10 Then  Do
  81.   810         Line=Line+10
  82.   820         Gosub Number'line
  83.   830           For K=0 To 4
  84.   840           Buffer2$(J,J)=Line'number$(K,K)
  85.   850           J=J+1
  86.   860           If J=128 Then Gosub Output'record
  87.   870           Next K
  88.   890         Enddo
  89.   900       Next I
  90.   910     Rec1=Rec1+1
  91.   920     Until Iostat(1,0)>0
  92.   930   Close\1\
  93.   933   Buffer2$(J,J)=Chr$(27)
  94.   940   Put\2,Rec2\Buffer2$(-1)
  95.   950   @ Buffer2$(-1)
  96.   960   Close\2\
  97.   970   On Error Stop
  98.   980   On Esc Stop
  99.   990   Goto Menu
  100.  1050 *New
  101.  1060   Stop
  102.  1070   End
  103.  1080 *Enter'input
  104.  1090   @ : Input"Enter the name of the file to read from. ",Basicfile1$(-1)
  105.  1100   If Basicfile1$="" Then Return
  106.  1110   @ : @"Checking........"
  107.  1120   Set 3,0
  108.  1130   On Error Goto 1160
  109.  1140   Open\1\Basicfile1$(-1)
  110.  1150   Close\1\
  111.  1160   If Sys(3)=0 Then Return
  112.  1170   @"You cannot OPEN this file."
  113.  1180   @"Error no. ";Sys(3);" has occured."
  114.  1190   @"Enter another name or press RETURN. ";
  115.  1200   Goto Enter'input
  116.  1210 *Enter'output
  117.  1220   @ : Input"Enter the name of the file to write to. ",Basicfile2$(-1)
  118.  1230   If Basicfile2$="" Then Return
  119.  1240   @ : @"Creating file.........."
  120.  1250   Set 3,0
  121.  1260   On Error Goto 1280
  122.  1270   Erase Basicfile2$
  123.  1280   Create Basicfile2$
  124.  1290   Return
  125.  1300 *Error'report
  126.  1310   Close
  127.  1315   On Error Stop
  128.  1316   On Esc Stop
  129.  1320   @"Error no. ";Sys(3);" has occured."
  130.  1330   Input"Press RETURN to go on. ",Command$
  131.  1340   Goto Menu
  132.  1350 *Escape
  133.  1360   Close
  134.  1365   On Error Stop
  135.  1370   On Esc Stop
  136.  1380   Goto Menu
  137.  1390 *Number'line
  138.  1400   Line$=Str$(Line)
  139.  1410   K=Len(Line$)
  140.  1420   Line'number$="     "
  141.  1430   Line'number$(5-K,4)=Line$
  142.  1440   Return
  143.  1450 *Output'record
  144.  1460   Put\2,Rec2\Buffer2$(-1)
  145.  1470   @ Buffer2$(-1);
  146.  1480   Buffer2$(-1)=""
  147.  1490   Rec2=Rec2+1
  148.  1500   J=0
  149.  1510   Return
  150.