Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open relative files from executing program path #123

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

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


File filepath = new File(filename);
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
{
try {
// Set up input stream from disk file
inputStream = new FileInputStream(filename);
inputStream = new FileInputStream(filepath);
FileIOData.setStreamInUse(fdToUse, inputStream); // Save stream for later use
} catch (FileNotFoundException e) {
fileErrorString = "File " + filename + " not found, open for input.";
Expand All @@ -392,7 +397,7 @@ public static int openFile(String filename, int flags) {
{
// Set up output stream to disk file
try {
outputStream = new FileOutputStream(filename, ((flags & O_APPEND) != 0));
outputStream = new FileOutputStream(filepath, ((flags & O_APPEND) != 0));
FileIOData.setStreamInUse(fdToUse, outputStream); // Save stream for later use
} catch (FileNotFoundException e) {
fileErrorString = "File " + filename + " not found, open for output.";
Expand Down Expand Up @@ -634,4 +639,4 @@ private static int nowOpening(String filename, int flag) {
}

} // end private class FileIOData
}
}
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 @@ -461,7 +461,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 @@ -615,6 +617,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 @@ -643,6 +647,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 @@ -1185,4 +1190,4 @@ private ImageIcon loadIcon(String name) {
private KeyStroke makeShortcut(int key) {
return KeyStroke.getKeyStroke(key, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
}
}
}