From 26bde94da7ee3aecbe35fb8be6da03cd196263a5 Mon Sep 17 00:00:00 2001 From: Allan CORNET Date: Fri, 3 Jan 2025 22:19:32 +0100 Subject: [PATCH] feat(os_functions): add cmdsep function for command separation Fixes #1322 --- CHANGELOG.md | 1 + modules/os_functions/etc/finish.m | 4 +- modules/os_functions/etc/startup.m | 1 + modules/os_functions/functions/cmdsep.m | 19 ++++++ .../os_functions/help/en_US/xml/cmdsep.xml | 61 +++++++++++++++++++ modules/os_functions/module.iss | 2 +- modules/os_functions/tests/test_cmdsep.m | 15 +++++ 7 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 modules/os_functions/functions/cmdsep.m create mode 100644 modules/os_functions/help/en_US/xml/cmdsep.xml create mode 100644 modules/os_functions/tests/test_cmdsep.m diff --git a/CHANGELOG.md b/CHANGELOG.md index df7961ba2b..af22c5c5c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [#1322](http://github.com/nelson-lang/nelson/issues/1322) `cmdsep`: Command separator for current operating system. - `urlencode`: Replace special characters in URLs with escape characters. - `docroot`: Utility to retrieve or define the root directory of Nelson Help. - `ismodule`: second input argument `isprotected` added. diff --git a/modules/os_functions/etc/finish.m b/modules/os_functions/etc/finish.m index dd0b60071d..4fa26932fe 100644 --- a/modules/os_functions/etc/finish.m +++ b/modules/os_functions/etc/finish.m @@ -7,4 +7,6 @@ % SPDX-License-Identifier: LGPL-3.0-or-later % LICENCE_BLOCK_END %============================================================================= -removegateway(modulepath('os_functions', 'builtin')); \ No newline at end of file +rmpath(modulepath('os_functions', 'functions')); +removegateway(modulepath('os_functions', 'builtin')); +%============================================================================= diff --git a/modules/os_functions/etc/startup.m b/modules/os_functions/etc/startup.m index c95a462b2b..6622401dbe 100644 --- a/modules/os_functions/etc/startup.m +++ b/modules/os_functions/etc/startup.m @@ -8,4 +8,5 @@ % LICENCE_BLOCK_END %============================================================================= addgateway(modulepath('os_functions', 'builtin'), 'os_functions'); +addpath(modulepath('os_functions', 'functions'), '-frozen'); %============================================================================= \ No newline at end of file diff --git a/modules/os_functions/functions/cmdsep.m b/modules/os_functions/functions/cmdsep.m new file mode 100644 index 0000000000..b8429f9647 --- /dev/null +++ b/modules/os_functions/functions/cmdsep.m @@ -0,0 +1,19 @@ +%============================================================================= +% Copyright (c) 2016-present Allan CORNET (Nelson) +%============================================================================= +% This file is part of the Nelson. +%============================================================================= +% LICENCE_BLOCK_BEGIN +% SPDX-License-Identifier: LGPL-3.0-or-later +% LICENCE_BLOCK_END +%============================================================================= +function varargout = cmdsep(varargin) + nargoutchk(0, 1); + narginchk(0, 0); + if ispc() + varargout{1} = "&&"; + else + varargout{1} = ";"; + end +end +%============================================================================= diff --git a/modules/os_functions/help/en_US/xml/cmdsep.xml b/modules/os_functions/help/en_US/xml/cmdsep.xml new file mode 100644 index 0000000000..399c94937b --- /dev/null +++ b/modules/os_functions/help/en_US/xml/cmdsep.xml @@ -0,0 +1,61 @@ + + + SAME AS NELSON SOFTWARE + + en_US + cmdsep + Command separator for current operating system. + + + sep = cmdsep() + + + + + + sep + a string: on windows "&&", on linux ";" + + + + + +

cmdsep returns the command separator for current operating system.

+

This function is used by Nelson to build command lines for unix and dos operating systems.

+
+ + + + + + + nelson + + + + + + + + + + unix + + + + + + + 1.11.0 + initial version + + + + + Allan CORNET + +
diff --git a/modules/os_functions/module.iss b/modules/os_functions/module.iss index 2b42237f6f..9a8b6ae3d5 100644 --- a/modules/os_functions/module.iss +++ b/modules/os_functions/module.iss @@ -16,7 +16,7 @@ Source: {#RootPath}modules\{#MODULE_NAME}\loader.m; DestDir: {app}\modules\{#MOD Source: {#RootPath}modules\{#MODULE_NAME}\etc\startup.m; DestDir: {app}\modules\{#MODULE_NAME}\etc\; Source: {#RootPath}modules\{#MODULE_NAME}\etc\finish.m; DestDir: {app}\modules\{#MODULE_NAME}\etc\; ;============================================================================== -;Source: {#RootPath}modules\{#MODULE_NAME}\functions\*.m; DestDir: {app}\modules\{#MODULE_NAME}\functions\; +Source: {#RootPath}modules\{#MODULE_NAME}\functions\*.m; DestDir: {app}\modules\{#MODULE_NAME}\functions\; ;============================================================================== Source: {#RootPath}modules\{#MODULE_NAME}\help\*.qch; DestDir: {app}\modules\{#MODULE_NAME}\help\; Flags: recursesubdirs;Components: {#COMPONENT_HELP_FILES} and {#COMPONENT_HELP_BROWSER}; ;============================================================================== diff --git a/modules/os_functions/tests/test_cmdsep.m b/modules/os_functions/tests/test_cmdsep.m new file mode 100644 index 0000000000..d583021bcc --- /dev/null +++ b/modules/os_functions/tests/test_cmdsep.m @@ -0,0 +1,15 @@ +%============================================================================= +% Copyright (c) 2016-present Allan CORNET (Nelson) +%============================================================================= +% This file is part of the Nelson. +%============================================================================= +% LICENCE_BLOCK_BEGIN +% SPDX-License-Identifier: LGPL-3.0-or-later +% LICENCE_BLOCK_END +%============================================================================= +if ispc() + assert_isequal(cmdsep(), "&&"); +else + assert_isequal(cmdsep(), ";"); +end +%=============================================================================