Skip to content

Commit 353ce31

Browse files
author
FeralChild64
committed
Rework AUTOEXEC.BAT support and make it UTF-8 aware
1 parent d974700 commit 353ce31

15 files changed

+776
-530
lines changed

include/autoexec.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2020-2023 The DOSBox Staging Team
3+
* Copyright (C) 2002-2021 The DOSBox Team
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License along
16+
* with this program; if not, write to the Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
*/
19+
20+
#ifndef DOSBOX_AUTOEXEC_H
21+
#define DOSBOX_AUTOEXEC_H
22+
23+
#include "setup.h"
24+
25+
#include <string>
26+
27+
// Registers the AUTOEXEC.BAT file on the emulated Z: drive.
28+
// From now on, the only changes to the file content which became visible on the
29+
// guest side, are DOS code page changes.
30+
// TODO: change this, every environment variable modification or [autoexec]
31+
// modification by CONFIG.COM command should be reflected; this will require
32+
// careful checking of our COMMAND.COM iomplementattion in order not break
33+
// anything when the change happens during AUTOEXEC.BAT execution.
34+
void AUTOEXEC_RegisterFile();
35+
36+
// Notify, that DOS display code page has changed, and the AUTOEXEC.BAT content
37+
// might need to be refreshed from the original (internal) UTF-8 version.
38+
void AUTOEXEC_NotifyNewCodePage();
39+
40+
// Adds/updates environment variable to the AUTOEXEC.BAT file. Empty value
41+
// removes the variable. If a shell is already running, it the environment is
42+
// updated accordingly.
43+
// The 'name' and 'value' have to be a printable, 7-bit ASCII variables.
44+
void AUTOEXEC_SetVariable(const std::string &name, const std::string &value);
45+
46+
void AUTOEXEC_Init(Section* sec);
47+
48+
#endif

include/dos_system.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,10 @@ void VFILE_Register(const char *name,
417417
const uint8_t *data,
418418
const uint32_t size,
419419
const char *dir = "");
420+
void VFILE_Register(const char* name, const std::vector<uint8_t>& blob,
421+
const char* dir = "");
422+
void VFILE_Update(const char* name, const std::vector<uint8_t>& blob,
423+
const char* dir = "");
424+
void VFILE_Remove(const char* name, const char* dir = "");
420425

421-
void VFILE_Register(const char *name, const std::vector<uint8_t> &blob, const char *dir);
422426
#endif

include/programs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (C) 2020-2023 The DOSBox Staging Team
23
* Copyright (C) 2002-2021 The DOSBox Team
34
*
45
* This program is free software; you can redistribute it and/or modify
@@ -33,8 +34,6 @@
3334
#define WIKI_URL "https://github.com/dosbox-staging/dosbox-staging/wiki"
3435
#define WIKI_ADD_UTILITIES_ARTICLE WIKI_URL "/Add-Utilities"
3536

36-
constexpr int autoexec_maxsize = 4096;
37-
3837
class CommandLine {
3938
public:
4039
CommandLine(int argc, char const *const argv[]);

include/shell.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (C) 2020-2023 The DOSBox Staging Team
23
* Copyright (C) 2002-2021 The DOSBox Team
34
*
45
* This program is free software; you can redistribute it and/or modify
@@ -153,25 +154,8 @@ class DOS_Shell : public Program {
153154
bool call = false;
154155
};
155156

156-
/* Object to manage lines in the autoexec.bat The lines get removed from
157-
* the file if the object gets destroyed. The environment is updated
158-
* as well if the line set a a variable */
159-
class AutoexecObject{
160-
private:
161-
bool installed = false;
162-
std::string buf = {};
163-
164-
public:
165-
AutoexecObject() = default;
166-
AutoexecObject(const std::string& line);
167-
~AutoexecObject();
168-
169-
void Install(const std::string& in);
170-
void InstallBefore(const std::string& in);
171-
172-
private:
173-
void CreateAutoexec();
174-
};
157+
std::tuple<std::string, std::string, std::string> parse_drive_conf(
158+
std::string drive_letter, const std_fs::path& conf_path);
175159

176160
// Localized output
177161

src/dos/dos_keyboard_layout.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using sv = std::string_view;
2626

2727
#include "../ints/int10.h"
28+
#include "autoexec.h"
2829
#include "bios.h"
2930
#include "bios_disk.h"
3031
#include "callback.h"
@@ -1065,6 +1066,9 @@ KeyboardErrorCode KeyboardLayout::ReadCodePageFile(const char *requested_cp_file
10651066
}
10661067
INT10_SetupRomMemoryChecksum();
10671068

1069+
// convert UTF-8 [autoexec] section to new code page
1070+
AUTOEXEC_NotifyNewCodePage();
1071+
10681072
return KEYB_NOERROR;
10691073
}
10701074

@@ -1697,6 +1701,9 @@ class DOS_KeyboardLayout final : public Module_base {
16971701
LOG_MSG("LAYOUT: DOS keyboard layout loaded with main language code %s for layout %s",lcode,layoutname);
16981702
}
16991703
}
1704+
1705+
// Convert UTF-8 [autoexec] section to new code page
1706+
AUTOEXEC_NotifyNewCodePage();
17001707
}
17011708

17021709
~DOS_KeyboardLayout(){

src/dos/dos_programs.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "programs.h"
2323

24+
#include "autoexec.h"
2425
#include "program_attrib.h"
2526
#include "program_autotype.h"
2627
#include "program_boot.h"
@@ -47,7 +48,6 @@
4748

4849
extern uint32_t floppytype;
4950

50-
extern char autoexec_data[autoexec_maxsize];
5151
std::unique_ptr<Program> CONFIG_ProgramCreate();
5252
std::unique_ptr<Program> MIXER_ProgramCreate();
5353
std::unique_ptr<Program> SHELL_ProgramCreate();
@@ -91,8 +91,10 @@ void Add_VFiles(const bool add_autoexec)
9191
PROGRAMS_MakeFile("SERIAL.COM", ProgramCreate<SERIAL>);
9292
PROGRAMS_MakeFile("TREE.COM", ProgramCreate<TREE>);
9393
PROGRAMS_MakeFile("COMMAND.COM", SHELL_ProgramCreate);
94-
if (add_autoexec)
95-
VFILE_Register("AUTOEXEC.BAT", (uint8_t *)autoexec_data, (uint32_t)strlen(autoexec_data));
94+
95+
if (add_autoexec) {
96+
AUTOEXEC_RegisterFile();
97+
}
9698
}
9799

98100
void DOS_SetupPrograms(void)

0 commit comments

Comments
 (0)