Skip to content

Commit

Permalink
Use scdoc instead of md2man
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Gladkov <[email protected]>
  • Loading branch information
legionus committed May 24, 2019
1 parent d6096c1 commit c280119
Show file tree
Hide file tree
Showing 24 changed files with 370 additions and 429 deletions.
3 changes: 2 additions & 1 deletion COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ are Copyright (C) 2008 Stanislav Ievlev <[email protected]>,
The files
shell-version, shell-cmdline, shell-config, shell-error,
shell-ip-address, shell-mail-address, shell-unittest,
shell-signal, shell-var, shell-source shell-run
shell-signal, shell-var, shell-source, shell-run,
shell-terminfo, shell-temp, shell-git-config
are Copyright (C) 2009-2011 Alexey Gladkov <[email protected]>

All files in this package may be freely copied under the terms
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ GEN_SYMS = $(CURDIR)/gen-syms.sh
GEN_SINGLE = $(CURDIR)/gen-single.sh
GEN_VERS = $(CURDIR)/gen-version.sh

# github.com/legionus/md2man
MD2MAN ?= md2man
# https://git.sr.ht/~sircmpwn/scdoc
SCDOC ?= scdoc

PROJECT = libshell
VERSION = $(shell $(GEN_VERS))
Expand Down Expand Up @@ -40,7 +40,9 @@ shell-regexp: shell-quote
ln -s $^ $@

%.3: %.md
@[ -z "$(MD2MAN)" ] || $(MD2MAN) -output $@ $<
@[ -z "$(SCDOC)" ] || $(SCDOC) < $< > $@

man: ${man_TARGETS}

install: install-bin install-man install-data $(SUBDIRS)

Expand All @@ -57,7 +59,7 @@ install-bin: ${bin_TARGETS}
cp -a $^ ${DESTDIR}${bindir}/

install-man: ${man_TARGETS}
if [ -n "$(MD2MAN)" ]; then \
if [ -n "$(SCDOC)" ]; then \
install -d -m755 ${DESTDIR}${man3dir}; \
install -m644 $^ ${DESTDIR}${man3dir}; \
fi
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
libshell
=======
# libshell

This project contains common functions for shell projects to increase code reuse.
The libshell is a set of the most commonly-used shell functions. All functions use minimum
of external utilities and written for POSIX shell.

LICENSE
-------
## Install

Install dependencies:

