Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 2b323e45 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

WIP: Rewriting the manpage generator script

parent de527cb0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!105Refactor and more
#!/bin/sh #!/bin/sh
function die ()
{
echo "ERROR: $@" > /dev/stderr
exit 1
}
# $0: script name # $0: script name
# $1: input # $1: folder_in
# $2: output # $2: folder_out
# $3: header # $3: header
# $4: footer # $4: footer
[ $# -ne 4 ] && exit 1 [ $# -ne 4 ] && exit 1
[ "$1" == "$2" ] && exit 2
# Global variables # Global variables
HEADER="$3" HEADER="$3" # Header file
FOOTER="$4" FOOTER="$4" # Footer file
INPUT="$1" FOLDER_INPUT="$1" # Where to find template .1 files
OUTPUT="$2" FOLDER_OUTPUT="$2" # Where to put the generated files
# Functions # Functions
function the_day() { function the_day ()
{
# $1: file # $1: file
# $2: what to replace with the date [ $# -ne 1 ] && die "$0 function takes one argument"
local SUB='___DATE___'
local DATE=$(date +'%B %d, %Y') local DATE=$(date +'%B %d, %Y')
sed -i "s/$2/$DATE/g" "$1" sed -i "s/$SUB/$DATE/g" "$1"
} }
function the_page() { function the_page ()
{
# $1: file # $1: file
# $2: what to replace with the date
FILE=$(basename "$1") FILE=$(basename "$1")
FILE="${FILE%.*}" FILE="${FILE%.*}"
FILE="${FILE^^}" FILE="${FILE^^}"
sed -i "s/$2/$FILE/g" "$1" local SUB='___PAGE___'
sed -i "s/$SUB/$FILE/g" "$1"
} }
function mk_manpage() { function mk_manpage ()
{
# $1: input # $1: input
# $2: output # $2: output
cat $HEADER > $2 cat $HEADER > $2
cat $1 >> $2 cat $1 >> $2
cat $FOOTER >> $2 cat $FOOTER >> $2
the_day "$2" '___DATE___' the_day "$2"
the_page "$2" '___PAGE___' the_page "$2"
} }
mk_manpage "$INPUT" "$OUTPUT" mk_manpage "$INPUT" "$OUTPUT"
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter