Added line delimiters and directive prefix preferences

master
Marco Maccaferri 2019-01-02 11:19:44 +01:00
rodzic 8c950c335f
commit 9392b02e16
8 zmienionych plików z 178 dodań i 51 usunięć

Wyświetl plik

@ -1,21 +1,21 @@
;
; Hello World .BIN for MONITOR environment
;
; Hello World .BIN for MONITOR environment
;
; Upload as Intel HEX then type G5000 to run.
;
; ---------------------------------------------------------------------------
; Constant definitions
; ---------------------------------------------------------------------------
; Constant definitions
CHPUT .EQU 08H
; ---------------------------------------------------------------------------
; Compilation address
; ---------------------------------------------------------------------------
; Compilation address
.ORG 5000H
; ---------------------------------------------------------------------------
; Program code entry point
; ---------------------------------------------------------------------------
; Program code entry point
EXECUTE
LD HL, HELLOWORLD
@ -26,9 +26,9 @@ LOOP LD A, (HL)
INC HL
JR LOOP
; ---------------------------------------------------------------------------
; ---------------------------------------------------------------------------
; Data
HELLOWORLD .DB "Hello world!", 13, 10, 0
.END

Wyświetl plik

@ -1,31 +1,31 @@
;
; Hello World .COM for CP/M environment
;
; Upload as CP/M binary then type HELLOCPM to run.
;
; ---------------------------------------------------------------------------
; Constant definitions
BDOS .EQU 05H
STROUT .EQU 09H
; ---------------------------------------------------------------------------
; Compilation address, standard CP/M entry point
.ORG 0100H
; ---------------------------------------------------------------------------
; Program code entry point
EXECUTE LD DE, HELLOWORLD
LD C, STROUT
CALL BDOS
RET
; ---------------------------------------------------------------------------
; Data
HELLOWORLD .DB "Hello world!", 13, 10, "$"
.END
;
; Hello World .COM for CP/M environment
;
; Upload as CP/M binary then type HELLOCPM to run.
;
; ---------------------------------------------------------------------------
; Constant definitions
BDOS .EQU 05H
STROUT .EQU 09H
; ---------------------------------------------------------------------------
; Compilation address, standard CP/M entry point
.ORG 0100H
; ---------------------------------------------------------------------------
; Program code entry point
EXECUTE LD DE, HELLOWORLD
LD C, STROUT
CALL BDOS
RET
; ---------------------------------------------------------------------------
; Data
HELLOWORLD .DB "Hello world!", 13, 10, "$"
.END

Wyświetl plik

