Fixes in preferences

This commit is contained in:
llsth 2015-04-08 11:05:41 +02:00
parent d7f8c6cbd3
commit 05efc36c6f
24 changed files with 65 additions and 63 deletions

View File

@ -24,7 +24,7 @@
* *
* Generated with FlexCat. For more information, see: * Generated with FlexCat. For more information, see:
* http://sourceforge.net/projects/flexcat/ * http://sourceforge.net/projects/flexcat/
* *
*/ */
#ifndef AMATH_LOCALIZE_HELP_H #ifndef AMATH_LOCALIZE_HELP_H
@ -33,7 +33,7 @@
/** /**
* @file help.h * @file help.h
* @brief Localized help text definitions. * @brief Localized help text definitions.
* *
*/ */
#include "clib.h" #include "clib.h"

View File

@ -24,7 +24,7 @@
* *
* Generated with FlexCat. For more information, see: * Generated with FlexCat. For more information, see:
* http://sourceforge.net/projects/flexcat/ * http://sourceforge.net/projects/flexcat/
* *
*/ */
#ifndef AMATH_LOCALIZE_IDENT_HELP_H #ifndef AMATH_LOCALIZE_IDENT_HELP_H
@ -33,7 +33,7 @@
/** /**
* @file ident.h * @file ident.h
* @brief Localized help text definitions. * @brief Localized help text definitions.
* *
*/ */
#include "clib.h" #include "clib.h"

View File

@ -24,7 +24,7 @@
* *
* Generated with FlexCat. For more information, see: * Generated with FlexCat. For more information, see:
* http://sourceforge.net/projects/flexcat/ * http://sourceforge.net/projects/flexcat/
* *
*/ */
#ifndef AMATH_LOCALIZE_TEXT_H #ifndef AMATH_LOCALIZE_TEXT_H
@ -33,7 +33,7 @@
/** /**
* @file text.h * @file text.h
* @brief Localized text definitions. * @brief Localized text definitions.
* *
*/ */
#include "clib.h" #include "clib.h"

View File

@ -31,6 +31,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Program = CreateProgram(argc, argv); Program = CreateProgram(argc, argv);
Program->Initialize(argc, argv);
Program->Run(); Program->Run();
delete Program; delete Program;
FreeAllSafe(); FreeAllSafe();

View File

@ -104,10 +104,7 @@ char* PromptStatement::Execute()
buf->ClearAndCopy(prompt); buf->ClearAndCopy(prompt);
while(buf->RemoveTrailing(' ')); while(buf->RemoveTrailing(' '));
buf->Append(' '); buf->Append(' ');
Program->SetPrompt(buf->GetString());
Program->Console->SetPrompt(buf->GetString());
Program->Preferences->SetPrompt(buf->GetString());
delete buf; delete buf;
return (char*)EMPTYSTRING; return (char*)EMPTYSTRING;
} }

View File

@ -98,7 +98,6 @@ class Program* CreateProgram(int argc, char **argv) {
out = new StandardProgram(); out = new StandardProgram();
#endif #endif
} }
out->Initialize(argc, argv);
return out; return out;
} }

View File

@ -27,10 +27,9 @@
#include "clib.h" #include "clib.h"
#include "main/nodes.h" #include "main/nodes.h"
#include "main/evaluator.h" #include "main/evaluator.h"
#include "system/console_amiga.h"
#ifdef AMIGA #ifdef AMIGA
#include <clib/dos_protos.h>
#include "system/console_amiga.h"
AmigaShellConsole::AmigaShellConsole(const char *prompt) : AmigaShellConsole::AmigaShellConsole(const char *prompt) :
ConsoleBase(prompt) ConsoleBase(prompt)

View File

@ -91,7 +91,7 @@ void StandardConsole::ReadLine()
line = proc->GetLine(); line = proc->GetLine();
#ifdef UNIX #ifdef UNIX
tcsetattr(STDIN_FILENO, TCSANOW, &old_tio); tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
#endif #endif
} }

View File

