xref: /aosp_15_r20/external/libcap/progs/mkcapshdoc.sh (revision 2810ac1b38eead2603277920c78344c84ddf3aff)
1#!/bin/bash
2# This script generates some C code for inclusion in the capsh binary.
3# The Makefile generally only generates the .c code and compares it
4# with the checked in code in the progs directory.
5
6cat<<EOF
7#include <stdio.h>
8
9#include "./capshdoc.h"
10
11/*
12 * A line by line explanation of each named capability value
13 */
14EOF
15
16let x=0
17while [ -f "../doc/values/${x}.txt" ]; do
18    name=$(grep -F ",${x}}" ../libcap/cap_names.list.h|sed -e 's/{"//' -e 's/",/ = /' -e 's/},//')
19    echo "static const char *explanation${x}[] = {  /* ${name} */"
20    sed -e 's/"/\\"/g' -e 's/^/    "/' -e 's/$/",/' "../doc/values/${x}.txt"
21    let x=1+${x}
22    echo "    NULL"
23    echo "};"
24done
25
26cat<<EOF
27const char **explanations[] = {
28EOF
29let y=0
30while [ "${y}" -lt "${x}" ]; do
31    echo "    explanation${y},"
32    let y=1+${y}
33done
34cat<<EOF
35};
36
37const int capsh_doc_limit = ${x};
38EOF
39