Refactored to eliminate duplicate spaces between two tokens, handle Business BASIC text exportation the same as RTF

This commit is contained in:
2009-01-03 05:48:26 +00:00
parent 51f442d291
commit 20c92bc931
4 changed files with 59 additions and 48 deletions

View File

@ -53,7 +53,8 @@ public class BusinessBASICFileFilter implements FileFilter {
PrintWriter printWriter = new PrintWriter(byteArray, true);
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(fileEntry);
boolean firstLine = true;
int nest = 0;
boolean firstData = true;
int nestLevels = 0;
while (tokenizer.hasMoreTokens()) {
BusinessBASICToken token = tokenizer.getNextToken();
if (token == null) {
@ -64,22 +65,30 @@ public class BusinessBASICFileFilter implements FileFilter {
} else {
printWriter.println();
}
firstData = true;
printWriter.print(token.getLineNumber());
if (nest > 0) {
for (int i = 1; i < nest; i++)
printWriter.print(" "); //$NON-NLS-1$
if (nestLevels > 0) {
for (int i = 0; i < nestLevels; i++)
printWriter.print(" "); //$NON-NLS-1$
}
/*
if (token.isIndenter())
nest ++;
else if (token.isOutdenter())
nest --;
*/
//printWriter.print(" "); //$NON-NLS-1$
} else if (token.isToken()) {
if (!firstData)
printWriter.print(" "); //$NON-NLS-1$
printWriter.print(token.getTokenString());
firstData = false;
if (token.isIndenter()) {
nestLevels ++; }
else if (token.isOutdenter()) {
nestLevels --; }
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
printWriter.print(token.getStringValue());
firstData = true;
} else {
printWriter.print(" "+token.getStringValue());
if (!firstData)
printWriter.print(" "); //$NON-NLS-1$
printWriter.print(token.getStringValue().trim());
firstData = false;
}
}
printWriter.close();

View File

@ -1,7 +1,7 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2002-2004 by Robert Greene
* robgreene at users.sourceforge.net
* Copyright (C) 2008 by David Schmidt
* david__schmidt at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -33,7 +33,7 @@ import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
/**
* Provides a view of a syntax-colored Apple /// Business BASIC program listing.
*
* @author Rob Greene
* @author David Schmidt
*/
public class BusinessBASICFilterAdapter extends FilterAdapter {
private StyledText styledText;
@ -84,29 +84,31 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
}
firstData = true;
styledText.append(Integer.toString(token.getLineNumber()));
styledText.append(" "); //$NON-NLS-1$
styledText.append(" "); //$NON-NLS-1$
if (nestLevels > 0) {
for (int i = 0; i < nestLevels; i++)
styledText.append(" "); //$NON-NLS-1$
}
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
styledText.append(token.getStringValue());
firstData = false;
firstData = true;
} else if (token.isEndOfCommand()) {
styledText.append("\n"); //$NON-NLS-1$
firstData = false;
} else if (token.isString()) {
if (firstData)
if (!firstData)
styledText.append(" "); //$NON-NLS-1$
int caretOffset = styledText.getCharCount();
styledText.append(token.getStringValue());
styledText.append(token.getStringValue().trim());
StyleRange styleRange = new StyleRange();
styleRange.start = caretOffset;
styleRange.length = token.getStringValue().length();
styleRange.length = token.getStringValue().trim().length();
styleRange.foreground = getGreenColor();
styledText.setStyleRange(styleRange);
firstData = false;
} else if (token.isToken()) {
if (!firstData)
styledText.append(" "); //$NON-NLS-1$
int caretOffset = styledText.getCharCount();
styledText.append(token.getTokenString());
StyleRange styleRange = new StyleRange();

View File

@ -51,11 +51,11 @@ public class BusinessBASICToken {
}
public boolean isIndenter() {
return isToken() && tokenString.equals(" FOR "); //$NON-NLS-1$
return isToken() && tokenString.equals("FOR"); //$NON-NLS-1$
}
public boolean isOutdenter() {
return isToken() && tokenString.equals(" NEXT "); //$NON-NLS-1$
return isToken() && tokenString.equals("NEXT"); //$NON-NLS-1$
}
/**

View File

@ -40,33 +40,33 @@ import com.webcodepro.applecommander.storage.FileEntry;
*/
public class BusinessBASICTokenizer {
private static String tokens[] = { // starts at $80
" END ", " FOR ", " NEXT ", " INPUT ", " OUTPUT ", " DIM ", " READ ", " WRITE ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" OPEN ", " CLOSE ", " *error* ", " TEXT ", " *error* ", " BYE ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " WINDOW ", " INVOKE ", " PERFORM ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" FRE ", " HPOS ", " VPOS ", " ERRLIN ", " ERR ", " KBD ", " EOF ", " TIME$ ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" DATE$ ", " PREFIX$ ", " EXFN. ", " EXFN%. ", " OUTREC ", " INDENT ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " POP ", " HOME ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" SUB$( ", " OFF ", " TRACE ", " NOTRACE ", " NORMAL ", " INVERSE ", " SCALE( ", " RESUME ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " LET ", " GOTO ", " IF ", " RESTORE ", " SWAP ", " GOSUB ", " RETURN ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" REM ", " STOP ", " ON ", " *error* ", " LOAD ", " SAVE ", " DELETE ", " RUN ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" RENAME ", " LOCK ", " UNLOCK ", " CREATE ", " EXEC ", " CHAIN ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " CATALOG ", " *error* ", " *error* ", " DATA ", " IMAGE ", " CAT ", " DEF ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " PRINT ", " DEL ", " ELSE ", " CONT ", " LIST ", " CLEAR ", " GET ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" NEW ", " TAB ", " TO ", " SPC( ", " USING ", " THEN ", " *error* ", " MOD ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" STEP ", " AND ", " OR ", " EXTENSION "," DIV ", " *error* ", " FN ", " NOT ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " tf7 ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" TAB( ", " TO ", " SPC( ", " USING ", " THEN ", " *error* ", " MOD ", " STEP ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" AND ", " OR ", " EXTENSION "," DIV ", " *error* ", " FN ", " NOT ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " AS ", " SGN( ", " INT( ", " ABS( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " TYP( ", " REC( ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " PDL( ", " BUTTON( ", " SQR( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" RND( ", " LOG( ", " EXP( ", " COS( ", " SIN( ", " TAN( ", " ATN( ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", " *error* ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" *error* ", " *error* ", " *error* ", " STR$( ", " HEX$( ", " CHR$( ", " LEN( ", " VAL( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" ASC( ", " TEN( ", " *error* ", " *error* ", " CONV( ", " CONV&( ", " CONV$( ", " CONV%( ", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
" LEFT$( ", " RIGHT$( ", " MID$( ", " INSTR$( ", " *error* ", " *error* ", " *error* ", " *error* "};//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"END", "FOR", "NEXT", "INPUT", "OUTPUT", "DIM", "READ", "WRITE", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"OPEN", "CLOSE", "*error*", "TEXT", "*error*", "BYE", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "WINDOW", "INVOKE", "PERFORM", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"FRE", "HPOS", "VPOS", "ERRLIN", "ERR", "KBD", "EOF", "TIME$", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"DATE$", "PREFIX$", "EXFN.", "EXFN%.", "OUTREC", "INDENT", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "*error*", "*error*", "POP", "HOME", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"SUB$(", "OFF", "TRACE", "NOTRACE", "NORMAL", "INVERSE", "SCALE(", "RESUME", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "LET", "GOTO", "IF", "RESTORE", "SWAP", "GOSUB", "RETURN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"REM", "STOP", "ON", "*error*", "LOAD", "SAVE", "DELETE", "RUN", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"RENAME", "LOCK", "UNLOCK", "CREATE", "EXEC", "CHAIN", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "CATALOG", "*error*", "*error*", "DATA", "IMAGE", "CAT", "DEF", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "PRINT", "DEL", "ELSE", "CONT", "LIST", "CLEAR", "GET", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"NEW", "TAB", "TO", "SPC(", "USING", "THEN", "*error*", "MOD", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"STEP", "AND", "OR", "EXTENSION"," DIV", "*error*", "FN", "NOT", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "tf7", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"TAB(", "TO", "SPC(", "USING", "THEN", "*error*", "MOD", "STEP", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"AND", "OR", "EXTENSION"," DIV", "*error*", "FN", "NOT", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "*error*", "AS", "SGN(", "INT(", "ABS(", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "TYP(", "REC(", "*error*", "*error*", "*error*", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "*error*", "*error*", "PDL(", "BUTTON(", "SQR(", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"RND(", "LOG(", "EXP(", "COS(", "SIN(", "TAN(", "ATN(", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "*error*", "*error*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"*error*", "*error*", "*error*", "STR$(", "HEX$(", "CHR$(", "LEN(", "VAL(", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"ASC(", "TEN(", "*error*", "*error*", "CONV(", "CONV&(", "CONV$(", "CONV%(", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
"LEFT$(", "RIGHT$(", "MID$(", "INSTR$(", "*error*", "*error*", "*error*", "*error*"};//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
private byte[] fileData;
private int offset = 2;