Utility

by David Goben

In Search of Lost Superscripsit Files

Reconstruct crashed Superscripsit files with a minimum of fuss.

Superscripsit ftle crashes happen in a couple of ways: Bad disk media can cause a sector to become unreadable, or you can exit the program in the midst of writing a file, causing an end-of-flle error when you try to reload it. You can recover these flies, but first you must understand how they are set up.

Unlike most word processors. Superscripsit saves flies as blocks of text. Each text block consists of four disk sectors. Superscripsit places data pointers within the first sector of each block, allowing the block to hold almost IK of data. A single ftle can hold a maximum of 255 blocks, numbered zero-254. four of which are reserved for header and footer information. Six additonal sectors provide the file header. A Superscipsit file, therefore, has a maximum length of 1,026 sectors, or about 256.5K of disk space.

The first file-header sector contains general information about the text such as the author's comments, the file's printer driver, line-spacing defaults, which blocks contain the header and footer information, and all other information that is displayed when you open the text file. The first byte of this sector is EO hexadecimal (hex), indicating that it is a Superscripsit file.

The next five sectors house the file's index. Superscripsit adds one to the value of the first byte of the first sector of the index area to determine how many blocks the file contains. Five-byte clusters of block information follow.

The cluster's first byte gives the block name. The program multiplies this value by four and increases the result by six to

System Requirements

Model I/m/4 32K RAM

Basic One disk drive Superscripsit

You can recover a lost document by using the index information to rebuild the file order.

determine which relative sector within the block begins the file.

Adding seven to the next byte, which is equal to the first byte in the first sector of the corresponding block, gives you the relative-byte address within the block of the last sector containing data relevant to the text.

The next byte, which corresponds to the second byte in the first sector of the corresponding block, tells the system how many of the four possible sectors the file occupies. The four sectors are numbered zero-3. The next byte tells the system how many lines of text are in the block. The last byte is a system flag. The list terminates with block FF hex.

Header and footer indexing works somewhat differently. Block names are only reserved for odd-footer, odd-header, even-footer, and even-header sequences that start at relative byte 72 hex in the first file sector. If the first byte in the first sector of a block is zero, it is a header or footer block. Its second byte is always three, and FF hex always terminates its text.

You can recover a lost document either by using the index information to rebuild the file in order (blocks are not always grouped sequentially, which is the reason for the index), or if the index sectors are defective, by creating a sequential listing

Program Listing 1. Recover.

10 CLS: PRINT"-------------------------------" ' » 2273

20 PRINT"- SuperSCRIPSIT File Recovery '* 3196

30 PRINT"- Written by: David Goben -" '* 2979

50 PRINT"- Mansfield Center, CT 05250 -" ** 2851

60 IF PEEK(5)=0 THEN CLEAR ELSE CLEAR 500 *• 2472

70 print"-------------------------------": print '* 2450

80 DEFINT A-Z:MD«1:IF PEEK(5)<>0 THEN IF PEEK(293)<>73 THEN MD=0 '* 3876

90 GOTO 140 631

100 IF RB-256 THEN 120 ELSE IF RBOBR OR RSOSR THEN D=PEEK(PT+RB)

110 RS-0:RB-0:GOSUB 130:IF (RG>LG AND CR=1) OR LP>LG THEN 340 ELSE GET 1,RG*4+7:ET-0:GOSUB 100:IF D=0 THEN 110 ELSE BR«D+7:G0SUB 100:SR=D:RB-7:GOTO 100 '* 9201

120 RB»0:IF RS«SR THEN 110 ELSE RS-RS+1:GET 1,RS+RG*4+7:GOTO 160 3925

130 IF CR THEN RG-RG+1:RETURN ELSE LP-LP+1:RG-ASC(MID$(LOS,LP,1)):

140 FS$«"":LINE INPUT'Type in the FILESPEC of the File to RECOVER: ";FS$:IF FS$=""THEN 140 ELSE ON ERROR GOTO 150:0PEN"I",1,FS$: CLOSE:GOTO 160 '* 9490

150 PRINT FS$" cannot be found!":PRINT:RESUME 140 '* 3538

160 FD$-"":LINE INPUT"Type in the FILESPEC of the OUTPUT File : " ;FD$:IF FD$«""THEN 160 ELSE D$«"":F$«FS$:X=INSTR(F$,":"):IF X THEN F$-LEFT$(F$,X-1):D$«MID$(FS$,X+l) 10539

