Skip to content

Rework AUTOEXEC.BAT support, make it UTF-8 aware #2425

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

Merged
merged 1 commit into from
Apr 26, 2023
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
48 changes: 48 additions & 0 deletions include/autoexec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2020-2023 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* 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 Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef DOSBOX_AUTOEXEC_H
#define DOSBOX_AUTOEXEC_H

#include "setup.h"

#include <string>

// Registers the AUTOEXEC.BAT file on the emulated Z: drive.
// From now on, the only changes to the file content which became visible on the
// guest side, are DOS code page changes.
// TODO: change this, every environment variable modification or [autoexec]
// modification by CONFIG.COM command should be reflected; this will require
// careful checking of our COMMAND.COM iomplementattion in order not break
// anything when the change happens during AUTOEXEC.BAT execution.
void AUTOEXEC_RegisterFile();

// Notify, that DOS display code page has changed, and the AUTOEXEC.BAT content
// might need to be refreshed from the original (internal) UTF-8 version.
void AUTOEXEC_NotifyNewCodePage();

// Adds/updates environment variable to the AUTOEXEC.BAT file. Empty value
// removes the variable. If a shell is already running, it the environment is
// updated accordingly.
// The 'name' and 'value' have to be a printable, 7-bit ASCII variables.
void AUTOEXEC_SetVariable(const std::string& name, const std::string& value);

void AUTOEXEC_Init(Section* sec);

#endif
5 changes: 4 additions & 1 deletion include/dos_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ void VFILE_Register(const char *name,
const uint8_t *data,
const uint32_t size,
const char *dir = "");
void VFILE_Register(const char* name, const std::vector<uint8_t>& blob,
const char* dir = "");
void VFILE_Update(const char* name, std::vector<uint8_t> blob, const char* dir = "");
void VFILE_Remove(const char* name, const char* dir = "");

void VFILE_Register(const char *name, const std::vector<uint8_t> &blob, const char *dir);
#endif
3 changes: 1 addition & 2 deletions include/programs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2020-2023 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -33,8 +34,6 @@
#define WIKI_URL "https://github.com/dosbox-staging/dosbox-staging/wiki"
#define WIKI_ADD_UTILITIES_ARTICLE WIKI_URL "/Add-Utilities"

constexpr int autoexec_maxsize = 4096;

class CommandLine {
public:
CommandLine(int argc, char const *const argv[]);
Expand Down
22 changes: 3 additions & 19 deletions include/shell.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2020-2023 The DOSBox Staging Team
* Copyright (C) 2002-2021 The DOSBox Team
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -153,25 +154,8 @@ class DOS_Shell : public Program {
bool call = false;
};

/* Object to manage lines in the autoexec.bat The lines get removed from
* the file if the object gets destroyed. The environment is updated
* as well if the line set a a variable */
class AutoexecObject{
private:
bool installed = false;
std::string buf = {};

public:
AutoexecObject() = default;
AutoexecObject(const std::string& line);
~AutoexecObject();

void Install(const std::string& in);
void InstallBefore(const std::string& in);

private:
void CreateAutoexec();
};
std::tuple<std::string, std::string, std::string> parse_drive_conf(
std::string drive_letter, const std_fs::path& conf_path);

// Localized output

Expand Down
7 changes: 7 additions & 0 deletions src/dos/dos_keyboard_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using sv = std::string_view;

#include "../ints/int10.h"
#include "autoexec.h"
#include "bios.h"
#include "bios_disk.h"
#include "callback.h"
Expand Down Expand Up @@ -1065,6 +1066,9 @@ KeyboardErrorCode KeyboardLayout::ReadCodePageFile(const char *requested_cp_file
}
INT10_SetupRomMemoryChecksum();

// convert UTF-8 [autoexec] section to new code page
AUTOEXEC_NotifyNewCodePage();

return KEYB_NOERROR;
}

Expand Down Expand Up @@ -1697,6 +1701,9 @@ class DOS_KeyboardLayout final : public Module_base {
LOG_MSG("LAYOUT: DOS keyboard layout loaded with main language code %s for layout %s",lcode,layoutname);
}
}

// Convert UTF-8 [autoexec] section to new code page
AUTOEXEC_NotifyNewCodePage();
}

~DOS_KeyboardLayout(){
Expand Down
8 changes: 5 additions & 3 deletions src/dos/dos_programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "programs.h"

#include "autoexec.h"
#include "program_attrib.h"
#include "program_autotype.h"
#include "program_boot.h"
Expand All @@ -47,7 +48,6 @@

extern uint32_t floppytype;

extern char autoexec_data[autoexec_maxsize];
std::unique_ptr<Program> CONFIG_ProgramCreate();
std::unique_ptr<Program> MIXER_ProgramCreate();
std::unique_ptr<Program> SHELL_ProgramCreate();
Expand Down Expand Up @@ -91,8 +91,10 @@ void Add_VFiles(const bool add_autoexec)
PROGRAMS_MakeFile("SERIAL.COM", ProgramCreate<SERIAL>);
PROGRAMS_MakeFile("TREE.COM", ProgramCreate<TREE>);
PROGRAMS_MakeFile("COMMAND.COM", SHELL_ProgramCreate);
if (add_autoexec)
VFILE_Register("AUTOEXEC.BAT", (uint8_t *)autoexec_data, (uint32_t)strlen(autoexec_data));

if (add_autoexec) {
AUTOEXEC_RegisterFile();
}
}

void DOS_SetupPrograms(void)
Expand Down
Loading