diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2023-06-21 17:18:22 +1200 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2023-06-21 17:18:22 +1200 |
| commit | 5c799ffa098f6c9b6d88513c2662968a9f5aaa41 (patch) | |
| tree | 16124789c04fbe52b2b51266e299f7d26259955f | |
| parent | 185015b39b8db953b8034f29724ef03de09e7ea1 (diff) | |
| download | YATwm-5c799ffa098f6c9b6d88513c2662968a9f5aaa41.tar.gz YATwm-5c799ffa098f6c9b6d88513c2662968a9f5aaa41.zip | |
feat: Made a proper arg parser
Now supports quotes properly, and uses \ to escape characters
| -rw-r--r-- | commands.cpp | 62 | ||||
| -rw-r--r-- | config.cpp | 2 | ||||
| -rw-r--r-- | readme.html | 90 | ||||
| -rw-r--r-- | readme.org | 10 |
4 files changed, 103 insertions, 61 deletions
diff --git a/commands.cpp b/commands.cpp index 4e8e01b..de7d81e 100644 --- a/commands.cpp +++ b/commands.cpp @@ -72,18 +72,60 @@ Command* CommandsModule::lookupCommand(string name) vector<string> CommandsModule::splitCommand(string command) { vector<string> v; - string regexString = "((?:\"[^\"\n]+\")|(?:'[^'\n]+')|(?:[^ \n]+))+"; - std::regex regex(regexString, std::regex_constants::_S_icase); - auto begin = std::sregex_iterator(command.begin(), command.end(), regex); - auto end = std::sregex_iterator(); - for (std::sregex_iterator i = begin; i != end; i++) + string arg = ""; + bool inQuotes = false; + bool escapeNext = true; + char quoteType; + for(int i = 0; i < command.size(); i++) { - std::smatch match = *i; - std::string str = match.str(); - if(str[0] == '\'' || str[0] == '"') - str = str.substr(1, str.size() - 2); - v.push_back(str); + if(escapeNext) + { + arg += command[i]; + escapeNext = false; + } + else if(command[i] == '\\') + { + escapeNext = true; + } + else if(inQuotes) + { + if(command[i] == quoteType) + { + if(arg != "") + { + v.push_back(arg); + arg = ""; + } + inQuotes = false; + } + else + { + arg += command[i]; + } + } + else + { + if(command[i] == ' ') + { + if(arg != "") + { + v.push_back(arg); + arg = ""; + } + } + else if(command[i] == '"' || command[i] == '\'') + { + inQuotes = true; + quoteType = command[i]; + } + else + { + arg += command[i]; + } + } } + if(arg != "") + v.push_back(arg); return v; } @@ -98,6 +98,7 @@ std::vector<Err> Config::loadFromFile(std::string path) int line = 0; while(getline(config, cmd)) { + line++; if(cmd.size() == 0) continue; if(cmd.at(0) == '#') @@ -111,7 +112,6 @@ std::vector<Err> Config::loadFromFile(std::string path) errs.push_back({e.code, "Error in config (line " + std::to_string(line) + "): " + std::to_string(e.code) + "\n\tMessage: " + e.message}); } - line++; } loaded = true; return errs; diff --git a/readme.html b/readme.html index 38a81bc..24514ae 100644 --- a/readme.html +++ b/readme.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> -<!-- 2023-06-18 Sun 21:31 --> +<!-- 2023-06-21 Wed 17:18 --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>YATwm</title> @@ -200,36 +200,36 @@ <h2>Table of Contents</h2> <div id="text-table-of-contents" role="doc-toc"> <ul> -<li><a href="#org4543ad1">1. This config is best read in Emacs!</a></li> -<li><a href="#org8c9779d">2. Disclaimer: This is still very much in beta</a></li> -<li><a href="#orgd6a129e">3. Usage instructions</a> +<li><a href="#org286e38a">1. This config is best read in Emacs!</a></li> +<li><a href="#orgd129d06">2. Disclaimer: This is still very much in beta</a></li> +<li><a href="#org227444d">3. Usage instructions</a> <ul> -<li><a href="#org71e2ad0">3.1. Installation</a> +<li><a href="#org2311255">3.1. Installation</a> <ul> -<li><a href="#org4c27fc8">3.1.1. Pre reqs</a></li> -<li><a href="#org4738b76">3.1.2. Installing and removing</a></li> +<li><a href="#org4917590">3.1.1. Pre reqs</a></li> +<li><a href="#org69279ee">3.1.2. Installing and removing</a></li> </ul> </li> -<li><a href="#org48288fb">3.2. Config</a> +<li><a href="#org32292f7">3.2. Config</a> <ul> -<li><a href="#org78ac98a">3.2.1. Syntax</a></li> -<li><a href="#org70839ee">3.2.2. General</a></li> -<li><a href="#org7a3dcb5">3.2.3. Workspaces</a></li> -<li><a href="#org47d354f">3.2.4. Keybinds</a></li> +<li><a href="#org70b22f3">3.2.1. Syntax</a></li> +<li><a href="#orgc95e486">3.2.2. General</a></li> +<li><a href="#org525c2d1">3.2.3. Workspaces</a></li> +<li><a href="#org657af4b">3.2.4. Keybinds</a></li> </ul> </li> </ul> </li> -<li><a href="#org328b75f">4. Credits</a></li> +<li><a href="#org41cf547">4. Credits</a></li> </ul> </div> </div> -<div id="outline-container-org4543ad1" class="outline-2"> -<h2 id="org4543ad1"><span class="section-number-2">1.</span> This config is best read in Emacs!</h2> +<div id="outline-container-org286e38a" class="outline-2"> +<h2 id="org286e38a"><span class="section-number-2">1.</span> This config is best read in Emacs!</h2> </div> -<div id="outline-container-org8c9779d" class="outline-2"> -<h2 id="org8c9779d"><span class="section-number-2">2.</span> Disclaimer: This is still very much in beta</h2> +<div id="outline-container-orgd129d06" class="outline-2"> +<h2 id="orgd129d06"><span class="section-number-2">2.</span> Disclaimer: This is still very much in beta</h2> <div class="outline-text-2" id="text-2"> <p> This only just works, multiple monitors aren't supported and floating windows cannot move and there is no resizing. Many features are just hacked together and are likely to break. However, it is just about usable so if you really want to try then go for it! (feel free to make an issue if you have any questions).<br /> @@ -237,16 +237,16 @@ This only just works, multiple monitors aren't supported and floating windows ca </div> </div> -<div id="outline-container-orgd6a129e" class="outline-2"> -<h2 id="orgd6a129e"><span class="section-number-2">3.</span> Usage instructions</h2> +<div id="outline-container-org227444d" class="outline-2"> +<h2 id="org227444d"><span class="section-number-2">3.</span> Usage instructions</h2> <div class="outline-text-2" id="text-3"> </div> -<div id="outline-container-org71e2ad0" class="outline-3"> -<h3 id="org71e2ad0"><span class="section-number-3">3.1.</span> Installation</h3> +<div id="outline-container-org2311255" class="outline-3"> +<h3 id="org2311255"><span class="section-number-3">3.1.</span> Installation</h3> <div class="outline-text-3" id="text-3-1"> </div> -<div id="outline-container-org4c27fc8" class="outline-4"> -<h4 id="org4c27fc8"><span class="section-number-4">3.1.1.</span> Pre reqs</h4> +<div id="outline-container-org4917590" class="outline-4"> +<h4 id="org4917590"><span class="section-number-4">3.1.1.</span> Pre reqs</h4> <div class="outline-text-4" id="text-3-1-1"> <ul class="org-ul"> <li><code>Xlib</code> and <code>g++</code> and <code>libnotify</code> to build the program<br /></li> @@ -258,8 +258,8 @@ This only just works, multiple monitors aren't supported and floating windows ca </ul> </div> </div> -<div id="outline-container-org4738b76" class="outline-4"> -<h4 id="org4738b76"><span class="section-number-4">3.1.2.</span> Installing and removing</h4> +<div id="outline-container-org69279ee" class="outline-4"> +<h4 id="org69279ee"><span class="section-number-4">3.1.2.</span> Installing and removing</h4> <div class="outline-text-4" id="text-3-1-2"> <ul class="org-ul"> <li><code>make i</code> or <code>make install</code> to install<br /></li> @@ -269,23 +269,23 @@ This only just works, multiple monitors aren't supported and floating windows ca </div> </div> </div> -<div id="outline-container-org48288fb" class="outline-3"> -<h3 id="org48288fb"><span class="section-number-3">3.2.</span> Config</h3> +<div id="outline-container-org32292f7" class="outline-3"> +<h3 id="org32292f7"><span class="section-number-3">3.2.</span> Config</h3> <div class="outline-text-3" id="text-3-2"> <p> You can configure YATwm with the config file in <code>$HOME/.config/YATwm/config</code> or <code>$XDG_CONFIG_HOME/YATwm/config</code> if you have that set. I have provided an example config file in the project dir that has all the variables set to their defaults (this will also be installed to <code>/etc/YATwm/config</code>.<br /> It should alert you with a notification if you have an error, and put the error your log file. If the whole file is missing then it will use the default in <code>/etc/YATwm/config</code>.<br /> </p> </div> -<div id="outline-container-org78ac98a" class="outline-4"> -<h4 id="org78ac98a"><span class="section-number-4">3.2.1.</span> Syntax</h4> +<div id="outline-container-org70b22f3" class="outline-4"> +<h4 id="org70b22f3"><span class="section-number-4">3.2.1.</span> Syntax</h4> <div class="outline-text-4" id="text-3-2-1"> <p> -The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the <code>gaps</code> command like this <code>gaps 10</code> (make sure this is all there is on that line). This says to call the command <code>gaps</code> with the arguments of <code>10</code>. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. <code>addWorkspace "1: A" 1</code>, here the arguments are <code>1: A</code> and <code>1</code>.<br /> +The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the <code>gaps</code> command like this <code>gaps 10</code> (make sure this is all there is on that line). This says to call the command <code>gaps</code> with the arguments of <code>10</code>. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. <code>addWorkspace "1: A" 1</code>, here the arguments are <code>1: A</code> and <code>1</code>. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with <code>\</code> (e.g. <code>\'</code>), to insert <code>\</code> then use <code>\\</code>.<br /> </p> </div> <ol class="org-ol"> -<li><a id="orgf44e4fe"></a>Command arg types<br /> +<li><a id="org10dc20b"></a>Command arg types<br /> <div class="outline-text-5" id="text-3-2-1-1"> <ul class="org-ul"> <li>String: this is just some text, this can be wrapped in quotes if you want a space in it.<br /></li> @@ -302,17 +302,17 @@ The config file is a list of commands. Each command should be on a new line. For </ul> </div> </li> -<li><a id="org8b55f35"></a>List of commands<br /> +<li><a id="orgac1b7f4"></a>List of commands<br /> <div class="outline-text-5" id="text-3-2-1-2"> <ul class="org-ul"> <li>exit: shuts down YATwm<br /></li> <li>spawn: Spawns an application using <code>execvp</code><br /> <ul class="org-ul"> -<li>String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes)<br /></li> +<li>String rest: what to spawn, first word is the command, and following words are arguments<br /></li> </ul></li> <li>spawnOnce: Same as spawn but only runs on the first load of the config file<br /> <ul class="org-ul"> -<li>String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes)<br /></li> +<li>String rest: what to spawn, first word is the command, and following words are arguments<br /></li> </ul></li> <li>toggle: Changes the tiling direction for the next window<br /></li> <li>kill: Kills the focused window<br /></li> @@ -330,11 +330,11 @@ The config file is a list of commands. Each command should be on a new line. For </ul></li> <li>bashSpawn: Spawns something uses <code>system</code> (your shell)<br /> <ul class="org-ul"> -<li>String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes)<br /></li> +<li>String rest: A string which gets sent to bash<br /></li> </ul></li> <li>bashSpawnOnce: Same as bashSpawn but only runs on the first load of the config file<br /> <ul class="org-ul"> -<li>String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes)<br /></li> +<li>String rest: A string which gets sent to bash<br /></li> </ul></li> <li>reload: Reloads YATwm, this reloads the config file and re runs the monitor detection, and will unmap and remap all windows to refresh them.<br /></li> <li>nextMonitor: Focuses the next monitor, wraps around.<br /></li> @@ -367,8 +367,8 @@ The config file is a list of commands. Each command should be on a new line. For </li> </ol> </div> -<div id="outline-container-org70839ee" class="outline-4"> -<h4 id="org70839ee"><span class="section-number-4">3.2.2.</span> General</h4> +<div id="outline-container-orgc95e486" class="outline-4"> +<h4 id="orgc95e486"><span class="section-number-4">3.2.2.</span> General</h4> <div class="outline-text-4" id="text-3-2-2"> <p> You can change either the inner gaps (padding around each window - so double it for space between windows), or the outer gaps (padding around the display - add to inner gaps to get space between window and screen edges).<br /> @@ -378,8 +378,8 @@ YATwm also keeps a log file, the location of this file can be changed with the c </div> </div> -<div id="outline-container-org7a3dcb5" class="outline-4"> -<h4 id="org7a3dcb5"><span class="section-number-4">3.2.3.</span> Workspaces</h4> +<div id="outline-container-org525c2d1" class="outline-4"> +<h4 id="org525c2d1"><span class="section-number-4">3.2.3.</span> Workspaces</h4> <div class="outline-text-4" id="text-3-2-3"> <p> You can add workspace with the command <code>addworkspace</code> in the config file.<br /> @@ -405,8 +405,8 @@ Defaults workspace are listed below (these are the args for the addworkspace com </ol> </div> </div> -<div id="outline-container-org47d354f" class="outline-4"> -<h4 id="org47d354f"><span class="section-number-4">3.2.4.</span> Keybinds</h4> +<div id="outline-container-org657af4b" class="outline-4"> +<h4 id="org657af4b"><span class="section-number-4">3.2.4.</span> Keybinds</h4> <div class="outline-text-4" id="text-3-2-4"> <p> Current keybinds (these can all be edited):<br /> @@ -449,8 +449,8 @@ Commands are executed going down the list and multiple commands with the same ke </div> </div> -<div id="outline-container-org328b75f" class="outline-2"> -<h2 id="org328b75f"><span class="section-number-2">4.</span> Credits</h2> +<div id="outline-container-org41cf547" class="outline-2"> +<h2 id="org41cf547"><span class="section-number-2">4.</span> Credits</h2> <div class="outline-text-2" id="text-4"> <p> Catwm (<a href="https://github.com/pyknite/catwm">https://github.com/pyknite/catwm</a>)<br /> @@ -463,7 +463,7 @@ basic<sub>wm</sub> (<a href="https://github.com/jichu4n/basic_wm">https://github </div> </div> <div id="postamble" class="status"> -<p class="date">Created: 2023-06-18 Sun 21:31</p> +<p class="date">Created: 2023-06-21 Wed 17:18</p> <p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p> </div> </body> @@ -20,7 +20,7 @@ This only just works, multiple monitors aren't supported and floating windows ca You can configure YATwm with the config file in ~$HOME/.config/YATwm/config~ or ~$XDG_CONFIG_HOME/YATwm/config~ if you have that set. I have provided an example config file in the project dir that has all the variables set to their defaults (this will also be installed to ~/etc/YATwm/config~. It should alert you with a notification if you have an error, and put the error your log file. If the whole file is missing then it will use the default in ~/etc/YATwm/config~. *** Syntax -The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the ~gaps~ command like this ~gaps 10~ (make sure this is all there is on that line). This says to call the command ~gaps~ with the arguments of ~10~. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. ~addWorkspace "1: A" 1~, here the arguments are ~1: A~ and ~1~. +The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the ~gaps~ command like this ~gaps 10~ (make sure this is all there is on that line). This says to call the command ~gaps~ with the arguments of ~10~. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. ~addWorkspace "1: A" 1~, here the arguments are ~1: A~ and ~1~. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with ~\~ (e.g. ~\'~), to insert ~\~ then use ~\\~. **** Command arg types - String: this is just some text, this can be wrapped in quotes if you want a space in it. - String rest: This will only ever be the final argument. This just takes the rest of the line as a string, so you can use spaces without needing quotes. @@ -34,9 +34,9 @@ The config file is a list of commands. Each command should be on a new line. For **** List of commands - exit: shuts down YATwm - spawn: Spawns an application using ~execvp~ - - String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes) + - String rest: what to spawn, first word is the command, and following words are arguments - spawnOnce: Same as spawn but only runs on the first load of the config file - - String rest: what to spawn, first word is the command, and following words are arguments (note: due to limitations with the command system you cannot use quotes) + - String rest: what to spawn, first word is the command, and following words are arguments - toggle: Changes the tiling direction for the next window - kill: Kills the focused window - changeWS: changes to a different workspace @@ -46,9 +46,9 @@ The config file is a list of commands. Each command should be on a new line. For - focChange: Changes the focus in a direction - Direction: Which direction to focus in - bashSpawn: Spawns something uses ~system~ (your shell) - - String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes) + - String rest: A string which gets sent to bash - bashSpawnOnce: Same as bashSpawn but only runs on the first load of the config file - - String rest: A string which gets sent to bash (note: due to limitations with the command system you cannot use quotes) + - String rest: A string which gets sent to bash - reload: Reloads YATwm, this reloads the config file and re runs the monitor detection, and will unmap and remap all windows to refresh them. - nextMonitor: Focuses the next monitor, wraps around. - gaps: Sets the size of the inner gaps, margins around each window (this ends up looking doubled as each window has it) |
