Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

605 linhas
15 KiB

  1. #!/usr/bin/env bash
  2. # Copyright 2009 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. # Generate Go code listing errors and other #defined constant
  6. # values (ENAMETOOLONG etc.), by asking the preprocessor
  7. # about the definitions.
  8. unset LANG
  9. export LC_ALL=C
  10. export LC_CTYPE=C
  11. if test -z "$GOARCH" -o -z "$GOOS"; then
  12. echo 1>&2 "GOARCH or GOOS not defined in environment"
  13. exit 1
  14. fi
  15. # Check that we are using the new build system if we should
  16. if [[ "$GOOS" = "linux" ]] && [[ "$GOARCH" != "sparc64" ]]; then
  17. if [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then
  18. echo 1>&2 "In the new build system, mkerrors should not be called directly."
  19. echo 1>&2 "See README.md"
  20. exit 1
  21. fi
  22. fi
  23. CC=${CC:-cc}
  24. if [[ "$GOOS" = "solaris" ]]; then
  25. # Assumes GNU versions of utilities in PATH.
  26. export PATH=/usr/gnu/bin:$PATH
  27. fi
  28. uname=$(uname)
  29. includes_Darwin='
  30. #define _DARWIN_C_SOURCE
  31. #define KERNEL
  32. #define _DARWIN_USE_64_BIT_INODE
  33. #include <stdint.h>
  34. #include <sys/attr.h>
  35. #include <sys/types.h>
  36. #include <sys/event.h>
  37. #include <sys/ptrace.h>
  38. #include <sys/socket.h>
  39. #include <sys/sockio.h>
  40. #include <sys/sysctl.h>
  41. #include <sys/mman.h>
  42. #include <sys/mount.h>
  43. #include <sys/utsname.h>
  44. #include <sys/wait.h>
  45. #include <sys/xattr.h>
  46. #include <net/bpf.h>
  47. #include <net/if.h>
  48. #include <net/if_types.h>
  49. #include <net/route.h>
  50. #include <netinet/in.h>
  51. #include <netinet/ip.h>
  52. #include <termios.h>
  53. '
  54. includes_DragonFly='
  55. #include <sys/types.h>
  56. #include <sys/event.h>
  57. #include <sys/socket.h>
  58. #include <sys/sockio.h>
  59. #include <sys/sysctl.h>
  60. #include <sys/mman.h>
  61. #include <sys/wait.h>
  62. #include <sys/ioctl.h>
  63. #include <net/bpf.h>
  64. #include <net/if.h>
  65. #include <net/if_types.h>
  66. #include <net/route.h>
  67. #include <netinet/in.h>
  68. #include <termios.h>
  69. #include <netinet/ip.h>
  70. #include <net/ip_mroute/ip_mroute.h>
  71. '
  72. includes_FreeBSD='
  73. #include <sys/capability.h>
  74. #include <sys/param.h>
  75. #include <sys/types.h>
  76. #include <sys/event.h>
  77. #include <sys/socket.h>
  78. #include <sys/sockio.h>
  79. #include <sys/sysctl.h>
  80. #include <sys/mman.h>
  81. #include <sys/mount.h>
  82. #include <sys/wait.h>
  83. #include <sys/ioctl.h>
  84. #include <net/bpf.h>
  85. #include <net/if.h>
  86. #include <net/if_types.h>
  87. #include <net/route.h>
  88. #include <netinet/in.h>
  89. #include <termios.h>
  90. #include <netinet/ip.h>
  91. #include <netinet/ip_mroute.h>
  92. #include <sys/extattr.h>
  93. #if __FreeBSD__ >= 10
  94. #define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10
  95. #undef SIOCAIFADDR
  96. #define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data
  97. #undef SIOCSIFPHYADDR
  98. #define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data
  99. #endif
  100. '
  101. includes_Linux='
  102. #define _LARGEFILE_SOURCE
  103. #define _LARGEFILE64_SOURCE
  104. #ifndef __LP64__
  105. #define _FILE_OFFSET_BITS 64
  106. #endif
  107. #define _GNU_SOURCE
  108. // <sys/ioctl.h> is broken on powerpc64, as it fails to include definitions of
  109. // these structures. We just include them copied from <bits/termios.h>.
  110. #if defined(__powerpc__)
  111. struct sgttyb {
  112. char sg_ispeed;
  113. char sg_ospeed;
  114. char sg_erase;
  115. char sg_kill;
  116. short sg_flags;
  117. };
  118. struct tchars {
  119. char t_intrc;
  120. char t_quitc;
  121. char t_startc;
  122. char t_stopc;
  123. char t_eofc;
  124. char t_brkc;
  125. };
  126. struct ltchars {
  127. char t_suspc;
  128. char t_dsuspc;
  129. char t_rprntc;
  130. char t_flushc;
  131. char t_werasc;
  132. char t_lnextc;
  133. };
  134. #endif
  135. #include <bits/sockaddr.h>
  136. #include <sys/epoll.h>
  137. #include <sys/eventfd.h>
  138. #include <sys/inotify.h>
  139. #include <sys/ioctl.h>
  140. #include <sys/mman.h>
  141. #include <sys/mount.h>
  142. #include <sys/prctl.h>
  143. #include <sys/stat.h>
  144. #include <sys/types.h>
  145. #include <sys/time.h>
  146. #include <sys/socket.h>
  147. #include <sys/xattr.h>
  148. #include <linux/if.h>
  149. #include <linux/if_alg.h>
  150. #include <linux/if_arp.h>
  151. #include <linux/if_ether.h>
  152. #include <linux/if_tun.h>
  153. #include <linux/if_packet.h>
  154. #include <linux/if_addr.h>
  155. #include <linux/falloc.h>
  156. #include <linux/filter.h>
  157. #include <linux/fs.h>
  158. #include <linux/keyctl.h>
  159. #include <linux/magic.h>
  160. #include <linux/netfilter/nfnetlink.h>
  161. #include <linux/netlink.h>
  162. #include <linux/perf_event.h>
  163. #include <linux/random.h>
  164. #include <linux/reboot.h>
  165. #include <linux/rtnetlink.h>
  166. #include <linux/ptrace.h>
  167. #include <linux/sched.h>
  168. #include <linux/seccomp.h>
  169. #include <linux/sockios.h>
  170. #include <linux/wait.h>
  171. #include <linux/icmpv6.h>
  172. #include <linux/serial.h>
  173. #include <linux/can.h>
  174. #include <linux/vm_sockets.h>
  175. #include <linux/taskstats.h>
  176. #include <linux/genetlink.h>
  177. #include <linux/stat.h>
  178. #include <linux/watchdog.h>
  179. #include <linux/hdreg.h>
  180. #include <linux/rtc.h>
  181. #include <net/route.h>
  182. #include <asm/termbits.h>
  183. #ifndef MSG_FASTOPEN
  184. #define MSG_FASTOPEN 0x20000000
  185. #endif
  186. #ifndef PTRACE_GETREGS
  187. #define PTRACE_GETREGS 0xc
  188. #endif
  189. #ifndef PTRACE_SETREGS
  190. #define PTRACE_SETREGS 0xd
  191. #endif
  192. #ifndef SOL_NETLINK
  193. #define SOL_NETLINK 270
  194. #endif
  195. #ifdef SOL_BLUETOOTH
  196. // SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h
  197. // but it is already in bluetooth_linux.go
  198. #undef SOL_BLUETOOTH
  199. #endif
  200. // Certain constants are missing from the fs/crypto UAPI
  201. #define FS_KEY_DESC_PREFIX "fscrypt:"
  202. #define FS_KEY_DESC_PREFIX_SIZE 8
  203. #define FS_MAX_KEY_SIZE 64
  204. '
  205. includes_NetBSD='
  206. #include <sys/types.h>
  207. #include <sys/param.h>
  208. #include <sys/event.h>
  209. #include <sys/mman.h>
  210. #include <sys/socket.h>
  211. #include <sys/sockio.h>
  212. #include <sys/sysctl.h>
  213. #include <sys/termios.h>
  214. #include <sys/ttycom.h>
  215. #include <sys/wait.h>
  216. #include <net/bpf.h>
  217. #include <net/if.h>
  218. #include <net/if_types.h>
  219. #include <net/route.h>
  220. #include <netinet/in.h>
  221. #include <netinet/in_systm.h>
  222. #include <netinet/ip.h>
  223. #include <netinet/ip_mroute.h>
  224. #include <netinet/if_ether.h>
  225. // Needed since <sys/param.h> refers to it...
  226. #define schedppq 1
  227. '
  228. includes_OpenBSD='
  229. #include <sys/types.h>
  230. #include <sys/param.h>
  231. #include <sys/event.h>
  232. #include <sys/mman.h>
  233. #include <sys/socket.h>
  234. #include <sys/sockio.h>
  235. #include <sys/sysctl.h>
  236. #include <sys/termios.h>
  237. #include <sys/ttycom.h>
  238. #include <sys/wait.h>
  239. #include <net/bpf.h>
  240. #include <net/if.h>
  241. #include <net/if_types.h>
  242. #include <net/if_var.h>
  243. #include <net/route.h>
  244. #include <netinet/in.h>
  245. #include <netinet/in_systm.h>
  246. #include <netinet/ip.h>
  247. #include <netinet/ip_mroute.h>
  248. #include <netinet/if_ether.h>
  249. #include <net/if_bridge.h>
  250. // We keep some constants not supported in OpenBSD 5.5 and beyond for
  251. // the promise of compatibility.
  252. #define EMUL_ENABLED 0x1
  253. #define EMUL_NATIVE 0x2
  254. #define IPV6_FAITH 0x1d
  255. #define IPV6_OPTIONS 0x1
  256. #define IPV6_RTHDR_STRICT 0x1
  257. #define IPV6_SOCKOPT_RESERVED1 0x3
  258. #define SIOCGIFGENERIC 0xc020693a
  259. #define SIOCSIFGENERIC 0x80206939
  260. #define WALTSIG 0x4
  261. '
  262. includes_SunOS='
  263. #include <limits.h>
  264. #include <sys/types.h>
  265. #include <sys/socket.h>
  266. #include <sys/sockio.h>
  267. #include <sys/mman.h>
  268. #include <sys/wait.h>
  269. #include <sys/ioctl.h>
  270. #include <sys/mkdev.h>
  271. #include <net/bpf.h>
  272. #include <net/if.h>
  273. #include <net/if_arp.h>
  274. #include <net/if_types.h>
  275. #include <net/route.h>
  276. #include <netinet/in.h>
  277. #include <termios.h>
  278. #include <netinet/ip.h>
  279. #include <netinet/ip_mroute.h>
  280. '
  281. includes='
  282. #include <sys/types.h>
  283. #include <sys/file.h>
  284. #include <fcntl.h>
  285. #include <dirent.h>
  286. #include <sys/socket.h>
  287. #include <netinet/in.h>
  288. #include <netinet/ip.h>
  289. #include <netinet/ip6.h>
  290. #include <netinet/tcp.h>
  291. #include <errno.h>
  292. #include <sys/signal.h>
  293. #include <signal.h>
  294. #include <sys/resource.h>
  295. #include <time.h>
  296. '
  297. ccflags="$@"
  298. # Write go tool cgo -godefs input.
  299. (
  300. echo package unix
  301. echo
  302. echo '/*'
  303. indirect="includes_$(uname)"
  304. echo "${!indirect} $includes"
  305. echo '*/'
  306. echo 'import "C"'
  307. echo 'import "syscall"'
  308. echo
  309. echo 'const ('
  310. # The gcc command line prints all the #defines
  311. # it encounters while processing the input
  312. echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags |
  313. awk '
  314. $1 != "#define" || $2 ~ /\(/ || $3 == "" {next}
  315. $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers
  316. $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next}
  317. $2 ~ /^(SCM_SRCRT)$/ {next}
  318. $2 ~ /^(MAP_FAILED)$/ {next}
  319. $2 ~ /^ELF_.*$/ {next}# <asm/elf.h> contains ELF_ARCH, etc.
  320. $2 ~ /^EXTATTR_NAMESPACE_NAMES/ ||
  321. $2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next}
  322. $2 !~ /^ETH_/ &&
  323. $2 !~ /^EPROC_/ &&
  324. $2 !~ /^EQUIV_/ &&
  325. $2 !~ /^EXPR_/ &&
  326. $2 ~ /^E[A-Z0-9_]+$/ ||
  327. $2 ~ /^B[0-9_]+$/ ||
  328. $2 ~ /^(OLD|NEW)DEV$/ ||
  329. $2 == "BOTHER" ||
  330. $2 ~ /^CI?BAUD(EX)?$/ ||
  331. $2 == "IBSHIFT" ||
  332. $2 ~ /^V[A-Z0-9]+$/ ||
  333. $2 ~ /^CS[A-Z0-9]/ ||
  334. $2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ ||
  335. $2 ~ /^IGN/ ||
  336. $2 ~ /^IX(ON|ANY|OFF)$/ ||
  337. $2 ~ /^IN(LCR|PCK)$/ ||
  338. $2 !~ "X86_CR3_PCID_NOFLUSH" &&
  339. $2 ~ /(^FLU?SH)|(FLU?SH$)/ ||
  340. $2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ ||
  341. $2 == "BRKINT" ||
  342. $2 == "HUPCL" ||
  343. $2 == "PENDIN" ||
  344. $2 == "TOSTOP" ||
  345. $2 == "XCASE" ||
  346. $2 == "ALTWERASE" ||
  347. $2 == "NOKERNINFO" ||
  348. $2 ~ /^PAR/ ||
  349. $2 ~ /^SIG[^_]/ ||
  350. $2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ ||
  351. $2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ ||
  352. $2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ ||
  353. $2 ~ /^O?XTABS$/ ||
  354. $2 ~ /^TC[IO](ON|OFF)$/ ||
  355. $2 ~ /^IN_/ ||
  356. $2 ~ /^LOCK_(SH|EX|NB|UN)$/ ||
  357. $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|T?PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ ||
  358. $2 ~ /^TP_STATUS_/ ||
  359. $2 ~ /^FALLOC_/ ||
  360. $2 == "ICMPV6_FILTER" ||
  361. $2 == "SOMAXCONN" ||
  362. $2 == "NAME_MAX" ||
  363. $2 == "IFNAMSIZ" ||
  364. $2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ ||
  365. $2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ ||
  366. $2 ~ /^HW_MACHINE$/ ||
  367. $2 ~ /^SYSCTL_VERS/ ||
  368. $2 ~ /^(MS|MNT|UMOUNT)_/ ||
  369. $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ ||
  370. $2 ~ /^(O|F|E?FD|NAME|S|PTRACE|PT)_/ ||
  371. $2 ~ /^LINUX_REBOOT_CMD_/ ||
  372. $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ ||
  373. $2 !~ "NLA_TYPE_MASK" &&
  374. $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ ||
  375. $2 ~ /^SIOC/ ||
  376. $2 ~ /^TIOC/ ||
  377. $2 ~ /^TCGET/ ||
  378. $2 ~ /^TCSET/ ||
  379. $2 ~ /^TC(FLSH|SBRKP?|XONC)$/ ||
  380. $2 !~ "RTF_BITS" &&
  381. $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ ||
  382. $2 ~ /^BIOC/ ||
  383. $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ ||
  384. $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|LOCKS|MEMLOCK|MSGQUEUE|NICE|NOFILE|NPROC|RSS|RTPRIO|RTTIME|SIGPENDING|STACK)|RLIM_INFINITY/ ||
  385. $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ ||
  386. $2 ~ /^CLONE_[A-Z_]+/ ||
  387. $2 !~ /^(BPF_TIMEVAL)$/ &&
  388. $2 ~ /^(BPF|DLT)_/ ||
  389. $2 ~ /^CLOCK_/ ||
  390. $2 ~ /^CAN_/ ||
  391. $2 ~ /^CAP_/ ||
  392. $2 ~ /^ALG_/ ||
  393. $2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE|IOC_(GET|SET)_ENCRYPTION)/ ||
  394. $2 ~ /^GRND_/ ||
  395. $2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ ||
  396. $2 ~ /^KEYCTL_/ ||
  397. $2 ~ /^PERF_EVENT_IOC_/ ||
  398. $2 ~ /^SECCOMP_MODE_/ ||
  399. $2 ~ /^SPLICE_/ ||
  400. $2 !~ /^AUDIT_RECORD_MAGIC/ &&
  401. $2 ~ /^[A-Z0-9_]+_MAGIC2?$/ ||
  402. $2 ~ /^(VM|VMADDR)_/ ||
  403. $2 ~ /^IOCTL_VM_SOCKETS_/ ||
  404. $2 ~ /^(TASKSTATS|TS)_/ ||
  405. $2 ~ /^CGROUPSTATS_/ ||
  406. $2 ~ /^GENL_/ ||
  407. $2 ~ /^STATX_/ ||
  408. $2 ~ /^UTIME_/ ||
  409. $2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ ||
  410. $2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ ||
  411. $2 ~ /^FSOPT_/ ||
  412. $2 ~ /^WDIOC_/ ||
  413. $2 ~ /^NFN/ ||
  414. $2 ~ /^(HDIO|WIN|SMART)_/ ||
  415. $2 !~ "WMESGLEN" &&
  416. $2 ~ /^W[A-Z0-9]+$/ ||
  417. $2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE)/ {printf("\t%s = C.%s\n", $2, $2)}
  418. $2 ~ /^__WCOREFLAG$/ {next}
  419. $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)}
  420. {next}
  421. ' | sort
  422. echo ')'
  423. ) >_const.go
  424. # Pull out the error names for later.
  425. errors=$(
  426. echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
  427. awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' |
  428. sort
  429. )
  430. # Pull out the signal names for later.
  431. signals=$(
  432. echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
  433. awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
  434. egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' |
  435. sort
  436. )
  437. # Again, writing regexps to a file.
  438. echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
  439. awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' |
  440. sort >_error.grep
  441. echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
  442. awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' |
  443. egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' |
  444. sort >_signal.grep
  445. echo '// mkerrors.sh' "$@"
  446. echo '// Code generated by the command above; see README.md. DO NOT EDIT.'
  447. echo
  448. echo "// +build ${GOARCH},${GOOS}"
  449. echo
  450. go tool cgo -godefs -- "$@" _const.go >_error.out
  451. cat _error.out | grep -vf _error.grep | grep -vf _signal.grep
  452. echo
  453. echo '// Errors'
  454. echo 'const ('
  455. cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/'
  456. echo ')'
  457. echo
  458. echo '// Signals'
  459. echo 'const ('
  460. cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/'
  461. echo ')'
  462. # Run C program to print error and syscall strings.
  463. (
  464. echo -E "
  465. #include <stdio.h>
  466. #include <stdlib.h>
  467. #include <errno.h>
  468. #include <ctype.h>
  469. #include <string.h>
  470. #include <signal.h>
  471. #define nelem(x) (sizeof(x)/sizeof((x)[0]))
  472. enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below
  473. struct tuple {
  474. int num;
  475. const char *name;
  476. };
  477. struct tuple errors[] = {
  478. "
  479. for i in $errors
  480. do
  481. echo -E ' {'$i', "'$i'" },'
  482. done
  483. echo -E "
  484. };
  485. struct tuple signals[] = {
  486. "
  487. for i in $signals
  488. do
  489. echo -E ' {'$i', "'$i'" },'
  490. done
  491. # Use -E because on some systems bash builtin interprets \n itself.
  492. echo -E '
  493. };
  494. static int
  495. tuplecmp(const void *a, const void *b)
  496. {
  497. return ((struct tuple *)a)->num - ((struct tuple *)b)->num;
  498. }
  499. int
  500. main(void)
  501. {
  502. int i, e;
  503. char buf[1024], *p;
  504. printf("\n\n// Error table\n");
  505. printf("var errorList = [...]struct {\n");
  506. printf("\tnum syscall.Errno\n");
  507. printf("\tname string\n");
  508. printf("\tdesc string\n");
  509. printf("} {\n");
  510. qsort(errors, nelem(errors), sizeof errors[0], tuplecmp);
  511. for(i=0; i<nelem(errors); i++) {
  512. e = errors[i].num;
  513. if(i > 0 && errors[i-1].num == e)
  514. continue;
  515. strcpy(buf, strerror(e));
  516. // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
  517. if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
  518. buf[0] += a - A;
  519. printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf);
  520. }
  521. printf("}\n\n");
  522. printf("\n\n// Signal table\n");
  523. printf("var signalList = [...]struct {\n");
  524. printf("\tnum syscall.Signal\n");
  525. printf("\tname string\n");
  526. printf("\tdesc string\n");
  527. printf("} {\n");
  528. qsort(signals, nelem(signals), sizeof signals[0], tuplecmp);
  529. for(i=0; i<nelem(signals); i++) {
  530. e = signals[i].num;
  531. if(i > 0 && signals[i-1].num == e)
  532. continue;
  533. strcpy(buf, strsignal(e));
  534. // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
  535. if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
  536. buf[0] += a - A;
  537. // cut trailing : number.
  538. p = strrchr(buf, ":"[0]);
  539. if(p)
  540. *p = '\0';
  541. printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf);
  542. }
  543. printf("}\n\n");
  544. return 0;
  545. }
  546. '
  547. ) >_errors.c
  548. $CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out