80 REM **    **************
85 REM **      SCTOVC.BAS
90 REM **    **************
95 REM **  by Paul D. Bullock
100 PRINT"*******************************************"
110 PRINT"*******************************************"
120 PRINT"***                                     ***"
130 PRINT"***  THIS PROGRAM READS A SUPERCALC     ***"
140 PRINT"***  PRINT FILE AND CREATES A VISICALC  ***"
150 PRINT"***  DIF FILE WHICH CAN BE USED TO      ***"
160 PRINT"***  CREATE A VISICALC SPREADSHEET      ***"
170 PRINT"***  MUCH LIKE THE ORIGINAL             ***"
180 PRINT"***             NOTE                    ***"
200 PRINT"***  THE VISICALC COLUMN WIDTH SHOULD   ***"
210 PRINT"***  BE SET TO THE MAXIMUM WIDTH OF THE ***"
220 PRINT"***  SUPERCALC COLUMNS AND THE          ***"
230 PRINT"***  PRINT FILE MUST BE SAVED WITH      ***"
235 PRINT"***  THE BORDER ON. YES, BORDER ON!!    ***"
236 PRINT"***  WHEN CREATING THE PRINT FILE       ***"
237 PRINT"***  THE PRINT COLUMN WIDTH MUST BE     ***"
238 PRINT"***  SET TO HANDLE THE SHEET WIDTH      ***"
240 PRINT"*******************************************"
250 PRINT"*******************************************"
260 REM ** THIS PROGRAM HAS IT'S ROOTS IN
270 REM ** THE "CREATING A DIF FILE" FROM
280 REM ** SATN-18 "THE PROGRAMMER'S GUIDE
290 REM ** TO DIF" BY SOFTWARE ARTS,INC
300 REM ** DATED 1980
500 DIM CW(100):REM ** ARRAY FOR COLUMN WIDTHS
510 Q$="":REM ** Q$ IS EMPTY STRING
1000 PRINT"FILE NAME OF EXISTING SUPERCALC"
1010 PRINT"PRINT FILE - INCLUDE .PRN"
1020 INPUT F$
1022 PRINT"FILE NAME OF VISICALC DIF FILE"
1024 PRINT"THAT WILL BE CREATED - INCLUDE .DIF"
1026 INPUT G$
1030 OPEN "I",1, F$
1035 OPEN "O",2,G$
1036 PRINT"ENTER THE NUMBER OF SUPERCALC ROWS"
1038 INPUT NT
1040 PRINT"ENTER NUMBER OF SUPERCALC COLUMNS"
1045 INPUT NV
1047 TW=0
1050 FOR I = 1 TO NV
1060   PRINT"ENTER WIDTH OF COLUMN #";I;" ";
1062   INPUT CW(I)
1063   TW=TW+CW(I):REM ** CALCULATE TOTAL WIDTH
1064 NEXT I
1070 GOSUB 3000:REM ** WRITE OUT DIF HEADER
1080 FOR I=1 TO NT+2
1084   REM ** FIRST TWO ROWS ARE BORDER, THROW AWAY
1085   IF I<3 THEN INPUT #1,L$: GOTO 1200
1090   T=-1:V#=0:S$="BOT":REM ** OUTPUT BEGINNING OF TUPLE
1092   GOSUB 4000
1093   INPUT #1,L$:REM ** STRIP OFF LEFT BORDER
1094   IF MID$(L$,1,1)<>"|" THEN L$=MID$(L$,2,LEN(L$)-1):GOTO 1094
1096   L$=MID$(L$,2,LEN(L$)-1)
1104   SUM = 1
1106   FLAG=0
1110   FOR J=1 TO NV
1120     IF FLAG=1 THEN T=1:V#=0:S$=Q$:GOTO 1170
1130     S$=MID$(L$,SUM,CW(J)):REM ** OBTAIN CELL INFO
1133 REM ** SET FLAG IF REST OF LINE IS BLANK
1135     IF CW(J)+SUM>=LEN(L$) THEN FLAG = 1
1140     GOSUB 5000:REM ** IS S$ A 'STRING' OR 'NUMBER'
1170     SUM=SUM+CW(J):REM ** INCREMENT ACROSS ROW
1180     GOSUB 4000:REM ** OUTPUT DATA VALUES
1190   NEXT J
1195   PRINT "ROW #";I-2;" COMPLETE"
1200 NEXT I
1210 T=-1:V#=0:S$="EOD":REM ** OUTPUT END OF DATA
1220 GOSUB 4000
1230 CLOSE
1240 PRINT"FINISHED CREATING DIF FILE ";G$
1250 END
3000 REM ** ROUTINE TO WRITE OUT DIF HEADER
3010 PRINT#2,"TABLE":PRINT#2,"0,1":GOSUB 3500
3020 PRINT#2,"TUPLES":PRINT#2,"0,";NT:GOSUB 3500
3030 PRINT#2,"VECTORS":PRINT#2,"0,";NV:GOSUB 3500
3040 PRINT#2,"DATA":PRINT#2,"0,0":GOSUB 3500
3050 RETURN
3500 REM ** SUBROUTINE TO WRITE "" (NULL STRING)
3510 PRINT#2,CHR$(34);CHR$(34)
3520 RETURN
4000 REM ** ROUTINE TO WRITE OUT DATA VALUE
4010 PRINT #2,T;",";V#
4012 IF S$="BOT" OR S$="V" OR S$="EOD" THEN PRINT #2,S$:RETURN
4014 REM ** WRITE STRING TO DISK SURROUNDED BY QUOTES
4020 PRINT #2,CHR$(34)+S$+CHR$(34)
4030 RETURN
4040 END
5000 REM ** THIS SUBROUTINE DETERMINES WHETHER
5010 REM ** S$ IS A 'STRING' OR A 'NUMBER'
5012 REM ** IT IS ASSUMED THAT IF S$
5014 REM ** CONTAINS ONLY NUMERIC VALUES
5015 REM ** OR A DECIMAL POINT AND IF THE
5016 REM ** CHARACTERS ARE TO THE
5018 REM ** RIGHTMOST PART OF THE STRING
5019 REM ** THEN S$ IS A NUMBER
5020 T=1:V#=0
5030 SS$=S$
5040 C$=LEFT$(SS$,1)
5050 IF C$=" " THEN SS$=RIGHT$(SS$,LEN(SS$)-1):GOTO 5040
5055 IF SS$="" THEN S$="" :RETURN
5060 FLAGG=0
5070 FOR M=1 TO LEN(SS$)
5080   C$=MID$(SS$,M,1)
5090   IF ASC(C$)<46 OR ASC(C$)>57 THEN FLAGG=1
5100   IF ASC(C$)=47 THEN FLAGG=1
5110 NEXT M
5120 IF FLAGG =0 THEN T=0:V#=VAL(S$):S$="V"
5130 RETURN
C$)>57 THEN FLAGG=1
5100   IF ASC(C$)=47 THEN FLAGG=1
5110 NEXT M
5120 IF 