Skip to content

Commit

Permalink
command parse improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Sep 14, 2023
1 parent fcf9e3d commit 178e8f3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 3 deletions.
77 changes: 77 additions & 0 deletions doc/ympshell.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
Ymp Shell
=========
You can create new ymp shell with **ymp shell** command or **ympsh** command. You can run ymp operations into shell.

.. code-block:: shell
ymp shell
-> Ymp >> install git
Commends
^^^^^^^^
You can use **#** symbol or **:** operdation (dummy)

.. code-block:: shell
# hello world
: Hello world
Escape & exclusive characters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**$** character used for variables.

.. code-block:: shell
set num 13
echo $num
**\\** character ignore next characters functions

.. code-block:: shell
set msg Hello\ World
echo $msg
**"** character define string

.. code-block:: shell
set msg "Hello World"
echo $msg
**`** character execute command and replace output with yourself

.. code-block:: shell
set dist `uname -a`
echo $dist
Conditions
^^^^^^^^^^
**If** segment used for conditions. If segment must starts with **if** and must ends with **endif**

.. code-block:: shell
read var
if eq 12 $var
echo equal to 12
endif
Labels and goto
^^^^^^^^^^^^^^^
You can define label and use **goto** word like this
.. code-block:: shell
label test
read var
if eq $var 0
exit
endif
echo $var
goto test
This program can simulate while loop
4 changes: 2 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ run_command('bash', './tool/mkctx.sh',

run_command('bash', './tool/check.sh', meson.current_build_dir(), check:true)
args = ['-O0', '-flto', '-Wall','-lm',
'-fvisibility=hidden', '-Wextra', '-Wno-unused-parameter','-s',
'-Wl,--gc-sections','-ffunction-sections',
'-fvisibility=hidden', '-Wextra', '-Wno-unused-parameter','-s', '-Os',
'-Wl,--gc-sections','-ffunction-sections', '-fno-math-errno', '-ffast-math',
'-fdata-sections', '-fno-exceptions']


Expand Down
9 changes: 9 additions & 0 deletions src/util/archive.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class archive {
set_archive_type ("zip", "none");
}
private void load_archive (string path) {
debug (_ ("Load archive : %s").printf (path));
archive = new Archive.Read ();
archive.support_filter_all ();
archive.support_format_all ();
Expand All @@ -89,6 +90,7 @@ public class archive {
//DOC: `bool is_archive (string path):`
//DOC: check file is archive
public bool is_archive (string path) {
debug (_ ("Is archive : %s").printf (path));
archive = new Archive.Read ();
archive.support_filter_all ();
archive.support_format_all ();
Expand All @@ -101,6 +103,8 @@ public class archive {
//DOC: `string[] archive.list_files ():`
//DOC: Get archive file list
public string[] list_files () {
debug (_ ("List files in archive"));

load_archive (archive_path);
unowned Archive.Entry entry;
string[] ret = {};
Expand All @@ -114,6 +118,8 @@ public class archive {
//DOC: `void archive.set_target (string path):`
//DOC: Change target directory for extract
public void set_target (string path) {
debug (_ ("Set archive target : %s").printf (path));

if (path != null) {
target_path = path;
}
Expand All @@ -123,6 +129,8 @@ public class archive {
//DOC: Add a file to archive create list
private string[] archive_add_list;
public void add (string path) {
debug (_ ("Add to archive : %s").printf (path));

if (archive_add_list == null) {
archive_add_list = {};
}
Expand All @@ -138,6 +146,7 @@ public class archive {
//DOC: `void archive.extract (string path):`
//DOC: Extract **path** file to target directory
public void extract (string path) {
debug (_ ("Extract archve: %s").printf (path));
load_archive (archive_path);
Archive.ExtractFlags flags;
flags = Archive.ExtractFlags.TIME;
Expand Down
3 changes: 3 additions & 0 deletions src/util/yamlparser.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class yamlfile {
//DOC: `bool yamlfile.has_area (string fdata, string path):`
//DOC: return true if **fdata** has **path** area
public bool has_area (string fdata, string path) {
debug (_ ("Has area : %s").printf (path));
foreach (string line in ssplit (fdata, "\n")) {
if (startswith (line, path + ":")) {
return true;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class yamlfile {

public string[] get_area_names (string fdata) {
string[] ret = {};
debug (_ ("Get area names"));
foreach (string line in ssplit (fdata, "\n")) {
if (!startswith (line, " ") && ":" in line) {
string name = ssplit (line, ":")[0];
Expand Down Expand Up @@ -154,6 +156,7 @@ public class yamlfile {
}

private string get_area_single (string fdata, string path) {
debug (_ ("Get area : %s").printf (path));
if (fdata == null || fdata == "") {
return "";
}
Expand Down
54 changes: 53 additions & 1 deletion src/ymp.vala
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,64 @@ public class Ymp {
if (line.length == 0) {
continue;
}
string[] proc_args = ssplit (line, " ");
string[] proc_args = split_args(line);
if (proc_args[0] != null) {
add_process (proc_args[0], proc_args[1:]);
}
}
}
private string[] split_args(string line){
array ret = new array();
string cur = "";
char c = '\0';
char cc = '\0';
int type = 0; // 0 = normal 1 = exec 2 = quota
for(int i = 0; i < line.length ; i++){
c = line[i];
if(c >= 1){
cc = line[i-1];
}
if(c == '\\'){
i += 1;
if(i >= line.length){
error_add("Unexceped line ending!");
error(31);
}
cur += line[i].to_string();
continue;
}
if(c == '`' && cc != '\\'){
if(type != 1){
type = 1;
ret.add(cur);
cur = "";
}else{
ret.add(getoutput(cur).strip());
cur = "";
type = 0;
}
continue;
}
if(c == '"' && cc != '\\'){
if(type != 2){
type = 2;
}else{
type = 0;
}
continue;
}
if(c == ' ' && cc != '\\'){
if(type == 0){
ret.add(cur);
cur = "";
continue;
}
}
cur += c.to_string();
}
ret.add(cur);
return ret.get();
}
}
//DOC: `string[] argument_process (string[] args):`
//DOC: Clear options and apply variables from argument
Expand Down

0 comments on commit 178e8f3

Please sign in to comment.