|
Pieters bash scripts
Documentation for the bash scripts I have published
|
This script transforms bash scripts into php-ish that Doxygen can parse. More...
Go to the source code of this file.
Functions | |
| test () | |
| This is a function just to test the function declaration option not used in the rest of this document. | |
| test2 () | |
| This is a function just to test the function declaration option not used in the rest of this document. | |
| test3 () | |
| This is a function just to test the function declaration option not used in the rest of this document. | |
| get_next_char () | |
| Reads the next character from the input stream. | |
| strip_quotes_if_variable ($arg1) | |
| Removes the leading and trailing double quotes " from the given string. | |
| consume_whitespaces ($arg1) | |
| Discard whitespaces (except newline) from the input stream. | |
| consume_until_cmd_separator () | |
| Append everything to $token untill a command separator is encountered. | |
| consume_until_non_word_char () | |
| Append everything to $token untill a non word character is encountered. | |
| consume_until_closing_quote ($arg1) | |
| Append everything to $token untill a closing quote is encountered. | |
| consume_until_closing_square_bracket () | |
| Append everything to $token until the matching closing bracket (']') is encountered. | |
| consume_until_closing_parenthesis () | |
| Consumes all characters until a matching closing parenthesis is found. | |
| consume_until_space () | |
| Append everything to $token untill a whitespace is encountered. | |
| parse_comment () | |
| Parse the comment and add it to the inherited composition array. | |
| parse_variable () | |
| Parse a variable and add it to the inherited composition array. | |
| parse_function () | |
| Parse a function declaration and add it to the inherited composition array. | |
| parse_command () | |
| Parse a function or command call and add it to the inherited composition array. | |
| consume_until_keyword () | |
| consumes input until the keyword ($arg1) has been found. | |
| parse_flow_control () | |
| Parse a flow control statement and add it to the inherited composition array. | |
| parse_case () | |
| Gets the condition of the switch. | |
| parse_case_option () | |
| Gets the value of the switch case. | |
| parse_assignment () | |
| Extract variable name and value from assignment statements. | |
| parse () | |
| Parses an sh file into a composition. | |
| get_composition_element_size ($arg1) | |
| Calculate the offset of the next element in components based on the current one. | |
| update_function ($arg1) | |
| Extract function arguments ($n) and updates the function accordingly. | |
| analyse () | |
| Analyses the composition and updates information if required. | |
| parse_condition () | |
| Helper for sanitize_condition, parses the condition into variables and operators. | |
| sanitize_condition () | |
| Helper for write_as_php, cleans up the conditionals. | |
| sanitize_var ($arg1) | |
| Sanitize a variable. | |
| sanitize_assignment ($arg1) | |
| Sanitize an assignment (right hand side argument of assignment). | |
Variables | |
| const | $C_SUCCESS = 0 |
| Return value for success. | |
| const | $C_PARSE_ERROR = 1 |
| Return value on parse error. | |
| const | $C_ANALYSIS_ERROR = 2 |
| Return value on error when analysing parsed composition. | |
| const | $C_WRITE_ERROR = 3 |
| Return value on error when writing result. | |
This script transforms bash scripts into php-ish that Doxygen can parse.
Author: Pieter van der Star (info@.nosp@m.piet.nosp@m.ervan.nosp@m.ders.nosp@m.tar.n.nosp@m.l)
Modifications by: (unmodified)
Review function documentation.
Add support for [[ regex without if.
Add support for "source <script>".
Add support for line continuation ("\" followed by newline).
Add return type other than int if the function doesn't contain a return statement. (Also handle return void.)
Count the newlines in multiline condition (when using heredocs) for linenumber in error messages.
The line number for variable errors (such as incorrect flag to declare) seems to be one line too early.
When the source document is updated while the filter is running the filter sometimes ends up in an endless loop showing the error "Unknown item in get_composition_element_size".
This script works by parsing the Bash script file and then outputting matching PHP code on stdout. The parsing stores each tokens in one big flat array. This array is called composition. To identify each kind of token the first element is an identifier, which determines how many elements follow. Thy are stored as listed in the table below:
| Purpose | Identifier | Elements[1] | Purpose of element |
|---|---|---|---|
| shebang | ! | 1 | Contents of the shebang |
| Doxygen comment | d | 1 | Contents of the comment |
| comment | # | 1 | Contents fo the comment |
| newline | n | - | |
| variable | v | 1 | Indicates readonly variable |
| 2 | Type of the variable | ||
| 3 | Name of the variable | ||
| 4 | Assigned value, or empty if not assigned | ||
| function | f | 1 | Name of the function |
| 2 | Number of parameters, can be 0 if none | ||
| >2 (odd) | Name of the parameter | ||
| >2 (even) | Type of the parameter | ||
| scope opening | { | - | |
| scope closing | } | - | |
| command/function call | c | 1 | The command |
| 2 | Number of arguments, can be 0 if none | ||
| >2 | Parameter values | ||
| flow control | j | 1 | Type of control (if, while else etc) |
| 2 | The condition | ||
| return statement | r | - | |
| variable assignment | = | 1 | The operand |
| 2 | The operator | ||
| 3 | The value | ||
| whitespace | w | 1 | The value |
| switch option | o | 1 | The value |
| break statement (;;) | - |
1 Elements is the index of the element after the identifier.
Definition in file doxygen-bash-filter.sh.
| analyse | ( | ) |
Analyses the composition and updates information if required.
Definition at line 934 of file doxygen-bash-filter.sh.

| consume_until_closing_parenthesis | ( | ) |
Consumes all characters until a matching closing parenthesis is found.
Definition at line 335 of file doxygen-bash-filter.sh.
| consume_until_closing_quote | ( | $arg1 | ) |
Append everything to $token untill a closing quote is encountered.
| $arg1 | Should the characters be appended to $token? (1 yes, !=1 no) |
Definition at line 279 of file doxygen-bash-filter.sh.

| consume_until_closing_square_bracket | ( | ) |
Append everything to $token until the matching closing bracket (']') is encountered.
Definition at line 305 of file doxygen-bash-filter.sh.
| consume_until_cmd_separator | ( | ) |
Append everything to $token untill a command separator is encountered.
Definition at line 234 of file doxygen-bash-filter.sh.


| consume_until_keyword | ( | ) |
consumes input until the keyword ($arg1) has been found.
| $arg1 | Keyword to search for. |
| $C_SUCCESS | if keyword found. |
| $C_PARSE_ERROR | if keyword not found before end of file occurred. |
Definition at line 567 of file doxygen-bash-filter.sh.

| consume_until_non_word_char | ( | ) |
Append everything to $token untill a non word character is encountered.
Definition at line 266 of file doxygen-bash-filter.sh.

| consume_until_space | ( | ) |
Append everything to $token untill a whitespace is encountered.
Definition at line 362 of file doxygen-bash-filter.sh.

| consume_whitespaces | ( | $arg1 | ) |
Discard whitespaces (except newline) from the input stream.
| $arg1 | Should the characters be appended to token? (1 yes, !=1 no) |
Definition at line 208 of file doxygen-bash-filter.sh.

| get_composition_element_size | ( | $arg1 | ) |
Calculate the offset of the next element in components based on the current one.
| $arg1 | Index of the composition element to get the offset for. |
Definition at line 825 of file doxygen-bash-filter.sh.

| get_next_char | ( | ) |
Reads the next character from the input stream.
Definition at line 183 of file doxygen-bash-filter.sh.

| parse | ( | ) |
Parses an sh file into a composition.
the input script. Call like parse < "inputfile.sh".
Definition at line 696 of file doxygen-bash-filter.sh.
| parse_assignment | ( | ) |
Extract variable name and value from assignment statements.
Adds the assignment information to the composition.
Definition at line 666 of file doxygen-bash-filter.sh.
| parse_case | ( | ) |
Gets the condition of the switch.
Definition at line 633 of file doxygen-bash-filter.sh.

| parse_case_option | ( | ) |
Gets the value of the switch case.
Definition at line 649 of file doxygen-bash-filter.sh.
| parse_command | ( | ) |
Parse a function or command call and add it to the inherited composition array.
Definition at line 501 of file doxygen-bash-filter.sh.
| parse_comment | ( | ) |
Parse the comment and add it to the inherited composition array.
Definition at line 378 of file doxygen-bash-filter.sh.
| parse_condition | ( | ) |
Helper for sanitize_condition, parses the condition into variables and operators.
Definition at line 955 of file doxygen-bash-filter.sh.

| parse_flow_control | ( | ) |
Parse a flow control statement and add it to the inherited composition array.
Definition at line 591 of file doxygen-bash-filter.sh.
| parse_function | ( | ) |
Parse a function declaration and add it to the inherited composition array.
Definition at line 474 of file doxygen-bash-filter.sh.
| parse_variable | ( | ) |
Parse a variable and add it to the inherited composition array.
Definition at line 409 of file doxygen-bash-filter.sh.

| sanitize_assignment | ( | $arg1 | ) |
Sanitize an assignment (right hand side argument of assignment).
| $arg1 | Assignment to sanitize |
clean the switch option value and replace single | or operator with phps dual ||.
| $arg1 | The option string to sanitize. |
Write the php
| $arg1 | Include the <?php and ?> tags. If value is 1 then the tags are included, |
Writes the inherited composition as php to stdout.
Variable for iterating over the composition.
Main function
| $arg1 | Input file to rewrite to doxygen parsable php. |
Definition at line 1129 of file doxygen-bash-filter.sh.
| sanitize_condition | ( | ) |
Helper for write_as_php, cleans up the conditionals.
Removes bash brackets around condition. The behaviour is too tightly coupled to the writing of php for this to be part of tha analysis stage, in practise this function is doing both analysis and writing.
Definition at line 1021 of file doxygen-bash-filter.sh.
| sanitize_var | ( | $arg1 | ) |
Sanitize a variable.
| $arg1 | Variable to sanitize |
The behaviour is too tightly coupled to the writing of php for this to be part of tha analysis stage, in practise this function is doing both analysis and writing.
Definition at line 1101 of file doxygen-bash-filter.sh.
| strip_quotes_if_variable | ( | $arg1 | ) |
Removes the leading and trailing double quotes " from the given string.
| $arg1 | Name of the string variable to remove the quotes from |
Definition at line 193 of file doxygen-bash-filter.sh.
| test | ( | ) |
This is a function just to test the function declaration option not used in the rest of this document.
Definition at line 167 of file doxygen-bash-filter.sh.
| test2 | ( | ) |
This is a function just to test the function declaration option not used in the rest of this document.
Definition at line 171 of file doxygen-bash-filter.sh.
| test3 | ( | ) |
This is a function just to test the function declaration option not used in the rest of this document.
Definition at line 176 of file doxygen-bash-filter.sh.
| update_function | ( | $arg1 | ) |
Extract function arguments ($n) and updates the function accordingly.
| $arg1 | Index of the fuction in the composition. |
Updates the function in the composition.
Definition at line 869 of file doxygen-bash-filter.sh.

