Skip to content

Commit

Permalink
add "derive cwd" setting
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarlopernudisegura authored and TheThirdOne committed Jun 28, 2022
1 parent a699f31 commit 8925450
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Settings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ DataSegmentHighlightBackground = 0x0099ccff
DataSegmentHighlightForeground = 0
RegisterHighlightBackground = 0x0099cc55
RegisterHighlightForeground = 0

DeriveCurrentDirectory = false
9 changes: 7 additions & 2 deletions src/rars/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ public enum Bool {
/**
* Flag to determine whether a program uses rv64i instead of rv32i
*/
RV64_ENABLED("rv64Enabled", false);;
RV64_ENABLED("rv64Enabled", false),
/**
* Flag to determine whether to calculate relative paths from the current working directory
* or from the RARS executable path.
*/
DERIVE_CURRENT_WORKING_DIRECTORY("DeriveCurrentWorkingDirectory", false);

// TODO: add option for turning off user trap handling and interrupts
private String name;
Expand Down Expand Up @@ -1320,4 +1325,4 @@ private int[] getTextSegmentColumnOrder(String stringOfColumnIndexes) {
return list;
}

}
}
5 changes: 3 additions & 2 deletions src/rars/util/SystemIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,10 @@ public static int openFile(String filename, int flags) {
return -1;
} // fileErrorString would have been set

String parent = new File(Globals.program.getFilename()).getParent();
File filepath = new File(filename);
if (!filepath.isAbsolute()) {
if (!filepath.isAbsolute() && Globals.program != null && Globals.getSettings()
.getBooleanSetting(Settings.Bool.DERIVE_CURRENT_WORKING_DIRECTORY)) {
String parent = new File(Globals.program.getFilename()).getParent();
filepath = new File(parent, filename);
}
if (flags == O_RDONLY) // Open for reading only
Expand Down
15 changes: 10 additions & 5 deletions src/rars/venus/VenusUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class VenusUI extends JFrame {
private JMenuItem runGo, runStep, runBackstep, runReset, runAssemble, runStop, runPause, runClearBreakpoints, runToggleBreakpoints;
private JCheckBoxMenuItem settingsLabel, settingsPopupInput, settingsValueDisplayBase, settingsAddressDisplayBase,
settingsExtended, settingsAssembleOnOpen, settingsAssembleAll, settingsAssembleOpen, settingsWarningsAreErrors,
settingsStartAtMain, settingsProgramArguments, settingsSelfModifyingCode,settingsRV64;
settingsStartAtMain, settingsProgramArguments, settingsSelfModifyingCode, settingsRV64, settingsDeriveCurrentWorkingDirectory;
private JMenuItem settingsExceptionHandler, settingsEditor, settingsHighlighting, settingsMemoryConfiguration;
private JMenuItem helpHelp, helpAbout;

Expand All @@ -108,8 +108,8 @@ public class VenusUI extends JFrame {
private Action settingsLabelAction, settingsPopupInputAction, settingsValueDisplayBaseAction, settingsAddressDisplayBaseAction,
settingsExtendedAction, settingsAssembleOnOpenAction, settingsAssembleOpenAction, settingsAssembleAllAction,
settingsWarningsAreErrorsAction, settingsStartAtMainAction, settingsProgramArgumentsAction,
settingsExceptionHandlerAction, settingsEditorAction,
settingsHighlightingAction, settingsMemoryConfigurationAction, settingsSelfModifyingCodeAction,settingsRV64Action;
settingsExceptionHandlerAction, settingsEditorAction, settingsHighlightingAction, settingsMemoryConfigurationAction,
settingsSelfModifyingCodeAction, settingsRV64Action, settingsDeriveCurrentWorkingDirectoryAction;
private Action helpHelpAction, helpAboutAction;


Expand Down Expand Up @@ -465,7 +465,9 @@ public void handler(boolean value) {
csrTab.updateRegisters();
}
};

settingsDeriveCurrentWorkingDirectoryAction = new SettingsAction("Derive current working directory",
"If set, the working directory is derived from the main file instead of the RARS executable directory.",
Settings.Bool.DERIVE_CURRENT_WORKING_DIRECTORY);


settingsEditorAction = new SettingsEditorAction("Editor...", null,
Expand Down Expand Up @@ -619,6 +621,8 @@ private JMenuBar setUpMenuBar() {
settingsSelfModifyingCode.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.SELF_MODIFYING_CODE_ENABLED));
settingsRV64 = new JCheckBoxMenuItem(settingsRV64Action);
settingsRV64.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.RV64_ENABLED));
settingsDeriveCurrentWorkingDirectory = new JCheckBoxMenuItem(settingsDeriveCurrentWorkingDirectoryAction);
settingsDeriveCurrentWorkingDirectory.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.DERIVE_CURRENT_WORKING_DIRECTORY));
settingsAssembleOnOpen = new JCheckBoxMenuItem(settingsAssembleOnOpenAction);
settingsAssembleOnOpen.setSelected(Globals.getSettings().getBooleanSetting(Settings.Bool.ASSEMBLE_ON_OPEN));
settingsAssembleAll = new JCheckBoxMenuItem(settingsAssembleAllAction);
Expand Down Expand Up @@ -647,6 +651,7 @@ private JMenuBar setUpMenuBar() {
settings.add(settingsAssembleOpen);
settings.add(settingsWarningsAreErrors);
settings.add(settingsStartAtMain);
settings.add(settingsDeriveCurrentWorkingDirectory);
settings.addSeparator();
settings.add(settingsExtended);
settings.add(settingsSelfModifyingCode);
Expand Down Expand Up @@ -1189,4 +1194,4 @@ private ImageIcon loadIcon(String name) {
private KeyStroke makeShortcut(int key) {
return KeyStroke.getKeyStroke(key, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
}
}
}

0 comments on commit 8925450

Please sign in to comment.