@ -865,6 +865,7 @@ public class Application {
formatter.setCommentColumn(preferences.getCommentColumn());
formatter.setLabelCase(preferences.getLabelCase());
formatter.setMnemonicCase(preferences.getMnemonicCase());
formatter.setDirectivePrefix(preferences.getDirectivePrefix());
tab.getEditor().replaceText(formatter.format());
@ -1622,10 +1623,11 @@ public class Application {
if (file.exists()) {
try {
String lineDelimiter = System.getProperty("line.separator");
BufferedReader reader = new BufferedReader(new FileReader(file));
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append("\n");
sb.append(lineDelimiter);
}
reader.close();
} catch (Exception e) {
@ -1778,8 +1780,21 @@ public class Application {
file = new File(fileName);
}
String text = tab.getEditor().getText();
switch (preferences.getLineDelimiters()) {
case 0:
text = text.replaceAll("(\r\n|\n|\r)", System.getProperty("line.separator"));
break;
case 1:
text = text.replaceAll("(\r\n|\n|\r)", "\r\n");
break;
case 2:
text = text.replaceAll("(\r\n|\n|\r)", "\n");
break;
}
Writer os = new OutputStreamWriter(new FileOutputStream(file));
os.write(tab.getEditor().getText());
os.write(text);
os.close();
if (saveAs || tab.getFile() == null) {

Wyświetl plik

@ -64,6 +64,7 @@ public class Preferences {
String editorFont;
boolean showLineNumbers;
boolean reloadOpenTabs;
int lineDelimiters;
String[] openTabs;
String selectedTab;
@ -72,6 +73,7 @@ public class Preferences {
int commentColumn;
int labelCase;
int mnemonicCase;
int directivePrefix;
boolean useTabstops;
int tabWidth;
@ -95,6 +97,7 @@ public class Preferences {
Preferences() {
showLineNumbers = true;
reloadOpenTabs = true;
lineDelimiters = 1;
tabWidth = 4;
mnemonicColumn = 16;
@ -172,6 +175,14 @@ public class Preferences {
this.reloadOpenTabs = reloadOpenTabs;
}
public int getLineDelimiters() {
return lineDelimiters;
}
public void setLineDelimiters(int lineDelimiters) {
this.lineDelimiters = lineDelimiters;
}
public String[] getOpenTabs() {
return openTabs;
}
@ -228,6 +239,14 @@ public class Preferences {
this.mnemonicCase = mnemonicCase;
}
public int getDirectivePrefix() {
return directivePrefix;
}
public void setDirectivePrefix(int directivePrefix) {
this.directivePrefix = directivePrefix;
}
public boolean isUseTabstops() {
return useTabstops;
}

Wyświetl plik

@ -46,6 +46,7 @@ public class PreferencesDialog extends Dialog {
Button rootRemove;
Button rootMoveUp;
Button rootMoveDown;
Combo lineDelimiters;
Text editorFont;
Button editorFontBrowse;
@ -59,6 +60,7 @@ public class PreferencesDialog extends Dialog {
Text commentColumn;
Combo labelCase;
Combo mnemonicCase;
Combo directivePrefix;
List includes;
Button includesAdd;
@ -262,6 +264,16 @@ public class PreferencesDialog extends Dialog {
reloadOpenTabs.setText("Reload open tabs");
reloadOpenTabs.setSelection(preferences.isReloadOpenTabs());
label = new Label(composite, SWT.NONE);
label.setText("Line delimiters");
lineDelimiters = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
lineDelimiters.setItems(new String[] {
"Platform",
"Windows (CR/LF)",
"Linux (LF)",
});
lineDelimiters.select(preferences.getLineDelimiters());
addSeparator(composite);
label = new Label(composite, SWT.NONE);
@ -543,6 +555,16 @@ public class PreferencesDialog extends Dialog {
"Lower",
});
mnemonicCase.select(preferences.getMnemonicCase());
label = new Label(composite, SWT.NONE);
label.setText("Directive prefix");
directivePrefix = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
directivePrefix.setItems(new String[] {
"No change",
"Add dot",
"Remove dot",
});
directivePrefix.select(preferences.getDirectivePrefix());
}
void addSeparator(Composite parent) {
@ -560,12 +582,14 @@ public class PreferencesDialog extends Dialog {
preferences.setTabWidth(Integer.valueOf(tabWidth.getText()));
preferences.setUseTabstops(useTabstops.getSelection());
preferences.setReloadOpenTabs(reloadOpenTabs.getSelection());
preferences.setLineDelimiters(lineDelimiters.getSelectionIndex());
preferences.setMnemonicColumn(Integer.valueOf(mnemonicColumn.getText()));
preferences.setArgumentColumn(Integer.valueOf(argumentColumn.getText()));
preferences.setCommentColumn(Integer.valueOf(commentColumn.getText()));
preferences.setLabelCase(labelCase.getSelectionIndex());
preferences.setMnemonicCase(mnemonicCase.getSelectionIndex());
preferences.setDirectivePrefix(directivePrefix.getSelectionIndex());
preferences.setIncludes(includes.getItems());
preferences.setGenerateBinary(generateBinary.getSelection());

Wyświetl plik

@ -10,6 +10,9 @@
package com.maccasoft.tools;
import java.util.HashSet;
import java.util.Set;
import nl.grauw.glass.AssemblyException;
import nl.grauw.glass.Line;
import nl.grauw.glass.Source;
@ -33,6 +36,8 @@ public class SourceFormatter {
public static final int NO_CHANGE = 0;
public static final int TO_UPPER = 1;
public static final int TO_LOWER = 2;
public static final int ADD_DOT = 1;
public static final int REMOVE_DOT = 2;
Source source;
@ -42,12 +47,43 @@ public class SourceFormatter {
int labelCase;
int mnemonicCase;
int directivePrefix;
int column;
StringBuilder sb;
Set<String> directives;
public SourceFormatter(Source source) {
this.source = source;
this.directives = new HashSet<String>();
this.directives.add("byte");
this.directives.add("db");
this.directives.add("dd");
this.directives.add("ds");
this.directives.add("dw");
this.directives.add("else");
this.directives.add("end");
this.directives.add("endif");
this.directives.add("endm");
this.directives.add("endp");
this.directives.add("ends");
this.directives.add("equ");
this.directives.add("error");
this.directives.add("fill");
this.directives.add("if");
this.directives.add("incbin");
this.directives.add("include");
this.directives.add("irp");
this.directives.add("macro");
this.directives.add("org");
this.directives.add("proc");
this.directives.add("rept");
this.directives.add("section");
this.directives.add("text");
this.directives.add("word");
this.directives.add("warning");
}
public int getMnemonicColumn() {
@ -90,6 +126,14 @@ public class SourceFormatter {
this.mnemonicCase = mnemonicCase;
}
public int getDirectivePrefix() {
return directivePrefix;
}
public void setDirectivePrefix(int directivePrefix) {
this.directivePrefix = directivePrefix;
}
public String format() {
sb = new StringBuilder();
format(source);
@ -128,17 +172,29 @@ public class SourceFormatter {
sb.append(' ');
}
String s = line.getMnemonic();
if (isDirective(s)) {
if (directivePrefix == ADD_DOT) {
if (!s.startsWith(".")) {
s = "." + s;
}
}
else if (directivePrefix == REMOVE_DOT) {
if (s.startsWith(".")) {
s = s.substring(1);
}
}
}
if (mnemonicCase == TO_UPPER) {
sb.append(line.getMnemonic().toUpperCase());
sb.append(s.toUpperCase());
}
else if (mnemonicCase == TO_LOWER) {
sb.append(line.getMnemonic().toLowerCase());
sb.append(s.toLowerCase());
}
else {
sb.append(line.getMnemonic());
sb.append(s);
}
column += line.getMnemonic().length();
column += s.length();
if (line.getArguments() != null) {
while (column < argumentColumn) {
@ -148,7 +204,7 @@ public class SourceFormatter {
if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ' ') {
sb.append(' ');
}
String s = formatExpression(line.getArguments());
s = formatExpression(line.getArguments());
sb.append(s);
column += s.length();
}
@ -259,4 +315,11 @@ public class SourceFormatter {
return e.toString();
}
boolean isDirective(String s) {
if (s.startsWith(".")) {
return directives.contains(s.substring(1).toLowerCase());
}
return directives.contains(s.toLowerCase());
}
}

Wyświetl plik

@ -45,4 +45,8 @@ public class EditorUtil {
return text;
}
public static String trimLines(String text) {
return text.replaceAll("[ \\t]+(\r\n|\n|\r)", "$1");
}
}

Wyświetl plik

@ -581,7 +581,7 @@ public class SourceEditor {
ignoreUndo = true;
ignoreRedo = true;
text = text.replaceAll("[ \\t]+(\r\n|\n|\r)", "$1");
text = EditorUtil.trimLines(text);
text = EditorUtil.replaceTabs(text, this.text.getTabs());
currentLine = 0;
@ -601,7 +601,9 @@ public class SourceEditor {
int line = this.text.getLineAtOffset(offset);
int topindex = line - this.text.getTopIndex();
text = EditorUtil.trimLines(text);
text = EditorUtil.replaceTabs(text, this.text.getTabs());
this.text.setText(text);
if (line > this.text.getLineCount()) {
@ -613,7 +615,7 @@ public class SourceEditor {
public String getText() {
String s = text.getText();
String s2 = s.replaceAll("[ \\t]+(\r\n|\n|\r)", "$1");
String s2 = EditorUtil.trimLines(s);
if (!s2.equals(s)) {
int offset = text.getCaretOffset();
int line = text.getLineAtOffset(offset);