1
0
Fork 0

made the language file internal

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@319
This commit is contained in:
Peter Veenstra 2002-10-16 18:39:20 +00:00
parent 793cc770fd
commit 07efb3af57
6 changed files with 73 additions and 103 deletions

View file

@ -148,7 +148,7 @@ void DOSBOX_Init(void) {
secprop=control->AddSection_prop("DOSBOX",&DOSBOX_RealInit);
secprop->Add_string("LANGUAGE","dosbox.lang");
secprop->Add_string("LANGUAGE","");
secprop->Add_int("WARNINGS",0);
control->AddSection ("MEMORY",&MEM_Init);

View file

@ -1,74 +0,0 @@
:SHELL_CMD_HELP
supported commands are:
.
:SHELL_ILLEGAL_SWITCH
Illegal switch: %s
.
:SHELL_CMD_ECHO_ON
ECHO is on
.
:SHELL_CMD_ECHO_OFF
ECHO is off
.
:SHELL_CMD_CHDIR_ERROR
Unable to change to: %s
.
:SHELL_CMD_MKDIR_ERROR
Unable to make: %s
.
:SHELL_CMD_RMDIR_ERROR
Unable to remove: %s
.
:SHELL_SYNTAXERROR
The syntax of the command is incorrect
.
:SHELL_CMD_SET_NOT_SET
Environment variable %s not defined
.
:SHELL_CMD_SET_OUT_OF_SPACE
Not enough environment space left
.
:SHELL_CMD_IF_EXIST_MISSING_FILENAME
IF EXIST: Missing filename
.
:SHELL_CMD_IF_ERRORLEVEL_MISSING_NUMBER
IF ERRORLEVEL: Missing number
.
:SHELL_CMD_IF_ERRORLEVEL_INVALID_NUMBER
IF ERRORLEVEL: Invalid number
.
:SHELL_CMD_GOTO_MISSING_LABEL
No label supplied to GOTO command
.
:SHELL_CMD_GOTO_LABEL_NOT_FOUND
Label %s not found
.
:SHELL_CMD_FILE_NOT_FOUND
File %s not found
.
:SHELL_CMD_DIR_INTRO
Directory of %s
.
:SHELL_CMD_DIR_PATH_ERROR
Illegal Path
.
:SHELL_CMD_DIR_BYTES_USED
%16d File(s) %16s Bytes
.
:SHELL_CMD_DIR_BYTES_FREE
%16d Dir(s) %16s Bytes free
.
:SHELL_STARTUP
DOSBox Shell v0.35
For Help and supported commands type: HELP
HAVE FUN!
The DOSBox Team
.
:SHELL_EXECUTE_DRIVE_NOT_FOUND
Drive %c does not exist!
.
:SHELL_EXECUTE_ILLEGAL_COMMAND
Illegal command: %s
.

View file

@ -23,6 +23,9 @@
#include "cross.h"
#include "support.h"
#include "setup.h"
#include <list>
#include <string>
using namespace std;
@ -30,15 +33,39 @@
struct MessageBlock
{
char * name;
char * string;
MessageBlock * next;
string name;
string val;
MessageBlock(const char* _name, const char* _val):
name(_name),val(_val)
{}
};
static MessageBlock * first_message;
static list<MessageBlock> Lang;
typedef list<MessageBlock>::iterator itmb;
void AddMessage(const char * _name, const char* _val)
{
Lang.push_back(MessageBlock(_name,_val));
}
void ReplaceMessage(const char * _name, const char* _val)
{
//find the message
for(itmb tel=Lang.begin();tel!=Lang.end();tel++)
{
if((*tel).name==_name)
{ itmb teln=tel;
teln++;
Lang.erase(tel,teln);
break;
}
}
//even if the message doesn't exist add it
AddMessage(_name,_val);
}
static void LoadMessageFile(const char * fname) {
FILE * mfile=fopen(fname,"rb");
if(*fname=='\0') return;//empty string=no languagefile
FILE * mfile=fopen(fname,"rb");
/* This should never happen and since other modules depend on this use a normal printf */
if (!mfile) {
E_Exit("MSG:Can't load messages: %s",fname);
@ -66,15 +93,8 @@ static void LoadMessageFile(const char * fname) {
strcpy(name,linein+1);
/* End of string marker */
} else if (linein[0]=='.') {
/* Save the string internally */
size_t total=sizeof(MessageBlock)+strlen(name)+1+strlen(string)+1;
MessageBlock * newblock=(MessageBlock *)malloc(total);
newblock->name=((char *)newblock)+sizeof(MessageBlock);
newblock->string=newblock->name+strlen(name)+1;
strcpy(newblock->name,name);
strcpy(newblock->string,string);
newblock->next=first_message;
first_message=newblock;
/* Replace/Add the string to the internal langaugefile */
ReplaceMessage(name,string);
} else {
/* Normal string to be added */
strcat(string,linein);
@ -83,19 +103,20 @@ static void LoadMessageFile(const char * fname) {
}
fclose(mfile);
}
char * MSG_Get(char * msg) {
MessageBlock * index=first_message;
while (index) {
if (!strcmp(msg,index->name)) return index->string;
index=index->next;
}
return "Message not found";
const char * MSG_Get(char const * msg) {
for(itmb tel=Lang.begin();tel!=Lang.end();tel++)
{
if((*tel).name==msg)
{
return (*tel).val.c_str();
}
}
return "Message not Found!";
}
void MSG_Init(Section_prop * section) {
/* Load the messages from "dosbox.lang file" */
first_message=0;
std::string file_name;
if (control->cmdline->FindString("-lang",file_name)) {
LoadMessageFile(file_name.c_str());

View file

@ -92,7 +92,7 @@ Program::Program() {
cmd = new CommandLine(envscan,tail.buffer);
}
void Program::WriteOut(char * format,...) {
void Program::WriteOut(const char * format,...) {
char buf[1024];
va_list msg;

View file

@ -214,7 +214,7 @@ void S_Warn(char * format,...) {
GFX_ShowMsg(buf);
#endif
}
char buf[1024]; //global as else it doesn't always gets thrown right (linux/gcc2.95)
static char buf[1024]; //greater scope as else it doesn't always gets thrown right (linux/gcc2.95)
void E_Exit(char * format,...) {
// char buf[1024]; //see above

View file

@ -175,10 +175,33 @@ static char * path_string="PATH=Z:\\";
static char * comspec_string="COMSPEC=Z:\\COMMAND.COM";
static char * full_name="Z:\\COMMAND.COM";
static char * init_line="/INIT AUTOEXEC.BAT";
void SHELL_Init() {
call_shellstop=CALLBACK_Allocate();
//add messages:
AddMessage("SHELL_CMD_HELP","supported commands are:\n");
AddMessage("SHELL_CMD_ECHO_ON","ECHO is on\n");
AddMessage("SHELL_CMD_ECHO_OFF","ECHO is off\n");
AddMessage("SHELL_ILLEGAL_SWITCH","Illegal switch: %s");
AddMessage("SHELL_CMD_CHDIR_ERROR","Unable to change to: %s\n");
AddMessage("SHELL_CMD_MKDIR_ERROR","Unable to make: %s\n");
AddMessage("SHELL_CMD_RMDIR_ERROR","Unable to remove: %\n");
AddMessage("SHELL_SYNTAXERROR","The syntax of the command is incorrect.\n");
AddMessage("SHELL_CMD_SET_NOT_SET","Environment variable %s not defined\n");
AddMessage("SHELL_CMD_SET_OUT_OF_SPACE","Not enough environment space left.\n");
AddMessage("SHELL_CMD_IF_EXIST_MISSING_FILENAME","IF EXIST: Missing filename.\n");
AddMessage("SHELL_CMD_IF_ERRORLEVEL_MISSING_NUMBER","IF ERRORLEVEL: Missing number.\n");
AddMessage("SHELL_CMD_IF_ERRORLEVEL_INVALID_NUMBER","IF ERRORLEVEL: Invalid number.\n");
AddMessage("SHELL_CMD_GOTO_MISSING_LABEL","No label supplied to GOTO command.\n");
AddMessage("SHELL_CMD_GOTO_LABEL_NOT_FOUND","GOTO: Label %s not found.\n");
AddMessage("SHELL_CMD_FILE_NOT_FOUND","File %s not found.\n");
AddMessage("SHELL_CMD_DIR_INTRO","Directory of %s.\n");
AddMessage("SHELL_CMD_DIR_PATH_ERROR","Illegal Path\n");
AddMessage("SHELL_CMD_DIR_BYTES_USED","%5d File(s) %17s Bytes\n");
AddMessage("SHELL_CMD_DIR_BYTES_FREE","%5d Dir(s) %17s Bytes free");
AddMessage("SHELL_EXECUTE_DRIVE_NOT_FOUND","Drive %c does not exist!\n");
AddMessage("SHELL_EXECUTE_ILLEGAL_COMMAND","Illegal command: %s.\n");
AddMessage("SHELL_STARTUP","DOSBox Shell v0.40\nFor Help and supported commands type: HELP\n\nHAVE FUN!\nThe DOSBox Team\n\n");
//regular startup
call_shellstop=CALLBACK_Allocate();
CALLBACK_Setup(call_shellstop,shellstop_handler,CB_IRET);
PROGRAMS_MakeFile("COMMAND.COM",SHELL_ProgramStart);