Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
adesutherland committed Oct 10, 2024
1 parent 0edc9a2 commit d5afb3e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cmake_minimum_required(VERSION 3.18)
project(lib NONE)

add_subdirectory(rxfns)
add_subdirectory(plugins)
5 changes: 5 additions & 0 deletions lib/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.18)

project(plugins NONE)

add_subdirectory(sysinfo)
34 changes: 34 additions & 0 deletions lib/plugins/sysinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.10)
project(sysinfo_plugin C)

set(CMAKE_C_STANDARD 90)

# Including RXPA Build System
include(${CMAKE_SOURCE_DIR}/rxpa/RXPluginFunction.cmake)

# Create dynamic plugin module
add_dynamic_plugin_target(_sysinfo sysinfo.c)

# Build Test Rexx
add_custom_command(
COMMAND ${CMAKE_BINARY_DIR}/compiler/rxc
-i \"${CMAKE_BINARY_DIR}/lib/rxfns\;${CMAKE_CURRENT_BINARY_DIR}\"
-o sysinfo_test \"${CMAKE_CURRENT_SOURCE_DIR}/sysinfo_test\" &&
${CMAKE_BINARY_DIR}/assembler/rxas sysinfo_test

DEPENDS rxas rxc library _sysinfo ${CMAKE_CURRENT_SOURCE_DIR}/sysinfo_test.rexx
OUTPUT sysinfo_test.rxbin
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(sysinfo_test ALL
DEPENDS sysinfo_test.rxbin
)

# Enable testing functionality
enable_testing()

# Basic test to run sysinfo_test.rxbin with the sysinfo plugin
add_test(NAME sysinfo_test
COMMAND ${CMAKE_BINARY_DIR}/interpreter/rxvm sysinfo_test rx_sysinfo ${CMAKE_BINARY_DIR}/lib/rxfns/library
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
57 changes: 57 additions & 0 deletions lib/plugins/sysinfo/sysinfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// System Information Plugin for crexx/pa - Plugin Architecture
//
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // For POSIX systems (Linux/macOS)
#ifdef _WIN32
#include <direct.h> // For Windows
#define getcwd _getcwd // Map to Windows-specific version
#endif
#include "crexxpa.h" // crexx/pa - Plugin Architecture header file

// Function to get an environment variable
PROCEDURE(getEnv) {

// Should never happen as the compiler checks arguments; best practice is to check this anyway
if( NUM_ARGS != 1) RETURNSIGNAL(SIGNAL_INVALID_ARGUMENTS, "environment variable name expected") // sets the signal and returns

char *varName = GETSTRING(ARG(0)); // Get the environment variable name
char *varValue = getenv(varName); // Get the environment variable value

/* Set the return value */
if (varValue == NULL) {
// If the environment variable is not found
SETSTRING(RETURN, "");
}
else {
SETSTRING(RETURN, varValue);
}

// Make sure the signal is reset to ok - best practice
RESETSIGNAL
}

// Function to get the current working directory
PROCEDURE(getCwd) {
char cwd[1024];
// Should never happen as the compiler checks arguments; best practice is to check this anyway
if( NUM_ARGS != 0) RETURNSIGNAL(SIGNAL_INVALID_ARGUMENTS, "no arguments expected") // sets the signal and returns

if (getcwd(cwd, sizeof(cwd)) != NULL) {
/* Set the return value */
SETSTRING(RETURN, cwd);
} else {
RETURNSIGNAL(SIGNAL_FAILURE, "Unable to get current working directory")
}

// Make sure the signal is reset to ok - best practice
RESETSIGNAL
}

// Functions to be provided to rexx
LOADFUNCS
// C Function, REXX namespace & name, Option, Return Type, Arguments
ADDPROC(getEnv, "sysinfo.getenv", "b", ".string", "env_name=.string");
ADDPROC(getCwd, "sysinfo.getcwd", "b", ".string", "");
ENDLOADFUNCS
7 changes: 7 additions & 0 deletions lib/plugins/sysinfo/sysinfo_test.rexx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* SysInfo Plugin Test */
options levelb
import sysinfo

say "SysInfo Plugin Test"
say "getEnv(PATH) -" getEnv("PATH")
say "getCwd() -" getCwd()

0 comments on commit d5afb3e

Please sign in to comment.