mkerrors.sh 14 KB

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