Added: System Variables
This commit is contained in:
parent
79f5bd9e66
commit
d64583a0e4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -28,6 +28,7 @@
|
|||
#include "uart_reg.h"
|
||||
#include "rtc_reg.h"
|
||||
#include "utilities.h"
|
||||
#include "variables.h"
|
||||
#include "vicky_general.h"
|
||||
#include "version.h"
|
||||
|
||||
|
@ -89,7 +90,7 @@ extern short cmd_credits(short channel, int argc, const char * argv[]);
|
|||
*/
|
||||
|
||||
short cli_screen = 0; /**< The default screen to use for the REPL of the CLI */
|
||||
char cli_command_path[MAX_PATH_LEN]; /**< Path to the command processor (empty string for built-in) */
|
||||
char cli_command_path[MAX_PATH_LEN]; /**< The path to the command processor */
|
||||
|
||||
/** The channel to use for interactions */
|
||||
short g_current_channel = 0;
|
||||
|
@ -149,14 +150,31 @@ const t_cli_command g_cli_commands[] = {
|
|||
* @param path the path to the command processor executable (0 or empty string for default)
|
||||
*/
|
||||
void cli_command_set(const char * path) {
|
||||
short i = 0;
|
||||
short result = 0;
|
||||
|
||||
if (path) {
|
||||
// Copy the desired path... without any trailing newline
|
||||
strncpy(cli_command_path, path, MAX_PATH_LEN);
|
||||
strtrimnl(cli_command_path);
|
||||
for (i = 0; i < strlen(path); i++) {
|
||||
char c = path[i];
|
||||
if ((c == CHAR_NL) || (c == CHAR_CR)) {
|
||||
cli_command_path[i] = 0;
|
||||
break;
|
||||
}
|
||||
cli_command_path[i] = c;
|
||||
}
|
||||
result = sys_var_set("SHELL", cli_command_path);
|
||||
if (result) {
|
||||
log(LOG_ERROR, "Unable to set SHELL");
|
||||
}
|
||||
|
||||
} else {
|
||||
// Set to the default CLI
|
||||
cli_command_path[0] = 0;
|
||||
result = sys_var_set("SHELL", 0);
|
||||
if (result) {
|
||||
log(LOG_ERROR, "Unable to set SHELL");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +185,12 @@ void cli_command_set(const char * path) {
|
|||
*/
|
||||
void cli_command_get(char * path) {
|
||||
// Copy the desired path
|
||||
strncpy(path, cli_command_path, MAX_PATH_LEN);
|
||||
const char * set_path = sys_var_get("SHELL");
|
||||
if (set_path) {
|
||||
strncpy(path, set_path, MAX_PATH_LEN);
|
||||
} else {
|
||||
path[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -540,18 +563,28 @@ short cmd_credits(short channel, int argc, const char * argv[]) {
|
|||
|
||||
print(channel, "\n");
|
||||
|
||||
sprintf(line, "| Version | %02d.%02d-alpha+%04d |\n", VER_MAJOR, VER_MINOR, VER_BUILD);
|
||||
print_box(channel, "{-------------------------------------------------------------}\n");
|
||||
print_box(channel, "| Foenix/MCP - A simple OS for Foenix Retro Systems computers |\n");
|
||||
print_box(channel, ">------------!------------------------------------------------<\n");
|
||||
sprintf(line, "| Version | %02d.%02d-alpha+%04d |\n", VER_MAJOR, VER_MINOR, VER_BUILD);
|
||||
print_box(channel, "{-------------------------------------------------------------------}\n");
|
||||
print_box(channel, "| Foenix/MCP - A simple OS for Foenix Retro Systems computers |\n");
|
||||
print_box(channel, ">---------------!---------------------------------------------------<\n");
|
||||
print_box(channel, line);
|
||||
print_box(channel, ">------------#------------------------------------------------<\n");
|
||||
print_box(channel, "| License | BSD-3-Clause |\n");
|
||||
print_box(channel, ">------------#------------------------------------------------<\n");
|
||||
print_box(channel, "| Creators | Foenix Retro Systems - Stefany Allaire |\n");
|
||||
print_box(channel, "| >------------------------------------------------<\n");
|
||||
print_box(channel, "| | Foenix/MCP - Peter Weingartner |\n");
|
||||
print_box(channel, "[------------@------------------------------------------------]\n");
|
||||
print_box(channel, ">---------------#---------------------------------------------------<\n");
|
||||
print_box(channel, "| License | BSD-3-Clause |\n");
|
||||
print_box(channel, ">---------------#---------------------------------------------------<\n");
|
||||
print_box(channel, "| Creators | Foenix Retro Systems - Stefany Allaire |\n");
|
||||
print_box(channel, "| >---------------------------------------------------<\n");
|
||||
print_box(channel, "| | Foenix/MCP - Peter Weingartner |\n");
|
||||
print_box(channel, ">---------------#---------------------------------------------------<\n");
|
||||
print_box(channel, "| License | BSD-3-Clause |\n");
|
||||
print_box(channel, ">---------------#---------------------------------------------------<\n");
|
||||
print_box(channel, "| Creators | Foenix Retro Systems - Stefany Allaire |\n");
|
||||
print_box(channel, "| >---------------------------------------------------<\n");
|
||||
print_box(channel, "| | Foenix/MCP - Peter Weingartner |\n");
|
||||
print_box(channel, ">---------------#---------------------------------------------------<\n");
|
||||
print_box(channel, "| Contributors | H\x86kan Th\x94rngren, Jesus Garcia, Vincent B. |\n");
|
||||
print_box(channel, ">---------------#---------------------------------------------------<\n");
|
||||
print_box(channel, "| Included Code | FatFS - http://elm-chan.org/fsw/ff/00index_e.html |\n");
|
||||
print_box(channel, "[---------------@---------------------------------------------------]\n");
|
||||
|
||||
print(channel, "\n\x1b[1mMake the machine yours!\x1b[0m\n");
|
||||
|
||||
|
@ -943,6 +976,7 @@ short cli_start_repl(short channel, const char * init_cwd) {
|
|||
}
|
||||
|
||||
// Start up the command shell
|
||||
cli_command_get(cli_command_path);
|
||||
if (cli_command_path[0] != 0) {
|
||||
// Over-ride path provided, boot it
|
||||
char * argv[1] = { cli_command_path };
|
||||
|
@ -966,7 +1000,7 @@ short cli_start_repl(short channel, const char * init_cwd) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return cli_repl(channel);
|
||||
}
|
||||
}
|
||||
|
@ -976,13 +1010,16 @@ short cli_start_repl(short channel, const char * init_cwd) {
|
|||
*/
|
||||
void cli_rerepl() {
|
||||
// Start up the command shell
|
||||
cli_command_get(cli_command_path);
|
||||
if (cli_command_path[0] != 0) {
|
||||
char * argv[1] = {cli_command_path};
|
||||
|
||||
// Over-ride path provided, boot it
|
||||
short result = sys_proc_run(cli_command_path, 1, argv);
|
||||
if (result) {
|
||||
print(0, "Unable to start: ");
|
||||
print(0, "Unable to start ");
|
||||
print(0, cli_command_path);
|
||||
print(0, ": ");
|
||||
print(0, err_message(result));
|
||||
while (1) ;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "snd/psg.h"
|
||||
#include "snd/sid.h"
|
||||
#include "snd/yamaha.h"
|
||||
#include "variables.h"
|
||||
#include "vicky_general.h"
|
||||
#include "fatfs/ff.h"
|
||||
#include "cli/cli.h"
|
||||
|
@ -131,6 +132,9 @@ void initialize() {
|
|||
// /* Hide the mouse */
|
||||
mouse_set_visible(0);
|
||||
|
||||
/* Initialize the variable system */
|
||||
var_init();
|
||||
|
||||
/* Initialize the text channels */
|
||||
txt_init();
|
||||
txt_a2560k_a_install();
|
||||
|
|
|
@ -88,6 +88,8 @@
|
|||
#define KFN_MEM_GET_RAMTOP 0x41 /* Get the upper limit of the top of system RAM */
|
||||
#define KFN_MEM_RESERVE 0x42 /* Reserve a block of memory at the top of system RAM */
|
||||
#define KFN_ELEVATE 0x43 /* Switch the user process to a full privilege */
|
||||
#define KFN_VAR_SET 0x44 /* Set the value of a system variable */
|
||||
#define KFN_VAR_GET 0x45 /* Get the value of a system variable */
|
||||
|
||||
/* Misc calls */
|
||||
|
||||
|
@ -773,6 +775,23 @@ extern short sys_kbd_layout(const char * tables);
|
|||
*/
|
||||
extern short sys_proc_run(const char * path, int argc, char * argv[]);
|
||||
|
||||
/**
|
||||
* Set the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @param value the value the variable should have
|
||||
* @return 0 on success, negative number on error
|
||||
*/
|
||||
extern short sys_var_set(const char *name, const char *value);
|
||||
|
||||
/**
|
||||
* Get the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @return pointer to the string on success, 0 if not found
|
||||
*/
|
||||
extern const char * sys_var_get(const char *name);
|
||||
|
||||
//
|
||||
// Text screen calls
|
||||
//
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "dev/rtc.h"
|
||||
#include "dev/txt_screen.h"
|
||||
#include "sys_general.h"
|
||||
#include "variables.h"
|
||||
|
||||
#if MODEL == MODEL_FOENIX_A2560K
|
||||
#include "dev/kbd_mo.h"
|
||||
|
@ -216,6 +217,12 @@ unsigned long syscall_dispatch(int32_t function, int32_t param0, int32_t param1,
|
|||
case KFN_MEM_RESERVE:
|
||||
return mem_reserve((unsigned long)param0);
|
||||
|
||||
case KFN_VAR_SET:
|
||||
return var_set((const char *)param0, (const char *)param1);
|
||||
|
||||
case KFN_VAR_GET:
|
||||
return (unsigned long)var_get((const char *)param0);
|
||||
|
||||
default:
|
||||
return ERR_GENERAL;
|
||||
}
|
||||
|
|
20414
src/mapfile
20414
src/mapfile
File diff suppressed because it is too large
Load diff
|
@ -728,6 +728,27 @@ short sys_proc_run(const char * path, int argc, char * argv[]) {
|
|||
return syscall(KFN_RUN, path, argc, argv);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @param value the value the variable should have
|
||||
* @return 0 on success, negative number on error
|
||||
*/
|
||||
short sys_var_set(const char *name, const char *value) {
|
||||
return syscall(KFN_VAR_SET, name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @return pointer to the string on success, 0 if not found
|
||||
*/
|
||||
const char * sys_var_get(const char *name) {
|
||||
return (const char *)syscall(KFN_VAR_GET, name);
|
||||
}
|
||||
|
||||
//
|
||||
// Text system calls
|
||||
//
|
||||
|
|
159
src/variables.c
Normal file
159
src/variables.c
Normal file
|
@ -0,0 +1,159 @@
|
|||
/** @file: variables.c
|
||||
*
|
||||
* Define routines to manage system variables
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "errors.h"
|
||||
#include "log.h"
|
||||
#include "utilities.h"
|
||||
#include "variables.h"
|
||||
|
||||
/*
|
||||
* Types
|
||||
*/
|
||||
|
||||
typedef struct s_var_entry {
|
||||
char * name;
|
||||
char * value;
|
||||
struct s_var_entry * next;
|
||||
} t_var_entry, *p_var_entry;
|
||||
|
||||
/*
|
||||
* Variables
|
||||
*/
|
||||
|
||||
/* Pointer to the first variable */
|
||||
static p_var_entry var_first_entry = 0;
|
||||
|
||||
/**
|
||||
* Initialize the system variables
|
||||
*/
|
||||
void var_init() {
|
||||
var_first_entry = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the entry matching the name
|
||||
*
|
||||
* @param name the name to find
|
||||
* @return a pointer to the entry, or 0 if not found
|
||||
*/
|
||||
p_var_entry var_find(const char * name) {
|
||||
TRACE("var_find");
|
||||
p_var_entry entry = var_first_entry;
|
||||
|
||||
while (entry) {
|
||||
if (strcicmp(name, entry->name) == 0) {
|
||||
// If found, return it...
|
||||
return entry;
|
||||
|
||||
} else {
|
||||
// Otherwise, try the next entry
|
||||
entry = entry->next;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to set the value of an entry
|
||||
*
|
||||
* NOTE: null value pointer will be translated to an empty string
|
||||
*
|
||||
* @param entry pointer to the entry to update
|
||||
* @param value pointer to the string to copy
|
||||
* @return 0 on success, negative number on error
|
||||
*/
|
||||
short var_set_value(p_var_entry entry, const char * value) {
|
||||
TRACE("var_set_value");
|
||||
|
||||
if (entry->value) {
|
||||
// Return the old value, if there is one
|
||||
free(entry->value);
|
||||
}
|
||||
|
||||
if (value != 0) {
|
||||
entry->value = malloc(strlen(value));
|
||||
if (entry->value == 0) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(entry->value, value);
|
||||
|
||||
} else {
|
||||
entry->value = malloc(1);
|
||||
if (entry->value == 0) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
entry->value[0] = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @param value the value the variable should have
|
||||
* @return 0 on success, negative number on error
|
||||
*/
|
||||
short var_set(const char *name, const char *value) {
|
||||
TRACE("var_set");
|
||||
|
||||
p_var_entry entry = var_find(name);
|
||||
short result = 0;
|
||||
|
||||
if (entry) {
|
||||
// Try to set the value
|
||||
return var_set_value(entry, value);
|
||||
|
||||
} else {
|
||||
// Not found... make a new entry
|
||||
entry = (p_var_entry)malloc(sizeof(t_var_entry));
|
||||
if (entry == 0) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
entry->value = 0;
|
||||
entry->name = 0;
|
||||
|
||||
// Make a copy of the name
|
||||
entry->name = malloc(strlen(name));
|
||||
if (entry->name == 0) {
|
||||
return ERR_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(entry->name, name);
|
||||
|
||||
// try to set the value
|
||||
result = var_set_value(entry, value);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Add the entry to the linked list
|
||||
entry->next = var_first_entry;
|
||||
var_first_entry = entry;
|
||||
|
||||
// Return success
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @return pointer to the string on success, 0 if not found
|
||||
*/
|
||||
const char * var_get(const char *name) {
|
||||
TRACE("var_get");
|
||||
p_var_entry entry = var_find(name);
|
||||
if (entry) {
|
||||
return entry->value;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
30
src/variables.h
Normal file
30
src/variables.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/** @file: variables.h
|
||||
*
|
||||
* Define routines to manage system variables
|
||||
*/
|
||||
|
||||
#ifndef __VARIABLES_H
|
||||
|
||||
/**
|
||||
* Initialize the system variables
|
||||
*/
|
||||
extern void var_init();
|
||||
|
||||
/**
|
||||
* Set the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @param value the value the variable should have
|
||||
* @return 0 on success, negative number on error
|
||||
*/
|
||||
extern short var_set(const char *name, const char *value);
|
||||
|
||||
/**
|
||||
* Get the value of a variable
|
||||
*
|
||||
* @param name the name of the variable to set
|
||||
* @return pointer to the string on success, 0 if not found
|
||||
*/
|
||||
extern const char * var_get(const char *name);
|
||||
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
#define __VERSION_H
|
||||
|
||||
#define VER_MAJOR 0
|
||||
#define VER_MINOR 75
|
||||
#define VER_BUILD 10
|
||||
#define VER_MINOR 80
|
||||
#define VER_BUILD 1
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue