-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTEXTOUT.BAS
More file actions
140 lines (107 loc) · 4.83 KB
/
Copy pathTEXTOUT.BAS
File metadata and controls
140 lines (107 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'****************************************************************************
' TEXTOUT.BAS - Source for TEXTOUT.COM
' by Don Malin
' (c) 1990, 1991 Crescent Software, Inc.
'
' Purpose: Extracts quoted strings and optionaly comments from a BASIC
' source file and writes them to a file with the same base name as the
' source file but with an ".SPL" extension. This file can be run through
' any spell checking program or used to translate program messages into
' another language.
'
' From DOS type: TEXTOUT FileName[.BAS] [/c]
'
' "/c" specifies extracting comments
'----------------------------------------------------------------------------
' Compile and link with P.D.Q. and QuickPak Pro as follows:
' bc TEXTOUT /O;
' link /NOD TEXTOUT,, NUL, PDQ PRO;
' exe2com TEXTOUT
'****************************************************************************
DEFINT A-Z
DECLARE FUNCTION Null% (Text$) 'Pro routine determines if a
' string is blank
'$INCLUDE: '\pdq\pdqdecl.bas'
'$LIST OFF
Qt$ = CHR$(34) 'Quotation mark character "
PRINT "Source Text Extraction Program"
PRINT "(c) 1990, 1991 Crescent Software, Inc."
PRINT
'~~~~~ Get the names of files to work with
Source$ = COMMAND$ 'Copy the command line arg.
GOSUB FixSourceName 'Extract "/C" command switch
IF LEN(Source$) = 0 THEN 'No file given?
PRINT "Source file name: "; 'Ask the user for a name
PDQInput Source$
GOSUB FixSourceName
IF LEN(Source$) = 0 THEN END
END IF
Per = INSTR(Source$, ".") 'Look for a period in name
IF Per THEN 'Create the names for files
Dest$ = LEFT$(Source$, Per) + "SPL"
ELSE
Dest$ = Source$ + ".SPL"
Source$ = Source$ + ".BAS"
END IF
'~~~~~ Open the needed files
OPEN Source$ FOR INPUT AS #1 'Open the Source file (.BAS)
OPEN Dest$ FOR OUTPUT AS #2 'Open the Text file (.SPL)
PRINT "Extracting text from " + Source$ + " to " + Dest$ + " ...";
CurLine = 0 'Initialize line number
'~~~~~ Read the source file until done
DO UNTIL EOF(1)
Text$ = "" 'Initialize the source line $
DO
LINE INPUT #1, Buf$ 'Read a line of source code
Text$ = Text$ + Buf$ 'Add chars. to Source line
LOOP WHILE RIGHT$(Text$, 1) = "_" 'Go back for more if needed
CurLine = CurLine + 1 'Bump the source line number
RemPos = 1 'Find remarks or end of line
GOSUB FindRemark
'~~~~~ Look for quoted strings to extract
Quote = 0 'No quote yet
DO
Quote = INSTR(Quote + 1, Text$, Qt$) 'Look for left quote
'If there is one and it's to
IF Quote > 0 AND Quote < Remark THEN ' the left of remarks,
Quote2 = INSTR(Quote + 1, Text$, Qt$) ' find the right-hand quote
IF Quote2 > Remark THEN 'If there is a remark char.
RemPos = Quote2 ' inside quotes, find next
GOSUB FindRemark ' remark char.
END IF
IF Quote2 = 0 THEN Quote2 = Remark 'No right quote, use length
IF Quote2 - Quote - 1 THEN 'If it's not a NUL string ("")
'Extract the quoted text
QStr$ = MID$(Text$, Quote + 1, Quote2 - Quote - 1)
'IF NOT Null(QStr$) THEN 'If it's not blank, write it
' to the ".SPL" file
PRINT #2, STR$(CurLine); ": "; Qt$; QStr$; Qt$
'END IF
END IF
Quote = Quote2 'Set position to look for
' another quoted string.
END IF
LOOP WHILE Quote
IF RemSwitch THEN
IF Remark < LEN(Text$) THEN
PRINT #2, STR$(CurLine); ": "; MID$(Text$, Remark)
END IF
END IF
LOOP
LOCATE CSRLIN, 1 'Tell the user what we did.
PRINT Dest$ + " has been created. "
END
'~~~~~ Find remarks or end of line
FindRemark:
Remark = INSTR(RemPos, Text$, "'")
IF Remark = 0 THEN Remark = INSTR(RemPos, UCASE$(Text$), "REM")
IF Remark = 0 THEN Remark = LEN(Text$)
RETURN
'~~~~~ Look for "/C" switch and trim the source file name
FixSourceName:
RemSwitch = INSTR(UCASE$(Source$), "/C")
IF RemSwitch THEN
Source$ = LEFT$(Source$, RemSwitch - 1) + MID$(Source$, RemSwitch + 2)
Source$ = UCASE$(LTRIM$(RTRIM$(Source$)))
END IF
RETURN