summaryrefslogtreecommitdiffstats
path: root/src/pmdk/utils/get_aliases.sh
blob: 87978e2bce8680a47d79e29bcc937e5122f7541f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2020, Intel Corporation
#

#
# get_aliases.sh -- generate map of manuals functions and libraries
#
# usage: run from /pmdk/doc/generated location without parameters:
# ./../../utils/get_aliases.sh
#
# This script searches manpages from section 7 then
# takes all functions from each section using specified pattern
# and at the end to every function it assign real markdown file
# representation based on *.gz file content
#
# Generated libs_map.yml file is used on gh-pages
# to handle functions and their aliases
#

list=("$@")
man_child=("$@")

function search_aliases {
children=$1
parent=$2
for i in ${children[@]}
do
	if [ -e ../$parent/$i ]
	then
		echo "Man: $i"
		content=$(head -c 150 ../$parent/$i)
		if [[ "$content" == ".so "* ]] ;
		then
			content=$(basename ${content#".so"})
			i="${i%.*}"
			echo "  $i: $content" >> $map_file
		else
			r="${i%.*}"
			echo "  $r: $i" >> $map_file
		fi
	fi
done
}

function list_pages {
	parent="${1%.*}"
	list=("$@")
	man_child=("$@")

	if [ "$parent" == "libpmem" ]; then
		man_child=($(ls -1 ../libpmem | grep -e ".*\.3$"))
		echo -n "- $parent: " >> $map_file
		echo "${man_child[@]}" >> $map_file
	fi

	if [ "$parent" == "libpmem2" ]; then
		man_child=($(ls -1 ../libpmem2 | grep -e ".*\.3$"))
		echo -n "- $parent: " >> $map_file
		echo "${man_child[@]}" >> $map_file
	fi

	if [ "$parent" == "libpmemblk" ]; then
		man_child=($(ls -1 ../libpmemblk | grep -e ".*\.3$"))
		echo -n "- $parent: " >> $map_file
		echo "${man_child[@]}" >> $map_file
	fi

	if [ "$parent" == "libpmemlog" ]; then
		man_child=($(ls -1 ../libpmemlog | grep -e ".*\.3$"))
		echo -n "- $parent: " >> $map_file
		echo "${man_child[@]}" >> $map_file
	fi

	if [ "$parent" == "libpmemobj" ]; then
		man_child=($(ls -1 ../libpmemobj | grep -e ".*\.3$"))
		echo -n "- $parent: " >> $map_file
		echo "${man_child[@]}" >> $map_file
	fi

	if [ "$parent" == "libpmempool" ]; then
		man_child=($(ls -1 ../libpmempool | grep -e ".*\.3$"))
		echo -n "- $parent: " >> $map_file
		echo "${man_child[@]}" >> $map_file
	fi

	if [ "$parent" == "librpmem" ]; then
		man_child=($(ls -1 ../librpmem | grep -e ".*\.3$"))
		echo -n "- $parent: " >> $map_file
		echo "${man_child[@]}" >> $map_file
	fi

	if [ ${#man_child[@]} -ne 0 ]
	then
		list=${man_child[@]}
		search_aliases "${list[@]}" "$parent"
	fi
}

man7=($(ls -1 ../*/ | grep -e ".*\.7$"))

map_file=libs_map.yml
[ -e $map_file ] && rm $map_file
touch $map_file

for i in "${man7[@]}"
do
echo "Library: $i"
	list_pages $i
done