-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0edc9a2
commit d5afb3e
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ cmake_minimum_required(VERSION 3.18) | |
project(lib NONE) | ||
|
||
add_subdirectory(rxfns) | ||
add_subdirectory(plugins) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |