upd4
This commit is contained in:
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
|
||||
program_linux='
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
'
|
||||
|
||||
program_freebsd='
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
'
|
||||
|
||||
system=$(uname -s)
|
||||
|
||||
case $system in
|
||||
Linux) PROGRAM=$program_linux;;
|
||||
FreeBSD) PROGRAM=$program_freebsd;;
|
||||
*) echo $0: $system is unsupported >&2; exit 1;;
|
||||
esac
|
||||
|
||||
KIND=$1
|
||||
KIND=${KIND:-"SocketType,SocketLevel,SocketOption,AddrFamily,AddrInfoFlag,NameInfoFlag"}
|
||||
|
||||
echo module netio
|
||||
echo
|
||||
echo '/*'
|
||||
echo -e "\tThis file is generated by mkconst.sh, DO NOT EDIT."
|
||||
echo '*/'
|
||||
echo
|
||||
|
||||
echo "$PROGRAM" | ${CC:-"cc"} -x c - -E -dM ${CFLAGS:-""} |
|
||||
awk -v KIND=$KIND '
|
||||
$1 != "#define" || $2 ~ /\(/ || $3 == "" {next}
|
||||
$2 ~ /^_/ {next}
|
||||
$2 ~ /^[a-z]/ {next}
|
||||
$2 ~ /^SOCK_/ && KIND ~ "SocketType" {printf "pub const %s = SocketType(C.%s)\n", tolower($2), $2}
|
||||
$2 ~ /^(SOL|IPPROTO)_/ && KIND ~ "SocketLevel" {printf "pub const %s = SocketLevel(C.%s)\n", tolower($2), $2}
|
||||
$2 ~ /^(SO|IP|IPV6)_/ && KIND ~ "SocketOption" {printf "pub const %s = SocketOption(C.%s)\n", tolower($2), $2}
|
||||
$2 ~ /^AF_/ && KIND ~ "AddrFamily" {printf "pub const %s = AddrFamily(C.%s)\n", tolower($2), $2}
|
||||
$2 ~ /^AI_/ && KIND ~ "AddrInfoFlag" {printf "pub const %s = AddrInfoFlag(C.%s)\n", tolower($2), $2}
|
||||
$2 ~ /^NI_/ && KIND ~ "NameInfoFlag" {printf "pub const %s = NameInfoFlag(C.%s)\n", tolower($2), $2}
|
||||
KIND ~ "Any" {printf "%s\n", $0}
|
||||
{next}' | sort -k 2 -V
|
||||
Reference in New Issue
Block a user