- coreutils
- [scdoc](https://git.sr.ht/~sircmpwn/scdoc) (optional: man pages)

## Documentation

See [docs](docs/libshell.md)

## LICENSE

Libshell is licensed under the GNU General Public License version 2.
17 changes: 17 additions & 0 deletions docs/.template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
shell-???(3)

# NAME

# SYNOPSIS

# DESCRIPTION

# ENVIRONMENT

# AUTHOR
Authors and contributors of the programs included in the *libshell* package are listed
in the COPYING file.

# BUGS
Report bugs to the authors.

7 changes: 7 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# libshell

The libshell is a set of the most commonly-used shell functions. All functions use minimum
of external utilities and written for POSIX shell.

The main idea is to get rid of implementing these functions in shell-scripts again and again,
and also to protect from common mistakes.
26 changes: 11 additions & 15 deletions docs/libshell.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
% LIBSHELL
% 3
% October 2016
% libshell
% Linux Programmer's Manual
libshell(3)

# NAME #
# NAME
libshell - the library of shell functions.

# DESCRIPTION #
# DESCRIPTION
The libshell is a set of the most commonly-used shell functions. All functions use minimum
of external utilities and written for POSIX shell.

The main idea is to get rid of implementing these functions in shell-scripts again and again,
and also to protect from common mistakes.

# STRUCTURE #
# STRUCTURE
The library has modular structure. Each module used for own special purpose.
Some modules use the functionality of each other and load the necessary dependence.

# USAGE #
All libshell modules **MUST** be kept in the PATH and could be not executable. It really helps to include
# USAGE
All libshell modules *MUST* be kept in the PATH and could be not executable. It really helps to include
these modules in the shell-program:

```bash
```
#!/bin/sh
. shell-error
. shell-getopt
# something useful ...
```

The **bash-completion** will not find these modules in the PATH, if they are not executable.
The *bash-completion* will not find these modules in the PATH, if they are not executable.

# AUTHOR #
Authors and contributors of the programs included in the **libshell** package are listed
# AUTHOR
Authors and contributors of the programs included in the *libshell* package are listed
in the COPYING file.

# BUGS #
# BUGS
Report bugs to the authors.

52 changes: 24 additions & 28 deletions docs/shell-args.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
% SHELL-ARGS
% 3
% October 2016
% libshell
% Linux Programmer's Manual
shell-args(3)

# NAME #
# NAME
opt_check_read, opt_check_exec, opt_check_dir, opt_check_number, show_usage, parse_common_option - functions
to check type of argument

# SYNOPSIS #
# SYNOPSIS

- opt_check_read "option-name" "option-value"
- opt_check_exec "option-name" "option-value"
Expand All @@ -17,45 +13,45 @@ to check type of argument
- show_usage ["error-message"]
- parse_common_option "option"

# DESCRIPTION #
# DESCRIPTION

## opt_check_read ##
## opt_check_read
Checks that given option value is a readable file.
Arguments: **option-name** is option name, **option-value** is option value.
If **option-value** is a readable file, outputs canonicalized file name, otherwise fails.
Arguments: *option-name* is option name, *option-value* is option value.
If *option-value* is a readable file, outputs canonicalized file name, otherwise fails.

## opt_check_exec ##
## opt_check_exec
Checks that given option value is an executable file.
Arguments: **option-name** is option name, **option-value** is option value.
If **option-value** is a executable file, outputs canonicalized file name, otherwise fails.
Arguments: *option-name* is option name, *option-value* is option value.
If *option-value* is a executable file, outputs canonicalized file name, otherwise fails.

## opt_check_dir ##
## opt_check_dir
Checks that given option value is a traversable directory.
Arguments: **option-name** is option name, **option-value** is option value.
Arguments: *option-name* is option name, *option-value* is option value.

## opt_check_number ##
## opt_check_number
Checks that given option value is a positive decimal integer.
Arguments: **option-name** is option name, **option-value** is option value.
If **option-value** is a positive decimal number, outputs it, otherwise returns fails.
Arguments: *option-name* is option name, *option-value* is option value.
If *option-value* is a positive decimal number, outputs it, otherwise returns fails.

## show_usage ##
## show_usage
Function shows short usage messages for script and finishes current script. Optionally,
this function can display error message.

## parse_common_option ##
## parse_common_option
Function to parse common arguments (*quiet*, *verbose*, *version*, *help*). Using this
function requires the definition of additional functions: **show_help**, **show_version**.
function requires the definition of additional functions: *show_help*, *show_version*.

# ENVIRONMENT #
# ENVIRONMENT

**getopt_common_opts** - short (one-character) ***getopt (1)*** options to parse common arguments ("q,v,V,h").
*getopt_common_opts* - short (one-character) *getopt (1)* options to parse common arguments ("q,v,V,h").

**getopt_common_longopts** - long (multi-character) ***getopt (1)*** options to parse common arguments ("quiet,verbose,version,help").
*getopt_common_longopts* - long (multi-character) *getopt (1)* options to parse common arguments ("quiet,verbose,version,help").

# AUTHOR #
Authors and contributors of the programs included in the **libshell** package are listed
# AUTHOR
Authors and contributors of the programs included in the *libshell* package are listed
in the COPYING file.

# BUGS #
# BUGS
Report bugs to the authors.

32 changes: 14 additions & 18 deletions docs/shell-cmdline.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
% SHELL-CMDLINE
% 3
% October 2016
% libshell
% Linux Programmer's Manual
shell-cmdline(3)

# NAME #
# NAME

cmdline_foreach, cmdline_get - parses and get values from `/proc/cmdline`

# SYNOPSIS #
# SYNOPSIS

- cmdline_foreach "proc-cmdline-data" "handler-function"
- cmdline_get "name-for-result" "name" ["proc-cmdline-data"]

# DESCRIPTION #
# DESCRIPTION
Collection of functions to parse and get values from `/proc/cmdline`. Because `/proc/cmdline` isn't
just shell command line we need to parse it differently. This string can have repetitions of parameters,
and only the last value makes sense, parameter names may contain characters illegal characters
for variables in a shell.

## cmdline_foreach ##
Function runs **handler-function** for each variable in **proc-cmdline-data**.
## cmdline_foreach
Function runs *handler-function* for each variable in *proc-cmdline-data*.
Returns nothing.

## cmdline_get ##
Function finds specified by **name** variable in `/proc/cmdline` or in **proc-cmdline-data**
and stores result into variable passed by **name-for-result**.
## cmdline_get
Function finds specified by *name* variable in `/proc/cmdline` or in *proc-cmdline-data*
and stores result into variable passed by *name-for-result*.
Usage example:

```bash
```
read cmdline < /proc/cmdline
cmdline_get 'initrd_value' 'initrd' "$cmdline"
echo "$initrd_value"
```

or

```bash
```
cmdline_get 'initrd_value' 'initrd'
echo "$initrd_value"
```

# AUTHOR #
Authors and contributors of the programs included in the **libshell** package are listed
# AUTHOR
Authors and contributors of the programs included in the *libshell* package are listed
in the COPYING file.

# BUGS #
# BUGS
Report bugs to the authors.

34 changes: 15 additions & 19 deletions docs/shell-config.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
% SHELL-CONFIG
% 3
% October 2016
% libshell
% Linux Programmer's Manual
shell-config(3)

# NAME #
# NAME

shell_config_comment, shell_config_del, shell_config_get, shell_config_set - functions
to work with a shell-like config files.

# SYNOPSIS #
# SYNOPSIS

- shell_config_comment "file" "name" ["delim"]
- shell_config_del "file" "name" ["delim"]
- shell_config_get "file" "name" ["delim"]
- shell_config_set "file" "name" "value" ["read-delim" ["write-delim"]]

# DESCRIPTION #
# DESCRIPTION
functions to work (read, change and remove variables) with a shell-like config files.

## shell_config_comment ##
Function puts **name** variable under comment in the config **file**.
## shell_config_comment
Function puts *name* variable under comment in the config *file*.
Optionally, you can define custom delimeter between name and value.

## shell_config_del ##
Function removes all entries (not commented) of **name** variable in the config **file**.
## shell_config_del
Function removes all entries (not commented) of *name* variable in the config *file*.
Optionally, you can define custom delimeter between name and value.

## shell_config_get ##
Function searches for the **name** variable in the config **file**. Optionally, you
## shell_config_get
Function searches for the *name* variable in the config *file*. Optionally, you
can define custom delimeter between name and value.

## shell_config_set ##
Function adds or uncomments **name** variable in the config **file**.
## shell_config_set
Function adds or uncomments *name* variable in the config *file*.

# AUTHOR #
Authors and contributors of the programs included in the **libshell** package are listed
# AUTHOR
Authors and contributors of the programs included in the *libshell* package are listed
in the COPYING file.

# BUGS #
# BUGS
Report bugs to the authors.

Loading

0 comments on commit c280119

Please sign in to comment.