170 Dl$="":Fl$»FD$:X=INSTR(Fl$,":"):IF X THEN FlS-LEFTS(FlS,X-l):D

180 IF FSOFIS OR (FS-F15 AND D$ODl$ AND D$<>"" AND D1$<>"")THEN

190 ELSE PRINT'DUPLICATE FILE NAMES! ILLEGAL 1":G0T0 240 '* 7075

190 ON ERROR GOTO 200:0PEN"0",2,FD$:GOTO 210 '» 2665

200 PRINT FDS" is Illegal 1":PRINT:RESUME 160 3025

210 ON ERROR GOTO 430:0PEN"R",1,FS$:FIELD 1,1 AS D$:P!-PEEK(VARPTR (D$)+1)+256*PEEK(VARPTR(D$)+2):IF P!>32767 THEN PT=P!-65536! E LSE PT=P1 8189

Listing continued of the file and then correcting the discrepancies in the text.

Recover

I wrote Recover (Program Listing 1). which operates under Model I/1II/4 Disk Basic, to reconstruct Superscripsit files using whichever method yields the best results. It asks you for the filespec of the defective file and then asks for the output filespec. which is an ASCII conversion of the file. Once Recover receives this data, it tries to build a reconstruction table from the information in the index area of the defective file. If it accomplishes this. Recover rebuilds the file in its proper order. If any of the used index sectors are defec-

To reconstruct files, Recover uses whichever method yields the best results.

tive. Recover tries to reconstruct the file sequentially.

If the index sectors are unreadable, you can still use Recover to gather enough in formation about each block to reconstruct the file. Success depends on your knowing the following facts.

• Each block is four sectors long.

• By adding seven to the first byte of each block you can tell where, in the last used sector of the block, the text data ends.

• The value of the second byte of each block is one less than the number of sectors the block occupies.

• The values of the first and second bytes of each block are the same as those of the second and third bytes in the index cluster that references the block.

• Text does not begin until after the seventh byte of the first sector of a block.

• If a block begins with byte value zero (does not give an offset value for the end of data in its final occupied sector), it is a header or footer block. You should ignore such blocks during recovery.

• If blocks are not stored in sequential order. you must move the text into proper sequence after recovery.

• If a sector is unreadable. Recover tries to read it four times before reporting the problem and proceeding to the next sector.

When the program recovers a file, it stores the data in a destination file in ASCII format. Convert the data back to Superscripsit format as follows.

• Create a new Superscripsit file with a different name.

• Arrange the file's framework (such as line spacing and margins).

• Select the ASCII conversion option at Superscripsit's main menu.

• Answer the prompt asking from which format you want to convert with "A" for ASCII.

• Answer the Superscripsit file-name prompt with the new Superscripsit file's name.

• Answer the ASCII file-name prompt with the recovered file's name.

When the conversion is complete, edit the new file and insert any special features. such as centering and underlining, that Recover deleted.

A Bonus

Program Listing 2. Convert, is a bonus. It converts Model I or III Superscripsit files to run under Model 4 Superscripsit. The files are not normally compatible because Models I and III use small blocks in the first sectors of their files as line markers, and the Model 4 uses underscores. Convert changes the small blocks to underscores. You can reverse the process (allow Models I and III to read Model 4 files) by switching the values of variables B$ and G$ at the end of line 90. ■

David Go ben is a programming consultant and frequent contributor to 90 Micro. Address questions and comments to him at 67 Highland Road. Mansfield Center. CT 06250.

Listing continued

220 ON ERROR GOTO 450»GBT 1,1»IF PEEK(PT)-4HE0 THEN 250 ELSE PRINT

•The SOURCE File is NOT a Super SCR IPSIT File!" '* 7641

230 CLOSE:KILL FD$ 1119

240 ON ERROR GOTO 0:END 1463

250 CR = 0:LP-0:ON ERROR GOTO 460»PRINT:PRINT'Picking up Pile Block Clusters...":HD$"CHR$(254)+CHRS(253)+CHRS(239)+CHRS(247)+CHRS( 2 48)+CHRS(245)+CHR$(242):L0$»""»GET 1,2»LG-PEEK(PT):RS—5:RB-1 :SR-7:RG-0:BR-257 13275