@ -31,12 +31,6 @@
#include "system/filesystem_amiga.h" #include "system/filesystem_amiga.h"
#ifdef AMIGA #ifdef AMIGA
#include <dos/exall.h>
#include <dos/var.h>
#include <exec/memory.h>
#include <exec/types.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
/** /**
* @brief * @brief

View File

@ -39,7 +39,7 @@
CharBuffer* StandardFilesystem::ListDirectory(const char *path) CharBuffer* StandardFilesystem::ListDirectory(const char *path)
{ {
#ifdef UNIX #ifdef UNIX
CharBuffer *pathbuf = new CharBuffer(); CharBuffer *pathbuf = new CharBuffer();
pathbuf->Empty(); pathbuf->Empty();
if (path == NOMEM) { if (path == NOMEM) {
pathbuf->Append("."); pathbuf->Append(".");
@ -108,9 +108,9 @@ CharBuffer* StandardFilesystem::ListDirectory(const char *path)
delete pathbuf; delete pathbuf;
return lines; return lines;
#else #else
CharBuffer *lines = new CharBuffer(); CharBuffer *lines = new CharBuffer();
lines->Empty(); lines->Empty();
return lines; return lines;
#endif #endif
} }

View File

@ -34,9 +34,7 @@
#include "system/language_amiga.h" #include "system/language_amiga.h"
#ifdef AMIGA #ifdef AMIGA
#include "clib/locale_protos.h" #include <clib/locale_protos.h>
//#include <inline/locale.h>
#include <clib/exec_protos.h>
AmigaLanguage::AmigaLanguage() AmigaLanguage::AmigaLanguage()
{ {

View File

@ -118,7 +118,7 @@ bool StandardLanguage::CharIsSpace(long unsigned int character)
bool StandardLanguage::CharIsCntrl(long unsigned int character) bool StandardLanguage::CharIsCntrl(long unsigned int character)
{ {
return (character <= 32 || character >= 126); return (character < 32 || character > 125);
} }
bool StandardLanguage::StrIsEqualLoc(const char* s1, const char* s2) bool StandardLanguage::StrIsEqualLoc(const char* s1, const char* s2)

View File

@ -47,15 +47,16 @@ PreferencesBase::~PreferencesBase()
void PreferencesBase::SetDefaults() void PreferencesBase::SetDefaults()
{ {
AllocAndCopy(&this->prompt, ">>> "); AllocAndCopy(&this->prompt, "> ");
digits = 9; digits = 9;
} }
char* PreferencesBase::GetDescription() char* PreferencesBase::GetDescription()
{ {
static const char *promptq = "\""; static const char promptq = '"';
static const char *sprompt = "prompt"; static const char *sprompt = "prompt";
static const char *sdigits = "digits"; static const char *sdigits = "digits";
static const char delimitor = ';';
Number *d = new RealNumber(GetDigits()); Number *d = new RealNumber(GetDigits());
NumeralSystem *ns = new DecimalSystem(2); NumeralSystem *ns = new DecimalSystem(2);
@ -64,20 +65,22 @@ char* PreferencesBase::GetDescription()
buf->Empty(); buf->Empty();
buf->EnsureSize( buf->EnsureSize(
StrLen(sprompt) + StrLen(SPACE) + StrLen(promptq) + sizeof(sprompt) + sizeof(SPACE) + sizeof(promptq) + StrLen(prompt) +
StrLen(prompt) + StrLen(promptq) + StrLen(NEWLINE) + sizeof(promptq) + sizeof(delimitor) + sizeof(NEWLINE) +
StrLen(sdigits) + StrLen(SPACE) + StrLen(dtext) + sizeof(sdigits) + sizeof(SPACE) + StrLen(dtext) + sizeof(delimitor) +
StrLen(NEWLINE) + 1); sizeof(NEWLINE) + 1);
buf->Append(sprompt); buf->Append(sprompt);
buf->Append(SPACE); buf->Append(SPACE);
buf->Append(promptq); buf->Append(promptq);
buf->Append(prompt); buf->Append(prompt);
buf->Append(promptq); buf->Append(promptq);
buf->Append(delimitor);
buf->Append(NEWLINE); buf->Append(NEWLINE);
buf->Append(sdigits); buf->Append(sdigits);
buf->Append(SPACE); buf->Append(SPACE);
buf->Append(dtext); buf->Append(dtext);
buf->Append(delimitor);
buf->Append(NEWLINE); buf->Append(NEWLINE);
delete ns; delete ns;
@ -86,6 +89,10 @@ char* PreferencesBase::GetDescription()
void PreferencesBase::SetPrefs(char* prefs) void PreferencesBase::SetPrefs(char* prefs)
{ {
if (prefs == NOMEM) {
return;
}
Parser *parser = new Parser(prefs); Parser *parser = new Parser(prefs);
SyntaxNode *node = parser->Parse(); SyntaxNode *node = parser->Parse();
delete parser; delete parser;

View File

@ -30,12 +30,6 @@
#include "system/preferences_amiga.h" #include "system/preferences_amiga.h"
#ifdef AMIGA #ifdef AMIGA
#include <dos/exall.h>
#include <dos/var.h>
#include <exec/memory.h>
#include <exec/types.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
static const char *tempname = "ENV:amath.prefs"; static const char *tempname = "ENV:amath.prefs";
static const char *permname = "ENVARC:amath.prefs"; static const char *permname = "ENVARC:amath.prefs";
@ -53,10 +47,12 @@ bool AmigaPreferences::Load()
const int bufsize = 64; const int bufsize = 64;
char* buf = new char[bufsize]; char* buf = new char[bufsize];
char* c; char* c;
int s = 1;
do { do {
c = FGets(file, buf, bufsize); c = FGets(file, buf, bufsize);
if (c != NULL) { if (c != NULL) {
text->EnsureSize(s++);
text->Append(c); text->Append(c);
} }
} while (c != NULL); } while (c != NULL);

View File

@ -38,6 +38,7 @@ static const char *permname = "/usr/local/etc/amath.conf";
bool StandardPreferences::Load() bool StandardPreferences::Load()
{ {
#ifdef UNIX
FILE *file = fopen(tempname, "r"); FILE *file = fopen(tempname, "r");
if (!file) { if (!file) {
return false; return false;
@ -49,10 +50,12 @@ bool StandardPreferences::Load()
const int bufsize = 64; const int bufsize = 64;
char* buf = new char[bufsize]; char* buf = new char[bufsize];
char* c; char* c;
int s = 1;
do { do {
c = fgets(buf, bufsize, file); c = fgets(buf, bufsize, file);
if (c != NULL) { if (c != NULL) {
text->EnsureSize(s++);
text->Append(c); text->Append(c);
} }
} while (c != NULL); } while (c != NULL);
@ -61,6 +64,7 @@ bool StandardPreferences::Load()
fclose(file); fclose(file);
SetPrefs(text->GetString()); SetPrefs(text->GetString());
delete text; delete text;
#endif
return true; return true;
} }
@ -76,6 +80,7 @@ bool StandardPreferences::Save()
bool StandardPreferences::SavePrefs(const char* name) bool StandardPreferences::SavePrefs(const char* name)
{ {
#ifdef UNIX
FILE *file = fopen(name, "w"); FILE *file = fopen(name, "w");
if (!file) { if (!file) {
return false; return false;
@ -84,6 +89,7 @@ bool StandardPreferences::SavePrefs(const char* name)
char *out = GetDescription(); char *out = GetDescription();
fputs(out, file); fputs(out, file);
fclose(file); fclose(file);
#endif
return true; return true;
} }

View File

@ -37,7 +37,6 @@
#include "system/task.h" #include "system/task.h"
#include "system/base/thread.h" #include "system/base/thread.h"
#ifdef WITHTEST // Still under development
#ifdef AMIGA #ifdef AMIGA
#include <exec/io.h> #include <exec/io.h>
#include <exec/memory.h> #include <exec/memory.h>
@ -70,4 +69,3 @@ private:
#endif #endif
#endif #endif
#endif

View File

@ -38,14 +38,11 @@ Program::Program()
Functions = new FunctionList(); Functions = new FunctionList();
Graphs = new GraphList(); Graphs = new GraphList();
ins = new RealNumber(); ins = new RealNumber();
Preferences = CreatePreferences();
// Preferences->Load();
Language = CreateLanguage(); Language = CreateLanguage();
Filesystem = CreateFilesystem();
Preferences = CreatePreferences();
Input = new DecimalSystem(Preferences->GetDigits(), Language->GetFractionPoint()); Input = new DecimalSystem(Preferences->GetDigits(), Language->GetFractionPoint());
Output = new DecimalSystem(Preferences->GetDigits(), Language->GetFractionPoint()); Output = new DecimalSystem(Preferences->GetDigits(), Language->GetFractionPoint());
Filesystem = CreateFilesystem();
} }
Program::~Program() Program::~Program()
@ -59,9 +56,8 @@ Program::~Program()
delete Language; delete Language;
delete ins; delete ins;
// Preferences->Keep(); Preferences->Keep();
delete Preferences; delete Preferences;
} }
void Program::NewPositionalInput(short unsigned int base, short unsigned int digits) void Program::NewPositionalInput(short unsigned int base, short unsigned int digits)
@ -90,6 +86,14 @@ void Program::NewPositionalOutput(short unsigned int base, short unsigned int di
} }
} }
void Program::SetPrompt(const char* text)
{
if (Console != NOMEM) {
Console->SetPrompt(text);
}
Preferences->SetPrompt(text);
}
Number* Program::GetLastResult() Number* Program::GetLastResult()
{ {
return ins; return ins;

View File

@ -63,7 +63,8 @@ public:
void NewPositionalInput(short unsigned int base, short unsigned int digits); void NewPositionalInput(short unsigned int base, short unsigned int digits);
void NewPositionalOutput(short unsigned int base, short unsigned int digits); void NewPositionalOutput(short unsigned int base, short unsigned int digits);
void SetLastResult(Number *number); void SetLastResult(Number *number);
struct Number* GetLastResult(); void SetPrompt(const char *text);
struct Number* GetLastResult();
class Language *Language; class Language *Language;
class ConsoleBase *Console; class ConsoleBase *Console;
class PreferencesBase *Preferences; class PreferencesBase *Preferences;
@ -75,7 +76,7 @@ public:
class GraphList *Graphs; class GraphList *Graphs;
private: private:
struct Number* ins; struct Number* ins;
}; };
#endif #endif

View File

@ -25,7 +25,6 @@
*/ */
#include "clib.h" #include "clib.h"
#include "platform.h"
#include "lib/charbuf.h" #include "lib/charbuf.h"
#include "main/graphlist.h" #include "main/graphlist.h"
#include "main/evaluator.h" #include "main/evaluator.h"
@ -40,11 +39,6 @@
#include "system/base/io.h" #include "system/base/io.h"
#ifdef AMIGA #ifdef AMIGA
#include <exec/types.h>
#include <clib/exec_protos.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#define ARGS_FORMAT "SHELL/S,INPUT/F" #define ARGS_FORMAT "SHELL/S,INPUT/F"
AmigaProgram::AmigaProgram() AmigaProgram::AmigaProgram()
@ -88,6 +82,8 @@ void AmigaProgram::Initialize(int argc, char **argv)
void AmigaProgram::Run() void AmigaProgram::Run()
{ {
Preferences->Load();
if (Console != NULL) { if (Console != NULL) {
Console->Run(); Console->Run();
} else if (args.input != NULL) { } else if (args.input != NULL) {
@ -106,3 +102,4 @@ void AmigaProgram::Exit()
#endif #endif

View File

@ -79,6 +79,8 @@ void StandardProgram::Initialize(int argc, char **argv)
void StandardProgram::Run() void StandardProgram::Run()
{ {
Preferences->Load();
if (Console != NOMEM) { if (Console != NOMEM) {
Console->Run(); Console->Run();
return; return;

View File

@ -56,7 +56,9 @@ void TestProgram::Run()
} }
void TestProgram::Initialize(int argc, char** argv) void TestProgram::Initialize(int argc, char** argv)
{ } {
Preferences->Load();
}
void TestProgram::Exit() void TestProgram::Exit()
{ } { }

View File

@ -29,7 +29,6 @@
#include "system/task_amiga.h" #include "system/task_amiga.h"
#ifdef AMIGA #ifdef AMIGA
#ifdef DEVNOTFINISH // Still under development
#include <exec/io.h> #include <exec/io.h>
#include <exec/memory.h> #include <exec/memory.h>
#include <intuition/intuition.h> #include <intuition/intuition.h>
@ -86,4 +85,3 @@ void AmigaTask::WaitExit()
} }
#endif #endif
#endif

View File

@ -34,11 +34,11 @@
*/ */
#include "clib.h" #include "clib.h"
#include "system/task.h"
#include "system/task_amiga.h" #include "system/task_amiga.h"
#include "system/base/thread.h" #include "system/base/thread.h"
#ifdef AMIGA #ifdef AMIGA
#ifdef DEVNOTFINISH // Still under development
#include <exec/io.h> #include <exec/io.h>
#include <exec/memory.h> #include <exec/memory.h>
#include <libraries/dos.h> #include <libraries/dos.h>
@ -76,4 +76,3 @@ private:
#endif #endif
#endif #endif
#endif

View File

@ -75,11 +75,15 @@ typedef int bool;
# ifndef ANSICONSOLE # ifndef ANSICONSOLE
# define ANSICONSOLE # define ANSICONSOLE
# endif # endif
# include <dos/var.h>
# include <dos/exall.h>
# include <exec/io.h> # include <exec/io.h>
# include <exec/types.h> # include <exec/types.h>
# include <exec/memory.h> # include <exec/memory.h>
# include <exec/semaphores.h> # include <exec/semaphores.h>
# include <clib/alib_protos.h>
# include <clib/exec_protos.h> # include <clib/exec_protos.h>
# include <clib/dos_protos.h>
#endif #endif
// Check weather an POSIX compatible API is available // Check weather an POSIX compatible API is available