From 1e1a2f1c6e1d1b36b322366087c33c6fb380f91b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sat, 2 Aug 2025 17:22:13 +0200 Subject: [PATCH] remove_first --- sh/core/code.awk | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index 033fb47..ca712ae 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -58,6 +58,12 @@ function extract(string, type) { } } +function remove_first(string, target, tmp) { + tmp = string + sub(target, "", tmp) + return trim(tmp) +} + function trim(string) { text = string sub("^[\t ]*", "", text) @@ -106,34 +112,26 @@ function parse(string) { # module if (match(string, RE_MODULE)) { current_match = "module" - module = string - sub("#\\.", "", module) + module = remove_first(string, "#\\.") doc_reset() - module = trim(module) shebang = "" # shebang } else if (match(string, RE_SHEBANG)) { current_match = "shebang" - shebang = string - sub("#!", "", shebang) - shebang = trim(shebang) + shebang = remove_first(string, "#!") # alias } else if (match(string, re["alias"])) { current_match = "alias" - alias = string - sub("#=", "", alias) - alias = trim(alias) + alias = remove_first(string, "#=") aliases[alias] = "" doc_append("= " alias) # command } else if (match(string, re["command"])) { current_match = "command" - command = string - sub("#/", "", command) - command = trim(command) + command = remove_first(string, "#/") commands[command] = "" doc_append("/ " command)