syscalls.sh (1102B)
- #!/bin/sh
- while read syscall args
- do
- fmt='"%s("'
- fmt_args='str_syscalls[nr]'
- fmt_sep=''
- n=0
- for i in $args; do
- case $i in
- "")
- break
- ;;
- "size")
- fmt="${fmt}${fmt_sep}\"%zd\""
- fmt_args="${fmt_args}, (size_t)args[$n]"
- ;;
- "off")
- fmt="${fmt}${fmt_sep}Pri_u"
- fmt_args="${fmt_args}, (off_t)args[$n]"
- ;;
- "uint")
- fmt="${fmt}${fmt_sep}Pri_u"
- fmt_args="${fmt_args}, (uint64_t)args[$n]"
- ;;
- "int")
- fmt="${fmt}${fmt_sep}Pri_i"
- fmt_args="${fmt_args}, (int64_t)args[$n]"
- ;;
- "oct")
- fmt="${fmt}${fmt_sep}Pri_o"
- fmt_args="${fmt_args}, (int64_t)args[$n]"
- ;;
- "hex"|"buf")
- fmt="${fmt}${fmt_sep}Pri_x"
- fmt_args="${fmt_args}, (int64_t)args[$n]"
- ;;
- "path")
- fmt="${fmt}${fmt_sep}Pri_str"
- fmt_args="${fmt_args}, read_str(args[$n], PATH_MAX)"
- ;;
- *)
- echo "syscalls.sh: error: Unhandled type ${i}" >&2
- exit 1
- esac
- : $((n+=1))
- fmt_sep=' ", " '
- done
- fmt="${fmt}"' ")"'
- printf ' case SYS_%s:\n' "$syscall"
- printf ' fprintf(stderr, %s, %s);\n' "$fmt" "$fmt_args"
- printf ' return;\n'
- done <syscalls.txt >syscalls_cases.h