260 X=LG*5+1»Y«X/256»X»X-Y*256»GET l,Y+2 :D-PEEK (PT+X) .-GET 1,2:IF D <>255 THEN PRINT"Index Data Confused. End of File Mixup caused here. Correcting...' '* 18827

278 GOSUB 108:IF D<255 THEN LOS-LOS+CHRS(D)»FOR Y-l TO 4:GOSUB 100 :NEXT Y:GOTO 270 ELSE LG-LEN(LOS):IF LG-8 THEN PRINT"Text File is Null":G0T0 240 '* 9464

280 IF ASC(MIDS(LOS,LG,l))*4+7>L0F(1)THEN LG-LG-1:IF LG THEN 280 E

LSE PRlNT'File Totally Unreadable I Aborting":G0T0 240 8231

290 PRINT:ET«0:0N ERROR GOTO 4 40 : BR-255 : SR-BR :RG—1 3295

300 GOSUB 130:RS«0:RB=0:GET 1,RG*4+7»ET=8»GOSUB 100»IF D-0 THEN 30

310 GOSUB 188 741

328 IF INSTR(HDS,DS) THEN ON INSTR(HD$,D$) GOTO 118,350,370,388,39

8,410,428 4225

330 IF D<32 OR D>127 THEN 310 ELSE PRINT42,D$;:PRINT DS»«GOTO 310 '* 3861 340 PRINTI2,CHRS<8)I«CLOSE»PRINT»PRINTsGOTO 248 •• 3849

358 PRINTJ2,CHRS(13)j:PRINT CHR$(140) '* 2181

360 GOSUB 100<IF D<>239 THEN 360 ELSE 320 '* 2357

378 GOSUB 1001IF D-255 THEN 340 ELSE 320 '* 2293

380 PRINTI2," "I:PRINT" "«»GOTO 310 '* 2101

400 IF MD THEN OUT 244,1»GOTO 310 ELSE POKE 14385,1»GOTO 310 3538

410 GOSUB 100»GOTO 310 1293

420 PRINT#2,CHRS(9)«»PRINT CHRS<9)»«GOTO 310 •• 2654

430 PRINT'There Is a problem OPENing *FSS'. Check your files befor e trying again.'»RESUME 238 7531

440 ET-ET+1»IF ET<4 THEN RESUME ELSE ET-0»PRINT»PRINT»PRINT"»**** FOUND A BAD DATA SECTOR. NOW SKIPPING SOME DATA *••*»'»PRINT:I F RS-0 THEN SR-3»BR-255»RESUME 120 ELSE RESUME 120 '* 11388

450 PRINT'The 1st sector of "FSS" is bombed. Assuming SuperSCRIPSI

460 PRINT"Information in the Index Clusters is CRASHED I"»PRI NT"Now calculating data by PREDICTING pointers "»PRINT'NOTE tha t some editing may be required by YOU after"»PRINT'the file is converted back to SuperSCRIPSIT format " '* 19839

470 INPUT'Press <ENTER> to continue"«DS::CR-1»LG«(LOF(1)-6)/4»RESU

HE 290 5824

Program Listing 2. Convert.

10 'SUPERSCRIPSIT DOCUMENT CONVERSION -- MODEL I/III TO MODEL 4 20 'WRITTEN BY » DAVID GOBEN 30 '

40 CLEAR»DEFI NT A-Z:CLS

50 PRI NT"SuperSCR I PSIT Document Conversion — Model I/III to Mod el 4"»PRINT

60 ANS*""»LINE INPUT'Type in the FILESPEC for the file to conver t: "«ANS

70 IF ANSm""THEN 60 ELSE ON ERROR GOTO 88»OPEN'I",1,ANS»CLOSE»GO TO 90

80 PRINT ERRSSsGOTO 70

90 OPEN'R",1,ANS:FIELD 1,255 AS AS»BS«CHRSUH84)»GS=CHR$(tH5F) 100 ON ERROR GOTO 0 »GET 1,1»CS=AS

110 X-INSTR(CS,B$)sif X THEN M1DS(CS,X,1)-GS:GOTO 110 120 LSET AS-CS»PUT 1,1»CLOSE 1»END

• *

0 0

Post a comment