libk  Diff

Differences From Artifact [199ffb3202]:

To Artifact [fbe8d4ad27]:


     1      1   #!/usr/bin/env sh
     2         -(test -d global && test -d $1) || {
            2  +(test -d global && test -f build.sh) || {
     3      3   	echo >&2 "($0) run $me from root of libk source directory"
     4      4   	exit 1
     5      5   }
     6      6   
     7      7   . global/common.sh
     8         -test "$OUT" = "" && {
     9         -	say "\$OUT environment variable must be set to your build directory - are you running this script by hand? run make doc in the root directory instead!"
            8  +test "$out" = "" && {
            9  +	say "\$out environment variable must be set to your build directory - are you running this script by hand? run make doc in the root directory instead!"
    10     10   	exit 2
    11     11   }
    12     12   
    13     13   if ! has cmark; then
    14     14   	say "to generate documentation for libk, install the cmark package and try again"
    15     15   	exit 3
    16     16   fi
    17     17   
    18     18   
    19         -name=$1
    20         -mandest=$OUT/doc/man
    21         -out=$2
    22         -file=$name/$name.md
    23         -desc="$(grep -m1 "^$name:" global/modules | cut -d: -f4)"
           19  +file="$1"
           20  +filename="$(basename "$file")"
           21  +stem=${filename%%.md}
           22  +mandest="$out/doc/man"
           23  +section=${section:-4}
           24  +out="$mandest/$stem.$section"
           25  +desc_rec="$(grep -m1 "^$name:" global/modules)"
           26  +if test $? -eq 0; then
           27  +	desc=" - $(echo $desc_rec | cut -d: -f4)"
           28  +else
           29  +	desc=""
           30  +fi
    24     31   date="$(date -r"$file" "+%d %A %Y")"
    25     32   
    26         -mkdir -p $mandest
           33  +mkdir -p "$mandest"
    27     34   
    28         -echo  >$out ".TH ${name^^} \"$section\" \"$date\" \"hale.su libk [r$BUILD]\" \"modules\""
           35  +echo  >"$out" ".TH ${name^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\""
    29     36   
    30         -echo >>$out ".SH NAME"
    31         -echo >>$out "$name - $desc"
    32         -echo >>$out ".SH SYNOPSIS" 
           37  +echo >>"$out" ".SH NAME"
           38  +echo >>"$out" "$stem$desc"
           39  +echo >>"$out" ".SH SYNOPSIS" 
    33     40   
    34         -dhead=$(grep -m1 -n "^# description$" $file)
           41  +dhead=$(grep -m1 -n "^# description$" "$file")
    35     42   if test $? -eq 0; then
    36     43   	descline=$(echo "$dhead" | cut -d: -f1)
    37     44   	offset=1
    38     45   else
    39         -	descline=$(grep -m2 -n "^#" $file | tail -n1 | cut -d: -f1)
           46  +	descline=$(grep -m2 -n "^#" "$file" | tail -n1 | cut -d: -f1)
    40     47   	offset=0
    41     48   fi
    42     49   
    43         -tail -n+2 $file | head -n$(expr $descline - 2) | cmark -t man >> $out
           50  +tail -n+2 $file | head -n$(expr $descline - 2) | cmark -t man >>"$out"
           51  +
           52  +echo >>"$out" ".SH DESCRIPTION"
           53  +
           54  +tail -n+$(expr $descline + $offset) "$file"  | cmark -t man >> "$out"
    44     55   
    45         -echo >>$out ".SH DESCRIPTION"
           56  +if has gzip; then
           57  +	gzip -f "$out"
           58  +	out="$out.gz"
           59  +fi
    46     60   
    47         -tail -n+$(expr $descline + $offset) $file  | cmark -t man >> $out
    48         -
    49         -say "wrote manpage for $name to $file"
           61  +say "wrote manpage for $stem to $out"